mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/1] mm/slab_common: fix shrink budget underflow in kfree_rcu_shrink_scan
@ 2026-08-24  9:18 Longlong Xia
  2026-08-26  2:56 ` Hao Li
  0 siblings, 1 reply; 3+ messages in thread
From: Longlong Xia @ 2026-08-24  9:18 UTC (permalink / raw)
  To: vbabka, harry, akpm
  Cc: hao.li, cl, rientjes, roman.gushchin, linux-mm, linux-kernel,
	paulmck, rcu, Longlong Xia

From: Longlong Xia <xialonglong@kylinos.cn>

The kfree_rcu shrinker decremented sc->nr_to_scan (unsigned long)
and then tested the result with <= 0. When a single CPU's object
count exceeds the remaining budget, the subtraction wraps to a large
positive value and the <= 0 comparison, which is equivalent to == 0
for an unsigned type, never fires again. The scan loop then iterates
through every possible CPU instead of honouring the reclaim budget.

Reorder the logic to compare count against nr_to_scan before
subtracting, so the loop exits as soon as the budget is met.

Assisted-by: Codex:gpt-5.6-sol
Signed-off-by: Longlong Xia <xialonglong@kylinos.cn>
---
 mm/slab_common.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mm/slab_common.c b/mm/slab_common.c
index 657fd75776ea..95ddbab290d4 100644
--- a/mm/slab_common.c
+++ b/mm/slab_common.c
@@ -2172,11 +2172,11 @@ kfree_rcu_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
 		count += drain_page_cache(krcp);
 		kfree_rcu_monitor(&krcp->monitor_work.work);
 
-		sc->nr_to_scan -= count;
 		freed += count;
 
-		if (sc->nr_to_scan <= 0)
+		if (count >= sc->nr_to_scan)
 			break;
+		sc->nr_to_scan -= count;
 	}
 
 	return freed == 0 ? SHRINK_STOP : freed;
-- 
2.43.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-08-26  7:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-24  9:18 [PATCH 1/1] mm/slab_common: fix shrink budget underflow in kfree_rcu_shrink_scan Longlong Xia
2026-08-26  2:56 ` Hao Li
2026-08-26  7:12   ` Longlong Xia

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®