From: Joel Fernandes <joel@joelfernandes.org>
To: "Paul E. McKenney" <paulmck@kernel.org>
Cc: linux-kernel@vger.kernel.org, urezki@gmail.com,
Davidlohr Bueso <dave@stgolabs.net>,
Ingo Molnar <mingo@redhat.com>,
Josh Triplett <josh@joshtriplett.org>,
Lai Jiangshan <jiangshanlai@gmail.com>,
Marco Elver <elver@google.com>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
rcu@vger.kernel.org, Steven Rostedt <rostedt@goodmis.org>
Subject: Re: [PATCH 1/7] rcu/segcblist: Prevent useless GP start if no CBs to accelerate
Date: Thu, 18 Jun 2020 20:04:41 -0400 [thread overview]
Message-ID: <20200619000441.GE40119@google.com> (raw)
In-Reply-To: <20200618230934.GA31937@paulmck-ThinkPad-P72>
On Thu, Jun 18, 2020 at 04:09:34PM -0700, Paul E. McKenney wrote:
> On Thu, Jun 18, 2020 at 03:11:19PM -0700, Paul E. McKenney wrote:
> > On Thu, Jun 18, 2020 at 04:29:49PM -0400, Joel Fernandes (Google) wrote:
> >
> > First, this looks like a very nice optimization, thank you!
Thanks!
> > > Cc: urezki@gmail.com
> > > Signed-off-by: Joel Fernandes (Google) <joel@joelfernandes.org>
>
> As discussed over IRC, I updated the patch as shown below. Does that
> work for you?
Yes, that works for me. Thanks!
- Joel
> Thanx, Paul
>
> ------------------------------------------------------------------------
>
> commit ec037e1f438074eb16fd68a63d699fc419c9ba0c
> Author: Joel Fernandes (Google) <joel@joelfernandes.org>
> Date: Thu Jun 18 16:29:49 2020 -0400
>
> rcu/segcblist: Prevent useless GP start if no CBs to accelerate
>
> The rcu_segcblist_accelerate() function returns true iff it is necessary
> to request another grace period. A tracing session showed that this
> function unnecessarily requests grace periods.
>
> For exmaple, consider the following sequence of events:
> 1. Callbacks are queued only on the NEXT segment of CPU A's callback list.
> 2. CPU A runs RCU_SOFTIRQ, accelerating these callbacks from NEXT to WAIT.
> 3. Thus rcu_segcblist_accelerate() returns true, requesting grace period N.
> 4. RCU's grace-period kthread wakes up on CPU B and starts grace period N.
> 4. CPU A notices the new grace period and invokes RCU_SOFTIRQ.
> 5. CPU A's RCU_SOFTIRQ again invokes rcu_segcblist_accelerate(), but
> there are no new callbacks. However, rcu_segcblist_accelerate()
> nevertheless (uselessly) requests a new grace period N+1.
>
> This extra grace period results in additional lock contention and also
> additional wakeups, all for no good reason.
>
> This commit therefore adds a check to rcu_segcblist_accelerate() that
> prevents the return of true when there are no new callbacks.
>
> This change reduces the number of grace periods (GPs) and wakeups in each
> of eleven five-second rcutorture runs as follows:
>
> +----+-------------------+-------------------+
> | # | Number of GPs | Number of Wakeups |
> +====+=========+=========+=========+=========+
> | 1 | With | Without | With | Without |
> +----+---------+---------+---------+---------+
> | 2 | 75 | 89 | 113 | 119 |
> +----+---------+---------+---------+---------+
> | 3 | 62 | 91 | 105 | 123 |
> +----+---------+---------+---------+---------+
> | 4 | 60 | 79 | 98 | 110 |
> +----+---------+---------+---------+---------+
> | 5 | 63 | 79 | 99 | 112 |
> +----+---------+---------+---------+---------+
> | 6 | 57 | 89 | 96 | 123 |
> +----+---------+---------+---------+---------+
> | 7 | 64 | 85 | 97 | 118 |
> +----+---------+---------+---------+---------+
> | 8 | 58 | 83 | 98 | 113 |
> +----+---------+---------+---------+---------+
> | 9 | 57 | 77 | 89 | 104 |
> +----+---------+---------+---------+---------+
> | 10 | 66 | 82 | 98 | 119 |
> +----+---------+---------+---------+---------+
> | 11 | 52 | 82 | 83 | 117 |
> +----+---------+---------+---------+---------+
>
> The reduction in the number of wakeups ranges from 5% to 40%.
>
> Cc: urezki@gmail.com
> [ paulmck: Rework commit log and comment. ]
> Signed-off-by: Joel Fernandes (Google) <joel@joelfernandes.org>
> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
>
> diff --git a/kernel/rcu/rcu_segcblist.c b/kernel/rcu/rcu_segcblist.c
> index 9a0f661..2d2a6b6b9 100644
> --- a/kernel/rcu/rcu_segcblist.c
> +++ b/kernel/rcu/rcu_segcblist.c
> @@ -475,8 +475,16 @@ bool rcu_segcblist_accelerate(struct rcu_segcblist *rsclp, unsigned long seq)
> * Also advance to the oldest segment of callbacks whose
> * ->gp_seq[] completion is at or after that passed in via "seq",
> * skipping any empty segments.
> + *
> + * Note that segment "i" (and any lower-numbered segments
> + * containing older callbacks) will be unaffected, and their
> + * grace-period numbers remain unchanged. For example, if i ==
> + * WAIT_TAIL, then neither WAIT_TAIL nor DONE_TAIL will be touched.
> + * Instead, the CBs in NEXT_TAIL will be merged with those in
> + * NEXT_READY_TAIL and the grace-period number of NEXT_READY_TAIL
> + * would be updated. NEXT_TAIL would then be empty.
> */
> - if (++i >= RCU_NEXT_TAIL)
> + if (rcu_segcblist_restempty(rsclp, i) || ++i >= RCU_NEXT_TAIL)
> return false;
>
> /*
prev parent reply other threads:[~2020-06-19 0:04 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-18 20:29 [PATCH 1/7] rcu/segcblist: Prevent useless GP start if no CBs to accelerate Joel Fernandes (Google)
2020-06-18 20:29 ` [PATCH 2/7] rcu/trace: Add tracing for how segcb list changes Joel Fernandes (Google)
2020-06-18 22:16 ` Paul E. McKenney
2020-06-18 23:52 ` Joel Fernandes
2020-06-18 20:29 ` [PATCH 3/7] rcu/trace: Add name of the source for gp_seq Joel Fernandes (Google)
2020-06-18 22:19 ` Paul E. McKenney
2020-06-18 23:51 ` Joel Fernandes
2020-06-19 0:12 ` Paul E. McKenney
2020-06-19 0:56 ` Joel Fernandes
2020-06-19 1:08 ` Joel Fernandes
2020-06-19 0:01 ` Steven Rostedt
2020-06-19 1:01 ` Joel Fernandes
2020-06-18 20:29 ` [PATCH 4/7] rcu/trace: Print negative GP numbers correctly Joel Fernandes (Google)
2020-06-18 22:30 ` Paul E. McKenney
2020-06-18 20:29 ` [PATCH 5/7] rcu/trace: Use rsp's gp_seq in acceleration's rcu_grace_period tracepoint Joel Fernandes (Google)
2020-06-18 22:27 ` Paul E. McKenney
2020-06-18 23:54 ` Joel Fernandes
2020-06-18 20:29 ` [PATCH 6/7] rcutorture: Add support to get the number of wakeups of main GP kthread Joel Fernandes (Google)
2020-06-18 22:40 ` Paul E. McKenney
2020-06-19 0:01 ` Joel Fernandes
2020-06-19 0:12 ` Paul E. McKenney
2020-06-19 1:00 ` Joel Fernandes
2020-06-19 3:23 ` Paul E. McKenney
2020-06-18 20:29 ` [PATCH 7/7] rcutorture: Add number of GP information to reports Joel Fernandes (Google)
2020-06-18 23:27 ` Paul E. McKenney
2020-06-18 22:11 ` [PATCH 1/7] rcu/segcblist: Prevent useless GP start if no CBs to accelerate Paul E. McKenney
2020-06-18 23:09 ` Paul E. McKenney
2020-06-19 0:04 ` Joel Fernandes [this message]
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=20200619000441.GE40119@google.com \
--to=joel@joelfernandes.org \
--cc=dave@stgolabs.net \
--cc=elver@google.com \
--cc=jiangshanlai@gmail.com \
--cc=josh@joshtriplett.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mingo@redhat.com \
--cc=paulmck@kernel.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.