[PATCH 17/19] srcutree: Make init_srcu_struct_atomic() prevent transition to big
From: Paul E. McKenney
Date: Fri Sep 18 2026 - 20:40:00 EST
From: Kunwu Chan <kunwu.chan@xxxxxxxxx>
The is_atomic parameter of init_srcu_struct_fields() exists so that
atomic SRCU never transitions to big, but neither
init_srcu_struct_atomic() nor its lockdep counterpart
__init_srcu_struct_atomic() sets it.
On systems where srcutree.convert_to_big selects SRCU_SIZING_INIT,
this needlessly allocates a full srcu_node combining tree for any
dynamically initialized atomic srcu_struct, despite atomic SRCU
having neither callbacks nor srcu_barrier() operations.
Pass true from both atomic entry points, adding an is_atomic parameter
to __init_srcu_struct_common().
Signed-off-by: Kunwu Chan <kunwu.chan@xxxxxxxxx>
Signed-off-by: Paul E. McKenney <paulmck@xxxxxxxxxx>
---
kernel/rcu/srcutree.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c
index 82e61421142e..4e9a0b8ea344 100644
--- a/kernel/rcu/srcutree.c
+++ b/kernel/rcu/srcutree.c
@@ -305,26 +305,27 @@ static int init_srcu_struct_fields(struct srcu_struct *ssp, bool is_static, bool
#ifdef CONFIG_DEBUG_LOCK_ALLOC
static int
-__init_srcu_struct_common(struct srcu_struct *ssp, const char *name, struct lock_class_key *key)
+__init_srcu_struct_common(struct srcu_struct *ssp, const char *name,
+ struct lock_class_key *key, bool is_atomic)
{
/* Don't re-initialize a lock while it is held. */
debug_check_no_locks_freed((void *)ssp, sizeof(*ssp));
lockdep_init_map(&ssp->dep_map, name, key, 0);
- return init_srcu_struct_fields(ssp, false, false);
+ return init_srcu_struct_fields(ssp, false, is_atomic);
}
int init_srcu_struct_lockdep(struct srcu_struct *ssp, const char *name,
struct lock_class_key *key)
{
ssp->srcu_reader_flavor = 0;
- return __init_srcu_struct_common(ssp, name, key);
+ return __init_srcu_struct_common(ssp, name, key, false);
}
EXPORT_SYMBOL_GPL(init_srcu_struct_lockdep);
int __init_srcu_struct_fast(struct srcu_struct *ssp, const char *name, struct lock_class_key *key)
{
ssp->srcu_reader_flavor = SRCU_READ_FLAVOR_FAST;
- return __init_srcu_struct_common(ssp, name, key);
+ return __init_srcu_struct_common(ssp, name, key, false);
}
EXPORT_SYMBOL_GPL(__init_srcu_struct_fast);
@@ -332,14 +333,14 @@ int __init_srcu_struct_fast_updown(struct srcu_struct *ssp, const char *name,
struct lock_class_key *key)
{
ssp->srcu_reader_flavor = SRCU_READ_FLAVOR_FAST_UPDOWN;
- return __init_srcu_struct_common(ssp, name, key);
+ return __init_srcu_struct_common(ssp, name, key, false);
}
EXPORT_SYMBOL_GPL(__init_srcu_struct_fast_updown);
int __init_srcu_struct_atomic(struct srcu_struct *ssp, const char *name, struct lock_class_key *key)
{
ssp->srcu_reader_flavor = SRCU_READ_FLAVOR_ATOMIC;
- return __init_srcu_struct_common(ssp, name, key);
+ return __init_srcu_struct_common(ssp, name, key, true);
}
EXPORT_SYMBOL_GPL(__init_srcu_struct_atomic);
@@ -414,7 +415,7 @@ EXPORT_SYMBOL_GPL(init_srcu_struct_fast_updown);
int init_srcu_struct_atomic(struct srcu_struct *ssp)
{
ssp->srcu_reader_flavor = SRCU_READ_FLAVOR_ATOMIC;
- return init_srcu_struct_fields(ssp, false, false);
+ return init_srcu_struct_fields(ssp, false, true);
}
EXPORT_SYMBOL_GPL(init_srcu_struct_atomic);
--
2.40.1