[PATCH 02/17] srcu: Let GP completion take a size-state snapshot

From: Kunwu Chan

Date: Tue Dec 01 2026 - 11:18:58 EST


Allow callers holding both mutexes to pass a SMALL or BIG size state.
The existing wrapper requests a size-state load during completion.

Signed-off-by: Kunwu Chan <kunwu.chan@xxxxxxxxx>
---
kernel/rcu/srcutree.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c
index 1ab5a1cdc163..16b1a6b677e1 100644
--- a/kernel/rcu/srcutree.c
+++ b/kernel/rcu/srcutree.c
@@ -974,6 +974,9 @@ static void srcu_schedule_cbs_snp(struct srcu_struct *ssp, struct srcu_node *snp
srcu_schedule_cbs_sdp(per_cpu_ptr(ssp->sda, cpu), delay);
}

+/* GP-end sentinel, outside the size-state range. */
+#define SRCU_GP_END_CURRENT_SIZE (-1)
+
/*
* Note the end of an SRCU grace period. Initiates callback invocation
* and starts a new grace period if needed.
@@ -982,8 +985,11 @@ static void srcu_schedule_cbs_snp(struct srcu_struct *ssp, struct srcu_node *snp
* instead prevents more than one grace period from starting while we
* are initiating callback invocation. This allows the ->srcu_have_cbs[]
* array to have a finite number of elements.
+ *
+ * SRCU_GP_END_CURRENT_SIZE reads the current size here. The fastpath
+ * samples SMALL or BIG under both mutexes to avoid allocation.
*/
-static void __srcu_gp_end(struct srcu_struct *ssp, bool is_atomic)
+static void __srcu_gp_end(struct srcu_struct *ssp, bool is_atomic, int ss_state)
{
unsigned long cbdelay = 1;
bool cbs;
@@ -996,7 +1002,6 @@ static void __srcu_gp_end(struct srcu_struct *ssp, bool is_atomic)
struct srcu_data *sdp;
unsigned long sgsne;
struct srcu_node *snp;
- int ss_state;
struct srcu_usage *sup = ssp->srcu_sup;

if (!is_atomic) {
@@ -1022,7 +1027,8 @@ static void __srcu_gp_end(struct srcu_struct *ssp, bool is_atomic)
/* A new grace period can start at this point. But only one. */

/* Initiate callback invocation as needed. */
- ss_state = smp_load_acquire(&sup->srcu_size_state);
+ if (ss_state < 0)
+ ss_state = smp_load_acquire(&sup->srcu_size_state); /* Size-state publication. */
if (!is_atomic && ss_state < SRCU_SIZE_WAIT_BARRIER) {
srcu_schedule_cbs_sdp(per_cpu_ptr(ssp->sda, get_boot_cpu_id()),
cbdelay);
@@ -1095,7 +1101,7 @@ static void srcu_gp_end(struct srcu_struct *ssp, bool is_atomic)
/* Prevent more than one additional grace period. */
if (!is_atomic)
mutex_lock(&ssp->srcu_sup->srcu_cb_mutex);
- __srcu_gp_end(ssp, is_atomic);
+ __srcu_gp_end(ssp, is_atomic, SRCU_GP_END_CURRENT_SIZE);
}

/*
--
2.43.0