RCU Archive mirror
 help / color / mirror / Atom feed
From: Uladzislau Rezki <urezki@gmail.com>
To: Joel Fernandes <joel@joelfernandes.org>
Cc: Uladzislau Rezki <urezki@gmail.com>,
	linux-kernel@vger.kernel.org, frederic@kernel.org,
	boqun.feng@gmail.com, neeraj.iitr10@gmail.com,
	rcu@vger.kernel.org, rostedt@goodmis.org,
	"Paul E. McKenney" <paulmck@kernel.org>,
	Neeraj Upadhyay <neeraj.upadhyay@kernel.org>,
	Josh Triplett <josh@joshtriplett.org>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	Lai Jiangshan <jiangshanlai@gmail.com>,
	Zqiang <qiang.zhang1211@gmail.com>
Subject: Re: [PATCH v2 rcu/dev 1/2] rcu/tree: Reduce wake up for synchronize_rcu() common case
Date: Tue, 19 Mar 2024 20:07:08 +0100	[thread overview]
Message-ID: <ZfniXAT6GOL7yy8B@pc636> (raw)
In-Reply-To: <1f7821ce-c036-4824-bb22-6d171714babf@joelfernandes.org>

On Tue, Mar 19, 2024 at 02:52:43PM -0400, Joel Fernandes wrote:
> 
> 
> On 3/19/2024 2:37 PM, Uladzislau Rezki wrote:
> > On Tue, Mar 19, 2024 at 01:33:11PM -0400, Joel Fernandes wrote:
> 
> >>> On 3/19/2024 1:26 PM, Uladzislau Rezki wrote:
> 
> >>>>>>>>>>>> /*
> >>>>>>>>>>>> @@ -1673,7 +1680,7 @@ static void rcu_sr_normal_gp_cleanup_work(struct work_struct *work)
> >>>>>>>>>>>> */
> >>>>>>>>>>>> static void rcu_sr_normal_gp_cleanup(void)
> >>>>>>>>>>>> {
> >>>>>>>>>>>> -    struct llist_node *wait_tail, *next, *rcu;
> >>>>>>>>>>>> +    struct llist_node *wait_tail, *next = NULL, *rcu = NULL;
> >>>>>>>>>>>>   int done = 0;
> >>>>>>>>>>>>
> >>>>>>>>>>>>   wait_tail = rcu_state.srs_wait_tail;
> >>>>>>>>>>>> @@ -1699,16 +1706,35 @@ static void rcu_sr_normal_gp_cleanup(void)
> >>>>>>>>>>>>           break;
> >>>>>>>>>>>>   }
> >>>>>>>>>>>>
> >>>>>>>>>>>> -    // concurrent sr_normal_gp_cleanup work might observe this update.
> >>>>>>>>>>>> -    smp_store_release(&rcu_state.srs_done_tail, wait_tail);
> >>>>>>>>>>>> +    /*
> >>>>>>>>>>>> +     * Fast path, no more users to process. Remove the last wait head
> >>>>>>>>>>>> +     * if no inflight-workers. If there are in-flight workers, let them
> >>>>>>>>>>>> +     * remove the last wait head.
> >>>>>>>>>>>> +     */
> >>>>>>>>>>>> +    WARN_ON_ONCE(!rcu);
> >>>>>>>>>>>>
> >>>>>>>>>>> This assumption is not correct. An "rcu" can be NULL in fact.
> >>>>>>>>>>
> >>>>>>>>>> Hmm I could never trigger that. Are you saying that is true after Neeraj recent patch or something else?
> >>>>>>>>>> Note, after Neeraj patch to handle the lack of heads availability, it could be true so I requested
> >>>>>>>>>> him to rebase his patch on top of this one.
> >>>>>>>>>>
> >>>>>>>>>> However I will revisit my patch and look for if it could occur but please let me know if you knew of a sequence of events to make it NULL.
> >>>>>>>>>>>
> >>>>>>>>> I think we should agree on your patch first otherwise it becomes a bit
> >>>>>>>>> messy or go with a Neeraj as first step and then work on youth. So, i
> >>>>>>>>> reviewed this patch based on latest Paul's dev branch. I see that Neeraj
> >>>>>>>>> needs further work.
> >>>>>>>>
> >>>>>>>> You are right. So the only change is to drop the warning and those braces. Agreed?
> >>>>>>>>
> >>>>>>> Let me check a bit. Looks like correct but just in case.
> >>>>>>>
> >>>>>>
> >>>>>> Thanks. I was also considering improving it for the rcu == NULL case, as
> >>>>>> below. I will test it more before re-sending.
> >>>>>>
> >>>>>> On top of my patch:
> >>>>>>
> >>>>>> ---8<-----------------------
> >>>>>>
> >>>>>> diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
> >>>>>> index 0df659a878ee..a5ef844835d4 100644
> >>>>>> --- a/kernel/rcu/tree.c
> >>>>>> +++ b/kernel/rcu/tree.c
> >>>>>> @@ -1706,15 +1706,18 @@ static void rcu_sr_normal_gp_cleanup(void)
> >>>>>>                         break;
> >>>>>>         }
> >>>>>>
> >>>>>> +
> >>>>>> +       /* Last head stays. No more processing to do. */
> >>>>>> +       if (!rcu)
> >>>>>> +               return;
> >>>>>> +
> >>>>>
> >>>>> Ugh, should be "if (!wait_head->next)"  instead of "if (!rcu)".  But
> >>>>> in any case, the original patch except the warning should hold.
> >>>>> Still, I am testing the above diff now.
> >>>>>
> >>>>>  - Joel
> >>>>>
> >>>> Just in case, it is based on your patch:
> >>>>
> >>>> <snip>
> >>>> diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
> >>>> index bd29fe3c76bf..98546afe7c21 100644
> >>>> --- a/kernel/rcu/tree.c
> >>>> +++ b/kernel/rcu/tree.c
> >>>> @@ -1711,29 +1711,25 @@ static void rcu_sr_normal_gp_cleanup(void)
> >>>>  	 * if no inflight-workers. If there are in-flight workers, let them
> >>>>  	 * remove the last wait head.
> >>>>  	 */
> >>>> -	WARN_ON_ONCE(!rcu);
> >>>> -	ASSERT_EXCLUSIVE_WRITER(rcu_state.srs_done_tail);
> >>>> -
> >>>> -	if (rcu && rcu_sr_is_wait_head(rcu) && rcu->next == NULL &&
> >>>> -		/* Order atomic access with list manipulation. */
> >>>> -		!atomic_read_acquire(&rcu_state.srs_cleanups_pending)) {
> >>>> +	if (wait_tail->next && rcu_sr_is_wait_head(wait_tail->next) && !wait_tail->next->next &&
> >>>> +			!atomic_read_acquire(&rcu_state.srs_cleanups_pending)) {
> >>>
> >>>
> >>> Yes this also works. But also if wait_tail->next == NULL, then you do not need
> >>> to queue worker for that case as well. I sent this as v3.
> >>>
> >> Sorry, I see you did add that later in the patch ;-). I think we have converged
> >> on the final patch then, give or take the use of 'rcu' versus 'wait_tail->next'.
> >>
> > Just combine all parts into one place and resend :)
> 
> Yes sir ;)
> 
Ha-ha :)))))

