From: Liu Shixin Date: Fri, 15 Sep 2023 08:34:17 +0000 (+0800) Subject: mm-vmscan-try-to-reclaim-swapcache-pages-if-no-swap-space-v6 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=ea2bfb36af7dc88d3d6917112f0c9ad7b9db972a;p=users%2Fjedix%2Flinux-maple.git mm-vmscan-try-to-reclaim-swapcache-pages-if-no-swap-space-v6 fix NULL pointing derefence and hung task problem reported by Sachin Link: https://lkml.kernel.org/r/20230915083417.3190512-1-liushixin2@huawei.com Signed-off-by: Liu Shixin Tested-by: Yosry Ahmed Reviewed-by: "Huang, Ying" Reviewed-by: Yosry Ahmed Cc: "Huang, Ying" Cc: Johannes Weiner Cc: Kefeng Wang Cc: Michal Hocko Cc: Sachin Sant Cc: Yosry Ahmed Cc: Muchun Song Cc: Roman Gushchin Cc: Shakeel Butt Signed-off-by: Andrew Morton --- diff --git a/mm/vmscan.c b/mm/vmscan.c index e78235927dee..96abaa5a973e 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -324,7 +324,8 @@ static inline bool can_reclaim_anon_pages(struct mem_cgroup *memcg, return true; /* Is there any swapcache pages to reclaim? */ if (total_swapcache_pages() > 0) { - sc->swapcache_only = 1; + if (sc) + sc->swapcache_only = 1; return true; } } else { @@ -333,7 +334,8 @@ static inline bool can_reclaim_anon_pages(struct mem_cgroup *memcg, return true; /* Is there any swapcache pages in memcg to reclaim? */ if (mem_cgroup_get_nr_swapcache_pages(memcg) > 0) { - sc->swapcache_only = 1; + if (sc) + sc->swapcache_only = 1; return true; } } @@ -1597,19 +1599,6 @@ static bool skip_cma(struct folio *folio, struct scan_control *sc) } #endif -static bool skip_isolate(struct folio *folio, struct scan_control *sc, - enum lru_list lru) -{ - if (folio_zonenum(folio) > sc->reclaim_idx) - return true; - if (skip_cma(folio, sc)) - return true; - if (unlikely(sc->swapcache_only && !is_file_lru(lru) && - !folio_test_swapcache(folio))) - return true; - return false; -} - /* * Isolating page from the lruvec to fill in @dst list by nr_to_scan times. * @@ -1656,7 +1645,8 @@ static unsigned long isolate_lru_folios(unsigned long nr_to_scan, nr_pages = folio_nr_pages(folio); total_scan += nr_pages; - if (skip_isolate(folio, sc, lru)) { + if (folio_zonenum(folio) > sc->reclaim_idx || + skip_cma(folio, sc)) { nr_skipped[folio_zonenum(folio)] += nr_pages; move_to = &folios_skipped; goto move; @@ -1671,6 +1661,15 @@ static unsigned long isolate_lru_folios(unsigned long nr_to_scan, */ scan += nr_pages; + /* + * Count non-swapcache too because the swapcache pages may + * be rare and it takes too much times here if not count + * the non-swapcache pages. + */ + if (unlikely(sc->swapcache_only && !is_file_lru(lru) && + !folio_test_swapcache(folio))) + goto move; + if (!folio_test_lru(folio)) goto move; if (!sc->may_unmap && folio_mapped(folio))