Skip to content

Commit 5cbf2ff

Browse files
haokexintorvalds
authored andcommitted
dump_stack: avoid the livelock of the dump_lock
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. [[email protected]: fix comment] Link: http://lkml.kernel.org/r/[email protected] Fixes: b58d977 ("dump_stack: serialize the output from dump_stack()") Signed-off-by: Kevin Hao <[email protected]> Suggested-by: Linus Torvalds <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent a316313 commit 5cbf2ff

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

lib/dump_stack.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,12 @@ asmlinkage __visible void dump_stack(void)
106106
was_locked = 1;
107107
} else {
108108
local_irq_restore(flags);
109-
cpu_relax();
109+
/*
110+
* Wait for the lock to release before jumping to
111+
* atomic_cmpxchg() in order to mitigate the thundering herd
112+
* problem.
113+
*/
114+
do { cpu_relax(); } while (atomic_read(&dump_lock) != -1);
110115
goto retry;
111116
}
112117

0 commit comments

Comments
 (0)