All of lore.kernel.org
 help / color / mirror / Atom feed
From: Uladzislau Rezki <urezki@gmail.com>
To: "Paul E. McKenney" <paulmck@kernel.org>,
	Joel Fernandes <joel@joelfernandes.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: Thu, 3 Nov 2022 13:41:43 +0100	[thread overview]
Message-ID: <Y2O3Bz0DMEBZF+83@pc638.lan> (raw)
In-Reply-To: <20221102202813.GR5600@paulmck-ThinkPad-P17-Gen-1>

> > >> /**
> > >> @@ -3066,10 +3068,12 @@ static void kfree_rcu_work(struct work_struct *work)
> > >>    struct kfree_rcu_cpu_work *krwp;
> > >>    int i, j;
> > >> 
> > >> -    krwp = container_of(to_rcu_work(work),
> > >> +    krwp = container_of(work,
> > >>                struct kfree_rcu_cpu_work, rcu_work);
> > >>    krcp = krwp->krcp;
> > >> 
> > >> +    cond_synchronize_rcu(krwp->gp_snap);
> > > 
> > > Might this provoke OOMs in case of callback flooding?
> > > 
> > > An alternative might be something like this:
> > > 
> > >    if (!poll_state_synchronize_rcu(krwp->gp_snap)) {
> > >        queue_rcu_work(system_wq, &krwp->rcu_work);
> > >        return;
> > >    }
> > > 
> > > Either way gets you a non-lazy callback in the case where a grace
> > > period has not yet elapsed.
> > > Or am I missing something that prevents OOMs here?
> > 
> > The memory consumptions appears to be much less in his testing with the onslaught of kfree, which makes OOM probably less likely.
> > 
> > Though, was your reasoning that in case of a grace period not elapsing, we need a non lazy callback queued, so as to make the reclaim happen sooner?
> > 
> > If so, the cond_synchronize_rcu() should already be conditionally queueing non-lazy CB since we don’t make synchronous users wait for seconds. Or did I miss something?
> 
> My concern is that the synchronize_rcu() will block a kworker kthread
> for some time, and that in callback-flood situations this might slow
> things down due to exhausting the supply of kworkers.
> 
This concern works in both cases. I mean in default configuration and
with a posted patch. The reclaim work, which name is kfree_rcu_work() only
does a progress when a gp is passed so the rcu_work_rcufn() can queue
our reclaim kworker.

As it is now:

1. Collect pointers, then we decide to drop them we queue the
   monitro_work() worker to the system_wq.

2. The monitor work, kfree_rcu_work(), tries to attach or saying
it by another words bypass a "backlog" to "free" channels.

3. It invokes the queue_rcu_work() that does call_rcu_flush() and
in its turn it queues our worker from the handler. So the worker
is run after GP is passed.

With a patch: 

[1] and [2] steps are the same. But on third step we do:

1. Record the GP status for last in channel;
2. Directly queue the drain work without any call_rcu() helpers;
3. On the reclaim worker entry we check if GP is passed;
4. If not it invokes synchronize_rcu().

The patch eliminates extra steps by not going via RCU-core route
instead it directly invokes the reclaim worker where it either
proceed or wait a GP if needed.

--
Uladzislau Rezki

  parent reply	other threads:[~2022-11-03 12:41 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
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 [this message]
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=Y2O3Bz0DMEBZF+83@pc638.lan \
    --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.