Commit e496612c authored by Minchan Kim's avatar Minchan Kim Committed by Linus Torvalds

mm: do not stall register_shrinker()

Shakeel Butt reported he has observed in production systems that the job
loader gets stuck for 10s of seconds while doing a mount operation.  It
turns out that it was stuck in register_shrinker() because some
unrelated job was under memory pressure and was spending time in
shrink_slab().  Machines have a lot of shrinkers registered and jobs
under memory pressure have to traverse all of those memcg-aware
shrinkers and affect unrelated jobs which want to register their own

To solve the issue, this patch simply bails out slab shrinking if it is
found that someone wants to register a shrinker in parallel.  A downside
is it could cause unfair shrinking between shrinkers.  However, it
should be rare and we can add compilcated logic if we find it's not

[ tweak code comment]
Link: default avatarMinchan Kim <>
Signed-off-by: default avatarShakeel Butt <>
Reported-by: default avatarShakeel Butt <>
Tested-by: default avatarShakeel Butt <>
Acked-by: default avatarJohannes Weiner <>
Acked-by: default avatarMichal Hocko <>
Cc: Tetsuo Handa <>
Cc: Anshuman Khandual <>
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
parent 48128397
......@@ -489,6 +489,15 @@ static unsigned long shrink_slab(gfp_t gfp_mask, int nid,
sc.nid = 0;
freed += do_shrink_slab(&sc, shrinker, priority);
* Bail out if someone want to register a new shrinker to
* prevent the regsitration from being stalled for long periods
* by parallel ongoing shrinking.
if (rwsem_is_contended(&shrinker_rwsem)) {
freed = freed ? : 1;
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment