Linux RCU subsystem development
 help / color / mirror / Atom feed
From: Joel Fernandes <joelagnelf@nvidia.com>
To: "Paul E. McKenney" <paulmck@kernel.org>
Cc: linux-kernel@vger.kernel.org,
	Frederic Weisbecker <frederic@kernel.org>,
	Neeraj Upadhyay <neeraj.upadhyay@kernel.org>,
	Josh Triplett <josh@joshtriplett.org>,
	Boqun Feng <boqun.feng@gmail.com>,
	Uladzislau Rezki <urezki@gmail.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	Lai Jiangshan <jiangshanlai@gmail.com>,
	Zqiang <qiang.zhang@linux.dev>,
	rcu@vger.kernel.org
Subject: Re: [PATCH v2] rcu: Reduce synchronize_rcu() latency by reporting GP kthread's CPU QS early
Date: Thu, 25 Dec 2025 21:33:39 -0500	[thread overview]
Message-ID: <20251226023339.GB739018@joelbox2> (raw)
In-Reply-To: <b355f3ed-3916-4419-951b-33e3788427f4@paulmck-laptop>

On Thu, Dec 25, 2025 at 10:35:44AM -0800, Paul E. McKenney wrote:
> On Mon, Dec 22, 2025 at 10:46:29PM -0500, Joel Fernandes wrote:
> > The RCU grace period mechanism uses a two-phase FQS (Force Quiescent
> > State) design where the first FQS saves dyntick-idle snapshots and
> > the second FQS compares them. This results in long and unnecessary latency
> > for synchronize_rcu() on idle systems (two FQS waits of ~3ms each with
> > 1000HZ) whenever one FQS wait sufficed.
> > 
> > Some investigations showed that the GP kthread's CPU is the holdout CPU
> > a lot of times after the first FQS as - it cannot be detected as "idle"
> > because it's actively running the FQS scan in the GP kthread.
> > 
> > Therefore, at the end of rcu_gp_init(), immediately report a quiescent
> > state for the GP kthread's CPU using rcu_qs() + rcu_report_qs_rdp(). The
> > GP kthread cannot be in an RCU read-side critical section while running
> > GP initialization, so this is safe and results in significant latency
> > improvements.
> > 
> > I benchmarked 100 synchronize_rcu() calls with 32 CPUs, 10 runs each
> > showing significant latency improvements (default settings for fqs jiffies):
> > 
> > Baseline (without fix):
> > | Run | Mean      | Min      | Max       |
> > |-----|-----------|----------|-----------|
> > | 1   | 10.088 ms | 9.989 ms | 18.848 ms |
> > | 2   | 10.064 ms | 9.982 ms | 16.470 ms |
> > | 3   | 10.051 ms | 9.988 ms | 15.113 ms |
> > | 4   | 10.125 ms | 9.929 ms | 22.411 ms |
> > | 5   |  8.695 ms | 5.996 ms | 15.471 ms |
> > | 6   | 10.157 ms | 9.977 ms | 25.723 ms |
> > | 7   | 10.102 ms | 9.990 ms | 20.224 ms |
> > | 8   |  8.050 ms | 5.985 ms | 10.007 ms |
> > | 9   | 10.059 ms | 9.978 ms | 15.934 ms |
> > | 10  | 10.077 ms | 9.984 ms | 17.703 ms |
> > 
> > With fix:
> > | Run | Mean     | Min      | Max       |
> > |-----|----------|----------|-----------|
> > | 1   | 6.027 ms | 5.915 ms |  8.589 ms |
> > | 2   | 6.032 ms | 5.984 ms |  9.241 ms |
> > | 3   | 6.010 ms | 5.986 ms |  7.004 ms |
> > | 4   | 6.076 ms | 5.993 ms | 10.001 ms |
> > | 5   | 6.084 ms | 5.893 ms | 10.250 ms |
> > | 6   | 6.034 ms | 5.908 ms |  9.456 ms |
> > | 7   | 6.051 ms | 5.993 ms | 10.000 ms |
> > | 8   | 6.057 ms | 5.941 ms | 10.001 ms |
> > | 9   | 6.016 ms | 5.927 ms |  7.540 ms |
> > | 10  | 6.036 ms | 5.993 ms |  9.579 ms |
> > 
> > Summary:
> > - Mean latency: 9.75 ms -> 6.04 ms (38% improvement)
> > - Max latency:  25.72 ms -> 10.25 ms (60% improvement)
> > 
> > Tested rcutorture TREE and SRCU configurations.
> > 
> > [apply paulmck feedack on moving logic to rcu_gp_init()]
> 
> If anything, these numbers look better, so good show!!!

Thanks, I ended up collecting more samples in the v2 to further confirm the
improvements.

> Are there workloads that might be hurt by some side effect such
> as increased CPU utilization by the RCU grace-period kthread?  One
> non-mainstream hypothetical situation that comes to mind is a kernel
> built with SMP=y but running on a single-CPU system with a high-frequence
> periodic interrupt that does call_rcu().  Might that result in the RCU
> grace-period kthread chewing up the entire CPU?

There are still GP delays due to FQS, even with this change, so it could not
chew up the entire CPU I believe. The GP cycle should still insert delays
into the GP kthread. I did not notice in my testing that synchronize_rcu()
latency dropping to sub millisecond, it was still limited by the timer wheel
delays and the FQS delays.

> For a non-hypothetical case, could you please see if one of the
> battery-powered embedded guys would be willing to test this?

My suspicion is the battery-powered folks are already running RCU_LAZY to
reduce RCU activity, so they wouldn't be effected. call_rcu() during idleness
will be going to the bypass. Last I checked, Android and ChromeOS were both
enabling RCU_LAZY everywhere (back when I was at Google).

Uladzislau works on embedded (or at least till recently) and had recently
checked this area for improvements so I think he can help quantify too
perhaps. He is on CC. I personally don't directly work on embedded at the
moment, just big compute hungry machines. ;-) Uladzislau, would you have some
time to test on your Android devices?

thanks,

 - Joel


  reply	other threads:[~2025-12-26  2:33 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-23  3:46 [PATCH v2] rcu: Reduce synchronize_rcu() latency by reporting GP kthread's CPU QS early Joel Fernandes
2025-12-25 18:35 ` Paul E. McKenney
2025-12-26  2:33   ` Joel Fernandes [this message]
2025-12-28 17:57     ` Uladzislau Rezki
2025-12-29  0:04       ` Paul E. McKenney
2025-12-29  2:49         ` Joel Fernandes
2025-12-29  4:37           ` Paul E. McKenney
2025-12-29 16:28             ` Joel Fernandes
2025-12-29 17:02               ` Paul E. McKenney
2025-12-29 13:28           ` Uladzislau Rezki
2025-12-29 15:53             ` Paul E. McKenney
2025-12-29 16:25               ` Uladzislau Rezki
2025-12-29 17:02                 ` Paul E. McKenney
2025-12-29 20:36                   ` Joel Fernandes
2025-12-29 11:47         ` Uladzislau Rezki

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=20251226023339.GB739018@joelbox2 \
    --to=joelagnelf@nvidia.com \
    --cc=boqun.feng@gmail.com \
    --cc=frederic@kernel.org \
    --cc=jiangshanlai@gmail.com \
    --cc=josh@joshtriplett.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=neeraj.upadhyay@kernel.org \
    --cc=paulmck@kernel.org \
    --cc=qiang.zhang@linux.dev \
    --cc=rcu@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=urezki@gmail.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