Skip to content

Commit cdb7d2d

Browse files
Waiman-LongIngo Molnar
authored andcommitted
locking/lockdep: Add number of dynamic keys to /proc/lockdep_stats
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 <[email protected]> Signed-off-by: Boqun Feng <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Cc: Bill Wendling <[email protected]> Cc: Justin Stitt <[email protected]> Cc: Nathan Chancellor <[email protected]> Cc: Nick Desaulniers <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Will Deacon <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/r/[email protected]
1 parent 6a1a219 commit cdb7d2d

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

kernel/locking/lockdep.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ static DECLARE_BITMAP(list_entries_in_use, MAX_LOCKDEP_ENTRIES);
219219
static struct hlist_head lock_keys_hash[KEYHASH_SIZE];
220220
unsigned long nr_lock_classes;
221221
unsigned long nr_zapped_classes;
222+
unsigned long nr_dynamic_keys;
222223
unsigned long max_lock_class_idx;
223224
struct lock_class lock_classes[MAX_LOCKDEP_KEYS];
224225
DECLARE_BITMAP(lock_classes_in_use, MAX_LOCKDEP_KEYS);
@@ -1238,6 +1239,7 @@ void lockdep_register_key(struct lock_class_key *key)
12381239
goto out_unlock;
12391240
}
12401241
hlist_add_head_rcu(&key->hash_entry, hash_head);
1242+
nr_dynamic_keys++;
12411243
out_unlock:
12421244
graph_unlock();
12431245
restore_irqs:
@@ -6609,6 +6611,7 @@ void lockdep_unregister_key(struct lock_class_key *key)
66096611
pf = get_pending_free();
66106612
__lockdep_free_key_range(pf, key, 1);
66116613
need_callback = prepare_call_rcu_zapped(pf);
6614+
nr_dynamic_keys--;
66126615
}
66136616
lockdep_unlock();
66146617
raw_local_irq_restore(flags);

kernel/locking/lockdep_internals.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ extern unsigned long nr_lock_classes;
138138
extern unsigned long nr_zapped_classes;
139139
extern unsigned long nr_zapped_lock_chains;
140140
extern unsigned long nr_list_entries;
141+
extern unsigned long nr_dynamic_keys;
141142
long lockdep_next_lockchain(long i);
142143
unsigned long lock_chain_count(void);
143144
extern unsigned long nr_stack_trace_entries;

kernel/locking/lockdep_proc.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ static int lockdep_stats_show(struct seq_file *m, void *v)
286286
#endif
287287
seq_printf(m, " lock-classes: %11lu [max: %lu]\n",
288288
nr_lock_classes, MAX_LOCKDEP_KEYS);
289+
seq_printf(m, " dynamic-keys: %11lu\n",
290+
nr_dynamic_keys);
289291
seq_printf(m, " direct dependencies: %11lu [max: %lu]\n",
290292
nr_list_entries, MAX_LOCKDEP_ENTRIES);
291293
seq_printf(m, " indirect dependencies: %11lu\n",

0 commit comments

Comments
 (0)