]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
mm-vmscan-try-to-reclaim-swapcache-pages-if-no-swap-space-v6
authorLiu Shixin <liushixin2@huawei.com>
Fri, 15 Sep 2023 08:34:17 +0000 (16:34 +0800)
committerAndrew Morton <akpm@linux-foundation.org>
Mon, 20 Nov 2023 21:16:45 +0000 (13:16 -0800)
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 <liushixin2@huawei.com>
Tested-by: Yosry Ahmed <yosryahmed@google.com>
Reviewed-by: "Huang, Ying" <ying.huang@intel.com>
Reviewed-by: Yosry Ahmed <yosryahmed@google.com>
Cc: "Huang, Ying" <ying.huang@intel.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Kefeng Wang <wangkefeng.wang@huawei.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Sachin Sant <sachinp@linux.ibm.com>
Cc: Yosry Ahmed <yosryahmed@google.com>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Shakeel Butt <shakeelb@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/vmscan.c

index e78235927deede9d42c044ecca861ee3bf5f1971..96abaa5a973e356e6f1e06b24d9920e95af8617a 100644 (file)
@@ -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))