Patch "mm/vmscan.c: set correct defer count for shrinker" has been added to the 4.4-stable tree
Subsystems (4)
This is a note to let you know that I've just added the patch titled
mm/vmscan.c: set correct defer count for shrinker
to the 4.4-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
mm-vmscan.c-set-correct-defer-count-for-shrinker.patch
and it can be found in the queue-4.4 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
Quoted 1 line
From
5f33a0803bbd781de916f5c7448cbbbbc763d911Mon Sep 17 00:00:00 2001
From: Shaohua Li <[email protected]>
Date: Mon, 12 Dec 2016 16:41:50 -0800
Subject: mm/vmscan.c: set correct defer count for shrinker
From: Shaohua Li <[email protected]>
commit 5f33a0803bbd781de916f5c7448cbbbbc763d911 upstream.
Our system uses significantly more slab memory with memcg enabled with the latest kernel. With 3.10 kernel, slab uses 2G memory, while with 4.6 kernel, 6G memory is used. The shrinker has problem. Let's see we have two memcg for one shrinker. In do_shrink_slab:
1. Check cg1. nr_deferred = 0, assume total_scan = 700. batch size is 1024, then no memory is freed. nr_deferred = 700
2. Check cg2. nr_deferred = 700. Assume freeable = 20, then total_scan = 10 or 40. Let's assume it's 10. No memory is freed. nr_deferred = 10.
The deferred share of cg1 is lost in this case. kswapd will free no memory even run above steps again and again.
The fix makes sure one memcg's deferred share isn't lost.
--- mm/vmscan.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
mm/vmscan.c +11 -3
@@ -277,6 +277,7 @@ static unsigned long do_shrink_slab(struint nid = shrinkctl->nid;long batch_size = shrinker->batch ? shrinker->batch :SHRINK_BATCH ; +long scanned =0 , next_deferred; freeable = shrinker->count_objects (shrinker, shrinkctl);if (freeable ==0 )
@@ -298,7 +299,9 @@ static unsigned long do_shrink_slab(strupr_err ("shrink_slab: %pF negative objects to delete nr=%ld\n" , shrinker->scan_objects, total_scan); total_scan = freeable; - } + next_deferred = nr; + }else + next_deferred = total_scan;/* * We need to avoid excessive windup on filesystem shrinkers
@@ -355,17 +358,22 @@ static unsigned long do_shrink_slab(strucount_vm_events (SLABS_SCANNED , nr_to_scan); total_scan -= nr_to_scan; + scanned += nr_to_scan;cond_resched (); } +if (next_deferred >= scanned) + next_deferred -= scanned; +else + next_deferred =0 ;/* * move the unused scan count back into the shrinker in a * manner that handles concurrent updates. If we exhausted the * scan, there is no need to do an update. */ -if (total_scan >0 ) - new_nr =atomic_long_add_return (total_scan, +if (next_deferred >0 ) + new_nr =atomic_long_add_return (next_deferred, &shrinker->nr_deferred[nid]);else new_nr =atomic_long_read (&shrinker->nr_deferred[nid]);
Patches currently in stable-queue which might be from [email protected] are
queue-4.4/mm-vmscan.c-set-correct-defer-count-for-shrinker.patch