All of lore.kernel.org
 help / color / mirror / Atom feed
From: Uladzislau Rezki <urezki@gmail.com>
To: "Paul E. McKenney" <paulmck@kernel.org>
Cc: Joel Fernandes <joel@joelfernandes.org>,
	Uladzislau Rezki <urezki@gmail.com>,
	rcu@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH RFC] rcu/kfree: Do not request RCU when not needed
Date: Wed, 2 Nov 2022 18:24:20 +0100	[thread overview]
Message-ID: <Y2KnxKDebPKiqTFZ@pc636> (raw)
In-Reply-To: <20221102163544.GM5600@paulmck-ThinkPad-P17-Gen-1>

On Wed, Nov 02, 2022 at 09:35:44AM -0700, Paul E. McKenney wrote:
> On Wed, Nov 02, 2022 at 12:13:17PM -0400, Joel Fernandes wrote:
> > On Wed, Nov 2, 2022 at 8:37 AM Uladzislau Rezki <urezki@gmail.com> wrote:
> > >
> > > On Sat, Oct 29, 2022 at 01:28:56PM +0000, Joel Fernandes (Google) wrote:
> > > > On ChromeOS, I am (almost) always seeing the optimization trigger.
> > > > Tested boot up and trace_printk'ing how often it triggers.
> > > >
> > > > Signed-off-by: Joel Fernandes (Google) <joel@joelfernandes.org>
> > > > ---
> > > >  kernel/rcu/tree.c | 18 +++++++++++++++++-
> > > >  1 file changed, 17 insertions(+), 1 deletion(-)
> > > >
> > > > diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
> > > > index 591187b6352e..3e4c50b9fd33 100644
> > > > --- a/kernel/rcu/tree.c
> > > > +++ b/kernel/rcu/tree.c
> > > > @@ -2935,6 +2935,7 @@ struct kfree_rcu_cpu_work {
> > > >
> > > >  /**
> > > >   * struct kfree_rcu_cpu - batch up kfree_rcu() requests for RCU grace period
> > > > + * @rdp: The rdp of the CPU that this kfree_rcu corresponds to.
> > > >   * @head: List of kfree_rcu() objects not yet waiting for a grace period
> > > >   * @bkvhead: Bulk-List of kvfree_rcu() objects not yet waiting for a grace period
> > > >   * @krw_arr: Array of batches of kfree_rcu() objects waiting for a grace period
> > > > @@ -2964,6 +2965,8 @@ struct kfree_rcu_cpu {
> > > >       struct kfree_rcu_cpu_work krw_arr[KFREE_N_BATCHES];
> > > >       raw_spinlock_t lock;
> > > >       struct delayed_work monitor_work;
> > > > +     struct rcu_data *rdp;
> > > > +     unsigned long last_gp_seq;
> > > >       bool initialized;
> > > >       int count;
> > > >
> > > > @@ -3167,6 +3170,7 @@ schedule_delayed_monitor_work(struct kfree_rcu_cpu *krcp)
> > > >                       mod_delayed_work(system_wq, &krcp->monitor_work, delay);
> > > >               return;
> > > >       }
> > > > +     krcp->last_gp_seq = krcp->rdp->gp_seq;
> > > >       queue_delayed_work(system_wq, &krcp->monitor_work, delay);
> > > >  }
> > > >
> > > > @@ -3217,7 +3221,17 @@ static void kfree_rcu_monitor(struct work_struct *work)
> > > >                       // be that the work is in the pending state when
> > > >                       // channels have been detached following by each
> > > >                       // other.
> > > > -                     queue_rcu_work(system_wq, &krwp->rcu_work);
> > > > +                     //
> > > > +                     // NOTE about gp_seq wrap: In case of gp_seq overflow,
> > > > +                     // it is possible for rdp->gp_seq to be less than
> > > > +                     // krcp->last_gp_seq even though a GP might be over. In
> > > > +                     // this rare case, we would just have one extra GP.
> > > > +                     if (krcp->last_gp_seq &&
> > > >
> > > This check can be eliminated i think. A kfree_rcu_cpu is defined as
> > > static so by default the last_gp_set is set to zero.
> > 
> > Ack.
> > 
> > > > @@ -4802,6 +4816,8 @@ static void __init kfree_rcu_batch_init(void)
> > > >       for_each_possible_cpu(cpu) {
> > > >               struct kfree_rcu_cpu *krcp = per_cpu_ptr(&krc, cpu);
> > > >
> > > > +             krcp->rdp = per_cpu_ptr(&rcu_data, cpu);
> > > > +             krcp->last_gp_seq = 0;
> > > >
> > > Yep. This one can be just dropped.
> > >
> > > But all the rest looks good :) I will give it a try from test point of
> > > view. It is interested from the memory footprint point of view.
> > 
> > Ack. Thanks. Even though we should not sample rdp->gp_seq, I think it
> > is still worth a test.
> 
> Just for completeness, the main purpose of rdp->gp_seq is to reject
> quiescent states that were seen during already-completed grace periods.
> 
So it means that instead of gp_seq reading we should take a snaphshot
of the current state:

snp = get_state_synchronize_rcu();

and later on do a:

cond_synchronize_rcu(snp);

to wait for a GP. Or if the poll_state_synchronize_rcu(oldstate)) != 0
queue_rcu_work().

Sorry for a description using the RCU API functions name :) 

--
Uladzislau Rezki

  reply	other threads:[~2022-11-02 17:24 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-29 13:28 [PATCH RFC] rcu/kfree: Do not request RCU when not needed Joel Fernandes (Google)
2022-10-29 13:31 ` Joel Fernandes
2022-11-02 12:37 ` Uladzislau Rezki
2022-11-02 16:13   ` Joel Fernandes
2022-11-02 16:35     ` Paul E. McKenney
2022-11-02 17:24       ` Uladzislau Rezki [this message]
2022-11-02 17:29         ` Joel Fernandes
2022-11-02 18:31           ` Uladzislau Rezki
2022-11-02 18:49             ` Paul E. McKenney
2022-11-02 19:46               ` Joel Fernandes
2022-11-02 20:28                 ` Paul E. McKenney
2022-11-02 21:26                   ` Joel Fernandes
2022-11-02 22:35                     ` Paul E. McKenney
2022-11-03 12:44                       ` Uladzislau Rezki
2022-11-03 13:05                         ` Uladzislau Rezki
2022-11-03 16:34                           ` Paul E. McKenney
2022-11-03 17:52                         ` Paul E. McKenney
2022-11-03 12:41                   ` Uladzislau Rezki
2022-11-03 17:51                     ` Paul E. McKenney
2022-11-03 18:36                       ` Joel Fernandes
2022-11-03 18:43                         ` Joel Fernandes
2022-11-04 14:39                           ` Uladzislau Rezki
2022-11-04 14:35                       ` Uladzislau Rezki
     [not found]             ` <CAEXW_YQWYfJPpeXoV0ZDGC7Kd585LJ+h2YbKfB3unDDZinxTRQ@mail.gmail.com>
2022-11-03 12:54               ` Uladzislau Rezki
2022-11-02 17:30         ` Uladzislau Rezki
2022-11-02 18:32           ` Paul E. McKenney
2022-11-02 19:51             ` Joel Fernandes
2022-11-02 16:11 ` Joel Fernandes

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=Y2KnxKDebPKiqTFZ@pc636 \
    --to=urezki@gmail.com \
    --cc=joel@joelfernandes.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paulmck@kernel.org \
    --cc=rcu@vger.kernel.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 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.