Linux RCU subsystem development
 help / color / mirror / Atom feed
From: Uladzislau Rezki <urezki@gmail.com>
To: Frederic Weisbecker <frederic@kernel.org>
Cc: "Uladzislau Rezki (Sony)" <urezki@gmail.com>,
	"Paul E . McKenney" <paulmck@kernel.org>,
	Joel Fernandes <joelagnelf@nvidia.com>,
	Boqun Feng <boqun.feng@gmail.com>, RCU <rcu@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Samir M <samir@linux.ibm.com>
Subject: Re: [PATCH -next v2 10/11] rcu: Latch normal synchronize_rcu() path on flood
Date: Wed, 20 May 2026 17:16:19 +0200	[thread overview]
Message-ID: <ag3QQ7zWGMDx4MbV@milan> (raw)
In-Reply-To: <ag3IhirNF-wlDE1W@localhost.localdomain>

On Wed, May 20, 2026 at 04:43:18PM +0200, Frederic Weisbecker wrote:
> Le Tue, May 19, 2026 at 09:45:23PM +0200, Uladzislau Rezki (Sony) a écrit :
> > Currently, rcu_normal_wake_from_gp is only enabled by default
> > on small systems(<= 16 CPUs) or when a user explicitly set it
> > enabled.
> > 
> > Introduce an adaptive latching mechanism:
> >  * Track the number of in-flight synchronize_rcu() requests
> >    using a new rcu_sr_normal_count counter;
> > 
> >  * If the count reaches/exceeds RCU_SR_NORMAL_LATCH_THR(64),
> >    it sets the rcu_sr_normal_latched, reverting new requests
> >    onto the scaled wait_rcu_gp() path;
> > 
> >  * The latch is cleared only when the pending requests are fully
> >    drained(nr == 0);
> > 
> >  * Enables rcu_normal_wake_from_gp by default for all systems,
> >    relying on this dynamic throttling instead of static CPU
> >    limits.
> > 
> > Testing(synthetic flood workload):
> >   * Kernel version: 6.19.0-rc6
> >   * Number of CPUs: 1536
> >   * 60K concurrent synchronize_rcu() calls
> > 
> > Perf(cycles, system-wide):
> >   total cycles: 932020263832
> >   rcu_sr_normal_add_req(): 2650282811 cycles(~0.28%)
> > 
> > Perf report excerpt:
> >   0.01%  0.01%  sync_test/...  [k] rcu_sr_normal_add_req
> > 
> > Measured overhead of rcu_sr_normal_add_req() remained ~0.28%
> > of total CPU cycles in this synthetic stress test.
> > 
> > Tested-by: Samir M <samir@linux.ibm.com>
> > Suggested-by: Joel Fernandes <joelagnelf@nvidia.com>
> > Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
> > ---
> >  .../admin-guide/kernel-parameters.txt         | 10 ++--
> >  kernel/rcu/tree.c                             | 52 ++++++++++++++-----
> >  2 files changed, 44 insertions(+), 18 deletions(-)
> > 
> > diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
> > index 4d0f545fb3ec..d5db2e85d551 100644
> > --- a/Documentation/admin-guide/kernel-parameters.txt
> > +++ b/Documentation/admin-guide/kernel-parameters.txt
> > @@ -5862,13 +5862,13 @@ Kernel parameters
> >  			use a call_rcu[_hurry]() path. Please note, this is for a
> >  			normal grace period.
> >  
> > -			How to enable it:
> > +			How to disable it:
> >  
> > -			echo 1 > /sys/module/rcutree/parameters/rcu_normal_wake_from_gp
> > -			or pass a boot parameter "rcutree.rcu_normal_wake_from_gp=1"
> > +			echo 0 > /sys/module/rcutree/parameters/rcu_normal_wake_from_gp
> > +			or pass a boot parameter "rcutree.rcu_normal_wake_from_gp=0"
> >  
> > -			Default is 1 if num_possible_cpus() <= 16 and it is not explicitly
> > -			disabled by the boot parameter passing 0.
> > +			Default is 1 if it is not explicitly disabled by the boot parameter
> > +			passing 0.
> >  
> >  	rcuscale.gp_async= [KNL]
> >  			Measure performance of asynchronous
> > diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
> > index 09f0cef5014c..94274330d1db 100644
> > --- a/kernel/rcu/tree.c
> > +++ b/kernel/rcu/tree.c
> > @@ -1632,17 +1632,21 @@ static void rcu_sr_put_wait_head(struct llist_node *node)
> >  	atomic_set_release(&sr_wn->inuse, 0);
> >  }
> >  
> > -/* Enable rcu_normal_wake_from_gp automatically on small systems. */
> > -#define WAKE_FROM_GP_CPU_THRESHOLD 16
> > -
> > -static int rcu_normal_wake_from_gp = -1;
> > +static int rcu_normal_wake_from_gp = 1;
> >  module_param(rcu_normal_wake_from_gp, int, 0644);
> >  static struct workqueue_struct *sync_wq;
> >  
> > +#define RCU_SR_NORMAL_LATCH_THR 64
> > +
> > +/* Number of in-flight synchronize_rcu() calls queued on srs_next. */
> > +static atomic_long_t rcu_sr_normal_count;
> > +static int rcu_sr_normal_latched; /* 0/1 */
> > +
> >  static void rcu_sr_normal_complete(struct llist_node *node)
> >  {
> >  	struct rcu_synchronize *rs = container_of(
> >  		(struct rcu_head *) node, struct rcu_synchronize, head);
> > +	long nr;
> >  
> >  	WARN_ONCE(IS_ENABLED(CONFIG_PROVE_RCU) &&
> >  		!poll_state_synchronize_rcu_full(&rs->oldstate),
> > @@ -1650,6 +1654,15 @@ static void rcu_sr_normal_complete(struct llist_node *node)
> >  
> >  	/* Finally. */
> >  	complete(&rs->completion);
> > +	nr = atomic_long_dec_return(&rcu_sr_normal_count);
> > +	WARN_ON_ONCE(nr < 0);
> > +
> > +	/*
> > +	 * Unlatch: switch back to normal path when fully
> > +	 * drained and if it has been latched.
> > +	 */
> > +	if (nr == 0)
> > +		(void)cmpxchg(&rcu_sr_normal_latched, 1, 0);
> 
> Given that it's already ordered by the llist add / del and the
> atomic_long_inc/dec_return, there should be no chance for bad
> things happening such as negative returned dec.
> 
> So it could be cmpxchg_relaxed(). But anyway, just an optimization.
> 
> In any case,
> 
> Reviewed-by: Frederic Weisbecker <frederic@kernel.org>
> 
Hello, Frederic!

I change it accordingly, please check!

diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
index 94274330d1db..2c76b59f75de 100644
--- a/kernel/rcu/tree.c
+++ b/kernel/rcu/tree.c
@@ -1655,14 +1655,13 @@ static void rcu_sr_normal_complete(struct llist_node *node)
 	/* Finally. */
 	complete(&rs->completion);
 	nr = atomic_long_dec_return(&rcu_sr_normal_count);
-	WARN_ON_ONCE(nr < 0);
 
 	/*
 	 * Unlatch: switch back to normal path when fully
 	 * drained and if it has been latched.
 	 */
 	if (nr == 0)
-		(void)cmpxchg(&rcu_sr_normal_latched, 1, 0);
+		(void)cmpxchg_relaxed(&rcu_sr_normal_latched, 1, 0);
 }
 
 static void rcu_sr_normal_gp_cleanup_work(struct work_struct *work)
@@ -1823,7 +1822,7 @@ static void rcu_sr_normal_add_req(struct rcu_synchronize *rs)
 	 * because it only selects between the fast and fallback paths.
 	 */
 	if (nr == RCU_SR_NORMAL_LATCH_THR)
-		(void)cmpxchg(&rcu_sr_normal_latched, 0, 1);
+		(void)cmpxchg_relaxed(&rcu_sr_normal_latched, 0, 1);
 
 	/* Publish for the GP kthread/worker. */
 	llist_add((struct llist_node *) &rs->head, &rcu_state.srs_next);

Sounds good?

--
Uladzislau Rezki

  reply	other threads:[~2026-05-20 15:16 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-19 19:45 [PATCH -next v2 00/11] Candidate patches for the v7.2 merge window Uladzislau Rezki (Sony)
2026-05-19 19:45 ` [PATCH -next v2 01/11] rcutorture: Fully test lazy RCU Uladzislau Rezki (Sony)
2026-05-19 19:45 ` [PATCH -next v2 02/11] torture: Add torture_sched_set_normal() for user-specified nice values Uladzislau Rezki (Sony)
2026-05-19 19:45 ` [PATCH -next v2 03/11] torture: Improve kvm-series.sh header comment Uladzislau Rezki (Sony)
2026-05-19 19:45 ` [PATCH -next v2 04/11] torture: Allow "norm" abbreviation for "normal" Uladzislau Rezki (Sony)
2026-05-19 19:45 ` [PATCH -next v2 05/11] srcu: Fix kerneldoc header comment typo in srcu_down_read_fast() Uladzislau Rezki (Sony)
2026-05-19 19:45 ` [PATCH -next v2 06/11] checkpatch: Undeprecate rcu_read_lock_trace() and rcu_read_unlock_trace() Uladzislau Rezki (Sony)
2026-05-19 19:45 ` [PATCH -next v2 07/11] rcu: Simplify rcu_do_batch() by applying clamp() Uladzislau Rezki (Sony)
2026-05-20 12:26   ` Frederic Weisbecker
2026-05-20 13:54     ` Uladzislau Rezki
2026-05-19 19:45 ` [PATCH -next v2 08/11] rcu: Simplify param_set_next_fqs_jiffies() by applying clamp_val() Uladzislau Rezki (Sony)
2026-05-20 12:31   ` Frederic Weisbecker
2026-05-19 19:45 ` [PATCH -next v2 09/11] rcu: Document rcu_access_pointer() feeding into cmpxchg() Uladzislau Rezki (Sony)
2026-05-20 12:44   ` Frederic Weisbecker
2026-05-19 19:45 ` [PATCH -next v2 10/11] rcu: Latch normal synchronize_rcu() path on flood Uladzislau Rezki (Sony)
2026-05-20 14:43   ` Frederic Weisbecker
2026-05-20 15:16     ` Uladzislau Rezki [this message]
2026-05-20 22:28       ` Frederic Weisbecker
2026-05-21  5:23         ` Uladzislau Rezki
2026-05-19 19:45 ` [PATCH -next v2 11/11] rcu-tasks: Fix possible boot-time tests failed for the call_rcu_tasks() Uladzislau Rezki (Sony)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ag3QQ7zWGMDx4MbV@milan \
    --to=urezki@gmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=frederic@kernel.org \
    --cc=joelagnelf@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paulmck@kernel.org \
    --cc=rcu@vger.kernel.org \
    --cc=samir@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox