Skip to contentSkip to conversation

srcu: Use suitable gfp_flags for the init_srcu_struct_nodes()

PATCH Superseded Zqiang 2 participants 5 messages Dec 13, 2025 – Dec 14, 2025

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Zqiang

author reviewer
#0 lore raw

PATCH 1/1 srcu: Use suitable gfp_flags for the init_srcu_struct_nodes()

In some kernels which is set convert_to_big to SRCU_SIZING_INIT, for use the init_srcu_struct*() to initialized srcu structure, the is_static parameters is always false, the memory allocation for srcu_sup structure's->node can use GFP_KERNEL flags.

---
 kernel/rcu/srcutree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/rcu/srcutree.c +1 -1
index ea3f128de06f..e4571b569752 100644
@@ -262,7 +262,7 @@ static int init_srcu_struct_fields(struct srcu_struct *ssp, bool is_static)
 	ssp->srcu_sup->srcu_gp_seq_needed_exp = SRCU_GP_SEQ_INITIAL_VAL;
 	ssp->srcu_sup->srcu_last_gp_end = ktime_get_mono_fast_ns();
 	if (READ_ONCE(ssp->srcu_sup->srcu_size_state) == SRCU_SIZE_SMALL && SRCU_SIZING_IS_INIT()) {
-		if (!init_srcu_struct_nodes(ssp, GFP_ATOMIC))
+		if (!init_srcu_struct_nodes(ssp, !is_static ? GFP_KERNEL : GFP_ATOMIC))
 			goto err_free_sda;
 		WRITE_ONCE(ssp->srcu_sup->srcu_size_state, SRCU_SIZE_BIG);
 	}
Signature · 1 line
2.48.1
maintainer
#1 lore raw
Quoted 19 lines · Zqiang

In some kernels which is set convert_to_big to SRCU_SIZING_INIT, for use the init_srcu_struct*() to initialized srcu structure, the is_static parameters is always false, the memory allocation for srcu_sup structure's->node can use GFP_KERNEL flags.

---
kernel/rcu/srcutree.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
kernel/rcu/srcutree.c +0 -0
index ea3f128de06f..e4571b569752 100644

kernel/rcu/srcutree.c static int init_srcu_struct_fields(struct srcu_struct *ssp, bool is_static) · line 265

Quoted 5 lines
kernel/rcu/srcutree.c +1 -1
@@ -262,7 +262,7 @@ static int init_srcu_struct_fields(struct srcu_struct *ssp, bool is_static)
   ssp->srcu_sup->srcu_gp_seq_needed_exp = SRCU_GP_SEQ_INITIAL_VAL;
   ssp->srcu_sup->srcu_last_gp_end = ktime_get_mono_fast_ns();
   if (READ_ONCE(ssp->srcu_sup->srcu_size_state) == SRCU_SIZE_SMALL && SRCU_SIZING_IS_INIT()) {
-        if (!init_srcu_struct_nodes(ssp, GFP_ATOMIC))
+        if (!init_srcu_struct_nodes(ssp, !is_static ? GFP_KERNEL : GFP_ATOMIC))

Nit: please avoid double negatives, becomes a bit harder to read:

Instead,
is_static ? GFP_ATOMIC : GFP_KERNEL

Is it also worthwhile adding a might_sleep() here for additional robustness?

Thanks.

Quoted 7 lines
kernel/rcu/srcutree.c +0 -1
           goto err_free_sda;
       WRITE_ONCE(ssp->srcu_sup->srcu_size_state, SRCU_SIZE_BIG);
   }
--

2.48.1

author reviewer
#2 lore raw
Quoted 25 lines
Quoted 14 lines · Zqiang

In some kernels which is set convert_to_big to SRCU_SIZING_INIT, for use the init_srcu_struct*() to initialized srcu structure, the is_static parameters is always false, the memory allocation for srcu_sup structure's->node can use GFP_KERNEL flags.

---

 kernel/rcu/srcutree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 11 lines

diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c
index ea3f128de06f..e4571b569752 100644
--- a/kernel/rcu/srcutree.c
+++ b/kernel/rcu/srcutree.c
@@ -262,7 +262,7 @@ static int init_srcu_struct_fields(struct srcu_struct *ssp, bool is_static) ssp->srcu_sup->srcu_gp_seq_needed_exp = SRCU_GP_SEQ_INITIAL_VAL; ssp->srcu_sup->srcu_last_gp_end = ktime_get_mono_fast_ns();
if (READ_ONCE(ssp->srcu_sup->srcu_size_state) == SRCU_SIZE_SMALL && SRCU_SIZING_IS_INIT()) {
- if (!init_srcu_struct_nodes(ssp, GFP_ATOMIC))
+ if (!init_srcu_struct_nodes(ssp, !is_static ? GFP_KERNEL : GFP_ATOMIC))

Quoted 4 lines

Nit: please avoid double negatives, becomes a bit harder to read:

Instead,
is_static ? GFP_ATOMIC : GFP_KERNEL

Ok, will do that.

Quoted 2 lines

Is it also worthwhile adding a might_sleep() here for additional robustness?

Would it be more appropriate to add might_sleep() before allocating ssp->srcu_sup ?

Thanks
Zqiang

Quoted 11 lines

Thanks.

Quoted 7 lines

goto err_free_sda;
WRITE_ONCE(ssp->srcu_sup->srcu_size_state, SRCU_SIZE_BIG); }
--
2.48.1

