dump_stack: Avoid the livelock of the dump_lock
PATCH v2 1/1 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.
Fixes b58d977432c8 ("dump_stack: serialize the output from dump_stack()")
Signed-off-by Kevin Hao <[email protected]>
---
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(-)
lib/dump_stack.c +5 -1
@@ -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; }
Signature · 1 line
2.14.4