aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMinchan Kim <[email protected]>2018-01-31 16:16:55 -0800
committerLinus Torvalds <[email protected]>2018-01-31 17:18:37 -0800
commite496612c5130567fc9d5f1969ca4b86665aa3cbb (patch)
tree5963ff9f270d3f7a046fa8d94ae25fcdde4c2630
parent48128397b04679717cfd419d55ec86456b84eb61 (diff)
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 shrinkers. 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 enough. [[email protected]: tweak code comment] Link: http://lkml.kernel.org/r/20171115005602.GB23810@bbox Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Minchan Kim <[email protected]> Signed-off-by: Shakeel Butt <[email protected]> Reported-by: Shakeel Butt <[email protected]> Tested-by: Shakeel Butt <[email protected]> Acked-by: Johannes Weiner <[email protected]> Acked-by: Michal Hocko <[email protected]> Cc: Tetsuo Handa <[email protected]> Cc: Anshuman Khandual <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
-rw-r--r--mm/vmscan.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/mm/vmscan.c b/mm/vmscan.c
index e73274a60b22..153e0795f4f0 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -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;
+ break;
+ }
}
up_read(&shrinker_rwsem);