maintainer
#3 lore raw
Quoted 36 lines · Zqiang



Quoted 28 lines
Quoted 20 lines
Quoted 4 lines · Zqiang

In some kernels which is set convert_to_big to SRCU_SIZING_INIT, for use the init_srcu_struct*() to initialized srcu structure, the is_static parameters is always false, the memory allocation for srcu_sup structure's->node can use GFP_KERNEL flags.

---
kernel/rcu/srcutree.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
kernel/rcu/srcutree.c +0 -0
index ea3f128de06f..e4571b569752 100644

kernel/rcu/srcutree.c static int init_srcu_struct_fields(struct srcu_struct *ssp, bool is_static) · line 266

Quoted 6 lines
kernel/rcu/srcutree.c +1 -1
@@ -262,7 +262,7 @@ static int init_srcu_struct_fields(struct srcu_struct *ssp, bool is_static)
 ssp->srcu_sup->srcu_gp_seq_needed_exp = SRCU_GP_SEQ_INITIAL_VAL;
 ssp->srcu_sup->srcu_last_gp_end = ktime_get_mono_fast_ns();
 if (READ_ONCE(ssp->srcu_sup->srcu_size_state) == SRCU_SIZE_SMALL && SRCU_SIZING_IS_INIT()) {
- if (!init_srcu_struct_nodes(ssp, GFP_ATOMIC))
+ if (!init_srcu_struct_nodes(ssp, !is_static ? GFP_KERNEL : GFP_ATOMIC))
 

Nit: please avoid double negatives, becomes a bit harder to read:

Quoted 2 lines

Instead,
is_static ? GFP_ATOMIC : GFP_KERNEL

Quoted 7 lines

Ok, will do that.

Quoted 2 lines

Is it also worthwhile adding a might_sleep() here for additional robustness?

Would it be more appropriate to add might_sleep() before allocating ssp->srcu_sup ?

Actually this is probably not needed because the slab allocator already does that for sleepable allocations.

So feel free to ignore the suggestion.;-)

The one reason to do it might just be for documentation.

Thanks.

author reviewer
#4 lore raw
Quoted 45 lines
Quoted 45 lines · Zqiang
Quoted 6 lines

On Dec 13, 2025, at 10:56 PM, Zqiang <[email protected]> wrote:

In some kernels which is set convert_to_big to SRCU_SIZING_INIT, for use the init_srcu_struct*() to initialized srcu structure, the is_static parameters is always false, the memory allocation for srcu_sup structure's->node can use GFP_KERNEL flags.

---

 kernel/rcu/srcutree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c
index ea3f128de06f..e4571b569752 100644
--- a/kernel/rcu/srcutree.c
+++ b/kernel/rcu/srcutree.c
@@ -262,7 +262,7 @@ static int init_srcu_struct_fields(struct srcu_struct *ssp, bool is_static) ssp->srcu_sup->srcu_gp_seq_needed_exp = SRCU_GP_SEQ_INITIAL_VAL; ssp->srcu_sup->srcu_last_gp_end = ktime_get_mono_fast_ns();
if (READ_ONCE(ssp->srcu_sup->srcu_size_state) == SRCU_SIZE_SMALL && SRCU_SIZING_IS_INIT()) {
- if (!init_srcu_struct_nodes(ssp, GFP_ATOMIC))
+ if (!init_srcu_struct_nodes(ssp, !is_static ? GFP_KERNEL : GFP_ATOMIC))

Quoted 6 lines

Nit: please avoid double negatives, becomes a bit harder to read:

Instead,
is_static ? GFP_ATOMIC : GFP_KERNEL

Ok, will do that.

Quoted 1 line
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines

Is it also worthwhile adding a might_sleep() here for additional robustness?

Would it be more appropriate to add might_sleep() before allocating ssp->srcu_sup ?

Actually this is probably not needed because the slab allocator already does that for sleepable allocations.

Yes, I also find the might_alloc() already exists in the slub allocator.

Thanks
Zqiang

Quoted 7 lines

So feel free to ignore the suggestion.;-)

The one reason to do it might just be for documentation.

Thanks.