Linux-mm Archive on
 help / color / Atom feed
From: Minchan Kim <>
To: Andrew Morton <>
	kernel-team <>,
	Minchan Kim <>, Michal Hocko <>,
	Tetsuo Handa <>,
	Shakeel Butt <>,
	Johannes Weiner <>
Subject: [PATCH] mm: Do not stall register_shrinker
Date: Fri, 24 Nov 2017 09:04:59 +0900
Message-ID: <> (raw)

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

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

Cc: Michal Hocko <>
Cc: Tetsuo Handa <>
Acked-by: Johannes Weiner <>
Reported-and-tested-by: Shakeel Butt <>
Signed-off-by: Shakeel Butt <>
Signed-off-by: Minchan Kim <>
 mm/vmscan.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/mm/vmscan.c b/mm/vmscan.c
index 6a5a72baccd5..6698001787bd 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -486,6 +486,14 @@ 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 long time stall by parallel ongoing shrinking.
+		 */
+		if (rwsem_is_contended(&shrinker_rwsem)) {
+			freed = freed ? : 1;
+			break;
+		}

To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to  For more info on Linux MM,
see: .
Don't email: <a href=mailto:""> </a>

             reply index

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-24  0:04 Minchan Kim [this message]
2017-11-24  7:50 ` Michal Hocko
2017-11-27  5:46 ` Anshuman Khandual
2017-11-27  6:31   ` Minchan Kim

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \ \ \ \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Linux-mm Archive on

Archives are clonable:
	git clone --mirror linux-mm/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-mm linux-mm/ \
	public-inbox-index linux-mm

Example config snippet for mirrors

Newsgroup available over NNTP:

AGPL code for this site: git clone