[lkml]   [2018]   [Aug]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
Subject[PATCH] mm/vmscan: adjust shrinkctl->nr_scanned after invoking scan_objects
Some shrinkers may free more than the requested nr_to_scan of pages
in one invocation of scan_objects, and some may free less than that.

Currently shrinkers can either return the actual number of pages that
have been freed via the return value of scan_objects or track that
actual number in shrinkctl->nr_scanned. But do_shrink_slab works on an
assumption that the actual number is always tracked via
shrinkctl->nr_scanned, which is not true. Having checked the shrinkers
used in the kernel, they basically return the actual number of freed
pages via the return value of scan_objects, and most of them leave
shrinkctl->nr_scanned unchanged after scan_objects is called.

So this patch adjusts shrinkctl->nr_scanned to the actual freed number
after scan_objects is called.

Signed-off-by: Wei Wang <>
Cc: Michal Hocko <>
Cc: Andrew Morton <>
Cc: Tetsuo Handa <>
Cc: Chris Wilson <>
Cc: Michael S. Tsirkin <>
mm/vmscan.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/mm/vmscan.c b/mm/vmscan.c
index 03822f8..78a75b9 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -447,9 +447,13 @@ static unsigned long do_shrink_slab(struct shrink_control *shrinkctl,
if (ret == SHRINK_STOP)
freed += ret;
+ shrinkctl->nr_scanned = ret;

count_vm_events(SLABS_SCANNED, shrinkctl->nr_scanned);
- total_scan -= shrinkctl->nr_scanned;
+ if (total_scan > shrinkctl->nr_scanned)
+ total_scan -= shrinkctl->nr_scanned;
+ else
+ total_scan = 0;
scanned += shrinkctl->nr_scanned;

 \ /
  Last update: 2018-08-03 13:26    [W:0.024 / U:16.124 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site