From: Kevin Hao <haokexin@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: Andrew Morton <akpm@linux-foundation.org>,
Linus Torvalds <torvalds@linux-foundation.org>
Subject: [PATCH v2] dump_stack: Avoid the livelock of the dump_lock
Date: Wed, 30 Oct 2019 11:16:37 +0800 [thread overview]
Message-ID: <20191030031637.6025-1-haokexin@gmail.com> (raw)
In the current code, we use the atomic_cmpxchg() to serialize the
output of the dump_stack(), but this implementation suffers the
thundering herd problem. We have observed such kind of livelock on a
Marvell cn96xx board(24 cpus) when heavily using the dump_stack() in
a kprobe handler. Actually we can let the competitors to wait for
the releasing of the lock before jumping to atomic_cmpxchg(). This
will definitely mitigate the thundering herd problem. Thanks Linus
for the suggestion.
Fixes: b58d977432c8 ("dump_stack: serialize the output from dump_stack()")
Cc: stable@vger.kernel.org
Signed-off-by: Kevin Hao <haokexin@gmail.com>
---
v2:
1. Use the method suggested by Linus.
2. Since this fix seems pretty simple, maybe it deserve to be
backported to stable kernel. So CC the stable.
lib/dump_stack.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/lib/dump_stack.c b/lib/dump_stack.c
index 5cff72f18c4a..0062dfcafd63 100644
--- a/lib/dump_stack.c
+++ b/lib/dump_stack.c
@@ -106,7 +106,11 @@ asmlinkage __visible void dump_stack(void)
was_locked = 1;
} else {
local_irq_restore(flags);
- cpu_relax();
+ /*
+ * Wait the lock to release before jumping to atomic_cmpxchg()
+ * in order to mitigate the thundering herd problem.
+ */
+ do { cpu_relax(); } while (atomic_read(&dump_lock) != -1);
goto retry;
}
--
2.14.4
reply other threads:[~2019-10-30 3:24 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191030031637.6025-1-haokexin@gmail.com \
--to=haokexin@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®