Skip to contentSkip to conversation

mm/mglru: only clear kswapd_failures if reclaimable

PATCH In review Wei Xu 3 participants 5 messages Oct 14, 2024 – Oct 16, 2024

Subsystems (3)
lore
Share & tools
lore

Wei Xu

author reviewer
#0 lore raw

PATCH 1/2 mm/mglru: only clear kswapd_failures if reclaimable

lru_gen_shrink_node() unconditionally clears kswapd_failures, which can prevent kswapd from sleeping and cause 100% kswapd cpu usage even when kswapd repeatedly fails to make progress in reclaim.

Only clear kswap_failures in lru_gen_shrink_node() if reclaim makes some progress, similar to shrink_node().

Fixes e4dde56cd208 ("mm: multi-gen LRU: per-node lru_gen_folio lists")
---
 mm/vmscan.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/vmscan.c +2 -2
index 50dc06d55b1d..9d1e1c4e383d 100644
@@ -4970,8 +4970,8 @@ static void lru_gen_shrink_node(struct pglist_data *pgdat, struct scan_control *
 
 	blk_finish_plug(&plug);
 done:
-	/* kswapd should never fail */
-	pgdat->kswapd_failures = 0;
+	if (sc->nr_reclaimed > reclaimed)
+		pgdat->kswapd_failures = 0;
 }
 
 /******************************************************************************
Signature · 1 line
2.47.0.rc1.288.g06298d1525-goog
maintainer
#1 lore raw
Quoted 6 lines · On Mon, 14 Oct 2024 22:12:11 +0000 Wei Xu <[email protected]> wrote:

lru_gen_shrink_node() unconditionally clears kswapd_failures, which can prevent kswapd from sleeping and cause 100% kswapd cpu usage even when kswapd repeatedly fails to make progress in reclaim.

Only clear kswap_failures in lru_gen_shrink_node() if reclaim makes some progress, similar to shrink_node().

That sounds bad. What triggers this? Can you suggest why it has just bee discovered, after 1.5 years? And should the fix be backported into -stable kernels?

author reviewer
#2 lore raw
Quoted 7 lines · Andrew Morton
Quoted 4 lines · On Mon, 14 Oct 2024 22:12:11 +0000 Wei Xu <[email protected]> wrote:

lru_gen_shrink_node() unconditionally clears kswapd_failures, which can prevent kswapd from sleeping and cause 100% kswapd cpu usage even when kswapd repeatedly fails to make progress in reclaim.

Quoted 7 lines
Quoted 2 lines

Only clear kswap_failures in lru_gen_shrink_node() if reclaim makes some progress, similar to shrink_node().

That sounds bad. What triggers this? Can you suggest why it has just bee discovered, after 1.5 years? And should the fix be backported into -stable kernels?

I happened to run into this problem in one of my tests recently. It requires a combination of several conditions: The allocator needs to allocate a right amount of pages such that it can wake up kswapd without itself being OOM killed; there is no memory for kswapd to reclaim (My test disables swap and cleans page cache first); no other process frees enough memory at the same time.

I think the fix is a good candidate for stable kernels.

#3 lore raw
In reply to Wei Xu
Quoted 19 lines · Wei Xu

lru_gen_shrink_node() unconditionally clears kswapd_failures, which can prevent kswapd from sleeping and cause 100% kswapd cpu usage even when kswapd repeatedly fails to make progress in reclaim.

Only clear kswap_failures in lru_gen_shrink_node() if reclaim makes some progress, similar to shrink_node().

Fixes e4dde56cd208 ("mm: multi-gen LRU: per-node lru_gen_folio lists")
---
 mm/vmscan.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/vmscan.c +0 -0
index 50dc06d55b1d..9d1e1c4e383d 100644

mm/vmscan.c static void lru_gen_shrink_node(struct pglist_data *pgdat, struct scan_control * · line 4972

Quoted 3 lines
mm/vmscan.c +0 -0
@@ -4970,8 +4970,8 @@ static void lru_gen_shrink_node(struct pglist_data *pgdat, struct scan_control *
 
        blk_finish_plug(&plug);
 done:

Nit: the "done:" isn't used anymore, so better just remove it.

Quoted 11 lines
mm/vmscan.c +2 -3
-       /* kswapd should never fail */
-       pgdat->kswapd_failures = 0;
+       if (sc->nr_reclaimed > reclaimed)
+               pgdat->kswapd_failures = 0;
 }
 
 /******************************************************************************
--

2.47.0.rc1.288.g06298d1525-goog

author reviewer
#4 lore raw
Quoted 22 lines · Yu Zhao
Quoted 20 lines · Wei Xu

lru_gen_shrink_node() unconditionally clears kswapd_failures, which can prevent kswapd from sleeping and cause 100% kswapd cpu usage even when kswapd repeatedly fails to make progress in reclaim.

Only clear kswap_failures in lru_gen_shrink_node() if reclaim makes some progress, similar to shrink_node().

Fixes e4dde56cd208 ("mm: multi-gen LRU: per-node lru_gen_folio lists")
---
 mm/vmscan.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/vmscan.c +0 -0
index 50dc06d55b1d..9d1e1c4e383d 100644
@@ -4970,8 +4970,8 @@ static void lru_gen_shrink_node(struct pglist_data *pgdat, struct scan_control *
 
Quoted 5 lines

mm/vmscan.c static void lru_gen_shrink_node(struct pglist_data *pgdat, struct scan_control * · line 4972

Quoted 2 lines
mm/vmscan.c +0 -0
        blk_finish_plug(&plug);
 done:

Nit: the "done:" isn't used anymore, so better just remove it.

"goto done" is still used at the beginning of lru_gen_shrink_node(). We can refactor the code to remove it. But it is better to be handled in a separate change.

Quoted 11 lines
Quoted 11 lines
mm/vmscan.c +2 -3
-       /* kswapd should never fail */
-       pgdat->kswapd_failures = 0;
+       if (sc->nr_reclaimed > reclaimed)
+               pgdat->kswapd_failures = 0;
 }
 
 /******************************************************************************
--

2.47.0.rc1.288.g06298d1525-goog