--
Uladzislau Rezki

      reply	other threads:[~2024-03-19 19:07 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-08 22:44 [PATCH v2 rcu/dev 1/2] rcu/tree: Reduce wake up for synchronize_rcu() common case Joel Fernandes (Google)
2024-03-08 22:44 ` [PATCH v2 rcu/dev 2/2] rcu/tree: Add comments explaining now-offline-CPU QS reports Joel Fernandes (Google)
2024-03-10 19:43   ` Paul E. McKenney
2024-03-11 16:01     ` Joel Fernandes
2024-03-18 18:58 ` [PATCH v2 rcu/dev 1/2] rcu/tree: Reduce wake up for synchronize_rcu() common case Uladzislau Rezki
2024-03-18 21:05   ` Joel Fernandes
2024-03-19  9:53     ` Uladzislau Rezki
2024-03-19 14:29       ` Joel Fernandes
2024-03-19 14:48         ` Uladzislau Rezki
2024-03-19 16:02           ` Joel Fernandes
2024-03-19 16:11             ` Joel Fernandes
2024-03-19 17:26               ` Uladzislau Rezki
2024-03-19 17:29                 ` Joel Fernandes
2024-03-19 17:33                   ` Joel Fernandes
2024-03-19 18:37                     ` Uladzislau Rezki
2024-03-19 18:52                       ` Joel Fernandes
2024-03-19 19:07                         ` Uladzislau Rezki [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=ZfniXAT6GOL7yy8B@pc636 \
    --to=urezki@gmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=frederic@kernel.org \
    --cc=jiangshanlai@gmail.com \
    --cc=joel@joelfernandes.org \
    --cc=josh@joshtriplett.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=neeraj.iitr10@gmail.com \
    --cc=neeraj.upadhyay@kernel.org \
    --cc=paulmck@kernel.org \
    --cc=qiang.zhang1211@gmail.com \
    --cc=rcu@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).