Skip to contentSkip to conversation

mm: do not stall register_shrinker()

PATCH In review Robert Kolchmeyer 2 participants 2 messages May 2, 2019 – May 5, 2019

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm: do not stall register_shrinker()

From: Minchan Kim <[email protected]>

commit e496612c5130567fc9d5f1969ca4b86665aa3cbb upstream.

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.

---
Backport of commit e496612c5130567fc9d5f1969ca4b86665aa3cbb upstream. We would like to apply this to linux-4.14.y.
I needed to change the patch context for the patch to apply to linux-4.14.y. The actual fix remains unchanged.

 mm/vmscan.c | 9 +++++++++
 1 file changed, 9 insertions(+)
mm/vmscan.c +9 -0
index 9734e62654fa..99837e931f53 100644
@@ -502,6 +502,15 @@ static unsigned long shrink_slab(gfp_t gfp_mask, int nid,
 			sc.nid = 0;
 
 		freed += do_shrink_slab(&sc, shrinker, nr_scanned, nr_eligible);
+		/*
+		 * 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);
Signature · 1 line
2.21.0.593.g511ec345e18-goog
#1 lore raw
Quoted 34 lines · Robert Kolchmeyer

From: Minchan Kim <[email protected]>

commit e496612c5130567fc9d5f1969ca4b86665aa3cbb upstream.

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.

Quoted 5 lines

---
Backport of commit e496612c5130567fc9d5f1969ca4b86665aa3cbb upstream. We would like to apply this to linux-4.14.y.
I needed to change the patch context for the patch to apply to linux-4.14.y. The actual fix remains unchanged.

Now queued up, thanks.

greg k-h