lib: fix lock initialization in region allocation benchmark

The Maple Tree benchmark uses MTREE_INIT() for a stack-allocated tree. 
Its static spinlock initializer leaves lockdep to use the lock address as
the class key.  Since the address is on the stack, the first allocation
triggers "INFO: trying to register non-static key" and disables lockdep.

The IDA benchmark has the same problem through IDA_INIT(), but runs after
Maple Tree and therefore encounters an already disabled lockdep.

Use mt_init_flags() and ida_init() to initialize the locks with persistent
lock-class keys.  Keep initialization outside the timed allocation paths.

Link: https://lore.kernel.org/20260911155244.1406122-1-ynorov@nvidia.com
Fixes: f4806cc63c ("lib: test bitmap vs IDA vs Maple Tree performance for region allocations")
Signed-off-by: Yury Norov <ynorov@nvidia.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Closes: https://lore.kernel.org/oe-lkp/202609101106.771b567e-lkp@intel.com
Acked-by: Liam R. Howlett (Oracle) <liam@infradead.org>
Cc: Alice Ryhl <aliceryhl@google.com>
Cc: Andrew Ballance <andrewjballance@gmail.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
This commit is contained in:
Yury Norov 2026-09-11 11:52:43 -04:00 committed by Andrew Morton
parent 27ffeec7b0
commit 718de76e2d

View File

@ -78,11 +78,13 @@ static size_t __init ida_size(unsigned long nr_ids)
static unsigned long __init benchmark_ida(unsigned long cap)
{
struct ida ida = IDA_INIT(ida);
struct ida ida;
unsigned long cnt, idx, off, nr_ids = 0;
ktime_t alloc_time, free_time;
int id = -ENOSPC;
ida_init(&ida);
alloc_time = ktime_get();
for (cnt = 0; cnt <= cap; cnt++) {
for (off = 0; off < reg_sz[cnt]; off++) {
@ -125,12 +127,14 @@ static unsigned long __init benchmark_ida(unsigned long cap)
static unsigned long __init benchmark_maple_tree(unsigned long cap)
{
struct maple_tree mt = MTREE_INIT(mt, MT_FLAGS_ALLOC_RANGE);
struct maple_tree mt;
unsigned long cnt, idx;
ktime_t alloc_time, free_time;
size_t sz;
int ret;
mt_init_flags(&mt, MT_FLAGS_ALLOC_RANGE);
alloc_time = ktime_get();
for (cnt = 0; cnt <= cap; cnt++) {
ret = mtree_alloc_range(&mt, &idx, xa_mk_value(cnt + 1),