From: Muhammad Bilal <meatuni001@gmail.com>
To: peterz@infradead.org, mingo@redhat.com, will@kernel.org,
boqun@kernel.org
Cc: longman@redhat.com, akpm@linux-foundation.org,
linux-kernel@vger.kernel.org,
Muhammad Bilal <meatuni001@gmail.com>
Subject: [PATCH] locking/lockdep: make chain-hlocks average depth configurable
Date: Tue, 4 Aug 2026 02:50:40 +0500 [thread overview]
Message-ID: <20260803215040.172457-1-meatuni001@gmail.com> (raw)
The static chain_hlocks[] pool is sized as:
MAX_LOCKDEP_CHAIN_HLOCKS = MAX_LOCKDEP_CHAINS * AVG_LOCKDEP_CHAIN_DEPTH
MAX_LOCKDEP_CHAINS is already tunable via CONFIG_LOCKDEP_CHAINS_BITS,
but AVG_LOCKDEP_CHAIN_DEPTH is hardcoded to 5 and has no Kconfig knob.
Workloads that build unusually deep individual lock chains -- rather
than simply a large number of distinct chains -- can exhaust
chain_hlocks[] and trip:
BUG: MAX_LOCKDEP_CHAIN_HLOCKS too low!
well before MAX_LOCKDEP_CHAINS itself is anywhere near full, which
silently disables lock debugging for the rest of the boot
(debug_locks_off_graph_unlock()). Bumping LOCKDEP_CHAINS_BITS alone
does not help in that case since the bottleneck is chain depth, not
chain count.
Observed on a PREEMPT_DYNAMIC + RCU lockdep + KASAN debug build,
reproducing at every boot from add_chain_cache() failing to allocate
out of the static pool, hit from sched wakeup, hrtimer, and btrfs
flush-workqueue paths (deep IRQ/softirq nesting stacked on top of
deep filesystem/scheduler call chains).
Add CONFIG_LOCKDEP_CHAIN_DEPTH so this can be tuned like
LOCKDEP_BITS/LOCKDEP_CHAINS_BITS, defaulting to 5 to preserve current
behavior for everyone who isn't hitting this.
Signed-off-by: Muhammad Bilal <meatuni001@gmail.com>
---
kernel/locking/lockdep_internals.h | 2 +-
lib/Kconfig.debug | 17 +++++++++++++++++
2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/kernel/locking/lockdep_internals.h b/kernel/locking/lockdep_internals.h
index 0e5e6ffe91a3..ed566681f3c8 100644
--- a/kernel/locking/lockdep_internals.h
+++ b/kernel/locking/lockdep_internals.h
@@ -121,7 +121,7 @@ enum {
#define MAX_LOCKDEP_CHAINS (1UL << MAX_LOCKDEP_CHAINS_BITS)
-#define AVG_LOCKDEP_CHAIN_DEPTH 5
+#define AVG_LOCKDEP_CHAIN_DEPTH CONFIG_LOCKDEP_CHAIN_DEPTH
#define MAX_LOCKDEP_CHAIN_HLOCKS (MAX_LOCKDEP_CHAINS * AVG_LOCKDEP_CHAIN_DEPTH)
extern struct lock_chain lock_chains[];
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 1244dcac2294..90b7f990611d 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -1614,6 +1614,23 @@ config LOCKDEP_CHAINS_BITS
help
Try increasing this value if you hit "BUG: MAX_LOCKDEP_CHAINS too low!" message.
+config LOCKDEP_CHAIN_DEPTH
+ int "Average depth for MAX_LOCKDEP_CHAIN_HLOCKS"
+ depends on LOCKDEP
+ range 3 20
+ default 5
+ help
+ Average per-chain depth used to size the static chain_hlocks[]
+ pool: MAX_LOCKDEP_CHAIN_HLOCKS = MAX_LOCKDEP_CHAINS *
+ LOCKDEP_CHAIN_DEPTH.
+
+ Workloads that build unusually deep lock chains (heavy irq/softirq
+ nesting stacked on top of deep filesystem or scheduler call chains)
+ can exhaust this pool and trip "BUG: MAX_LOCKDEP_CHAIN_HLOCKS too
+ low!" well before MAX_LOCKDEP_CHAINS itself is exhausted, silently
+ disabling lock debugging. Increase this value if you hit that
+ message and LOCKDEP_CHAINS_BITS increases alone don't help.
+
config LOCKDEP_STACK_TRACE_BITS
int "Size for MAX_STACK_TRACE_ENTRIES (as Nth power of 2)"
depends on LOCKDEP && !LOCKDEP_SMALL
--
2.55.0
next reply other threads:[~2026-08-03 21:50 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-03 21:50 Muhammad Bilal [this message]
2026-08-04 2:32 ` [PATCH] locking/lockdep: make chain-hlocks average depth configurable Zhan Xusheng
2026-08-04 10:36 ` Muhammad Bilal
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=20260803215040.172457-1-meatuni001@gmail.com \
--to=meatuni001@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=boqun@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=longman@redhat.com \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=will@kernel.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