kernel/locking/lockdep.c | 3 +++ kernel/locking/lockdep_internals.h | 1 + kernel/locking/lockdep_proc.c | 2 ++ 3 files changed, 6 insertions(+)
There have been recent reports about running out of lockdep keys
(MAX_LOCKDEP_KEYS too low!). One possible reason is that too many
dynamic keys have been registered. A possible culprit is the
lockdep_register_key() call in qdisc_alloc() of net/sched/sch_generic.c.
Currently, there is no way to find out how many dynamic keys have been
registered. Add such a stat to the /proc/lockdep_stats to get better
clarity.
Signed-off-by: Waiman Long <longman@redhat.com>
---
kernel/locking/lockdep.c | 3 +++
kernel/locking/lockdep_internals.h | 1 +
kernel/locking/lockdep_proc.c | 2 ++
3 files changed, 6 insertions(+)
diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index 58d78a33ac65..aeedaaaa403c 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -219,6 +219,7 @@ static DECLARE_BITMAP(list_entries_in_use, MAX_LOCKDEP_ENTRIES);
static struct hlist_head lock_keys_hash[KEYHASH_SIZE];
unsigned long nr_lock_classes;
unsigned long nr_zapped_classes;
+unsigned long nr_dynamic_keys;
unsigned long max_lock_class_idx;
struct lock_class lock_classes[MAX_LOCKDEP_KEYS];
DECLARE_BITMAP(lock_classes_in_use, MAX_LOCKDEP_KEYS);
@@ -1238,6 +1239,7 @@ void lockdep_register_key(struct lock_class_key *key)
goto out_unlock;
}
hlist_add_head_rcu(&key->hash_entry, hash_head);
+ nr_dynamic_keys++;
out_unlock:
graph_unlock();
restore_irqs:
@@ -6606,6 +6608,7 @@ void lockdep_unregister_key(struct lock_class_key *key)
pf = get_pending_free();
__lockdep_free_key_range(pf, key, 1);
need_callback = prepare_call_rcu_zapped(pf);
+ nr_dynamic_keys--;
}
lockdep_unlock();
raw_local_irq_restore(flags);
diff --git a/kernel/locking/lockdep_internals.h b/kernel/locking/lockdep_internals.h
index 20f9ef58d3d0..82156caf77d1 100644
--- a/kernel/locking/lockdep_internals.h
+++ b/kernel/locking/lockdep_internals.h
@@ -138,6 +138,7 @@ extern unsigned long nr_lock_classes;
extern unsigned long nr_zapped_classes;
extern unsigned long nr_zapped_lock_chains;
extern unsigned long nr_list_entries;
+extern unsigned long nr_dynamic_keys;
long lockdep_next_lockchain(long i);
unsigned long lock_chain_count(void);
extern unsigned long nr_stack_trace_entries;
diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
index 6db0f43fc4df..b52c07c4707c 100644
--- a/kernel/locking/lockdep_proc.c
+++ b/kernel/locking/lockdep_proc.c
@@ -286,6 +286,8 @@ static int lockdep_stats_show(struct seq_file *m, void *v)
#endif
seq_printf(m, " lock-classes: %11lu [max: %lu]\n",
nr_lock_classes, MAX_LOCKDEP_KEYS);
+ seq_printf(m, " dynamic-keys: %11lu\n",
+ nr_dynamic_keys);
seq_printf(m, " direct dependencies: %11lu [max: %lu]\n",
nr_list_entries, MAX_LOCKDEP_ENTRIES);
seq_printf(m, " indirect dependencies: %11lu\n",
--
2.49.0
On Thu, Apr 24, 2025 at 08:11:55PM -0400, Waiman Long wrote: > There have been recent reports about running out of lockdep keys > (MAX_LOCKDEP_KEYS too low!). One possible reason is that too many > dynamic keys have been registered. A possible culprit is the > lockdep_register_key() call in qdisc_alloc() of net/sched/sch_generic.c. > > Currently, there is no way to find out how many dynamic keys have been > registered. Add such a stat to the /proc/lockdep_stats to get better > clarity. > > Signed-off-by: Waiman Long <longman@redhat.com> Queued for 6.16. Regards, Boqun > --- > kernel/locking/lockdep.c | 3 +++ > kernel/locking/lockdep_internals.h | 1 + > kernel/locking/lockdep_proc.c | 2 ++ > 3 files changed, 6 insertions(+) > > diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c > index 58d78a33ac65..aeedaaaa403c 100644 > --- a/kernel/locking/lockdep.c > +++ b/kernel/locking/lockdep.c > @@ -219,6 +219,7 @@ static DECLARE_BITMAP(list_entries_in_use, MAX_LOCKDEP_ENTRIES); > static struct hlist_head lock_keys_hash[KEYHASH_SIZE]; > unsigned long nr_lock_classes; > unsigned long nr_zapped_classes; > +unsigned long nr_dynamic_keys; > unsigned long max_lock_class_idx; > struct lock_class lock_classes[MAX_LOCKDEP_KEYS]; > DECLARE_BITMAP(lock_classes_in_use, MAX_LOCKDEP_KEYS); > @@ -1238,6 +1239,7 @@ void lockdep_register_key(struct lock_class_key *key) > goto out_unlock; > } > hlist_add_head_rcu(&key->hash_entry, hash_head); > + nr_dynamic_keys++; > out_unlock: > graph_unlock(); > restore_irqs: > @@ -6606,6 +6608,7 @@ void lockdep_unregister_key(struct lock_class_key *key) > pf = get_pending_free(); > __lockdep_free_key_range(pf, key, 1); > need_callback = prepare_call_rcu_zapped(pf); > + nr_dynamic_keys--; > } > lockdep_unlock(); > raw_local_irq_restore(flags); > diff --git a/kernel/locking/lockdep_internals.h b/kernel/locking/lockdep_internals.h > index 20f9ef58d3d0..82156caf77d1 100644 > --- a/kernel/locking/lockdep_internals.h > +++ b/kernel/locking/lockdep_internals.h > @@ -138,6 +138,7 @@ extern unsigned long nr_lock_classes; > extern unsigned long nr_zapped_classes; > extern unsigned long nr_zapped_lock_chains; > extern unsigned long nr_list_entries; > +extern unsigned long nr_dynamic_keys; > long lockdep_next_lockchain(long i); > unsigned long lock_chain_count(void); > extern unsigned long nr_stack_trace_entries; > diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c > index 6db0f43fc4df..b52c07c4707c 100644 > --- a/kernel/locking/lockdep_proc.c > +++ b/kernel/locking/lockdep_proc.c > @@ -286,6 +286,8 @@ static int lockdep_stats_show(struct seq_file *m, void *v) > #endif > seq_printf(m, " lock-classes: %11lu [max: %lu]\n", > nr_lock_classes, MAX_LOCKDEP_KEYS); > + seq_printf(m, " dynamic-keys: %11lu\n", > + nr_dynamic_keys); > seq_printf(m, " direct dependencies: %11lu [max: %lu]\n", > nr_list_entries, MAX_LOCKDEP_ENTRIES); > seq_printf(m, " indirect dependencies: %11lu\n", > -- > 2.49.0 >
© 2016 - 2026 Red Hat, Inc.