From: Oleg Nesterov <oleg@redhat.com>
To: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
mingo@kernel.org, linux-kernel@vger.kernel.org, tj@kernel.org,
john.stultz@linaro.org, dimitrysh@google.com, romlem@google.com,
ccross@google.com, tkjos@google.com
Subject: Re: [PATCH] rcu_sync: simplify the state machine, introduce __rcu_sync_enter()
Date: Thu, 21 Jul 2016 19:34:13 +0200 [thread overview]
Message-ID: <20160721173412.GA22488@redhat.com> (raw)
In-Reply-To: <20160720205851.GL7094@linux.vnet.ibm.com>
On 07/20, Paul E. McKenney wrote:
>
> On Wed, Jul 20, 2016 at 05:13:58PM +0200, Oleg Nesterov wrote:
>
> > rcu_sync_enter() or __rcu_sync_enter() is legal in any state, the latter
> > won't block.
>
> Actually, I had no idea that __rcu_sync_enter() was intended for anything
> other than internal use.
>
> Other than that, agreed, with the exception that it is illegal after
> rcu_sync_dtor() has been called.
Yes, sure. rcu_sync_dtor() "destroys" struct rcu_sync, and currently it
is only called by destroy_super_work() right before kfree(). Nothing is
legal after rcu_sync_dtor().
> > > > static void rcu_sync_call(struct rcu_sync *rsp)
> > > > {
> > > > // TODO: THIS IS SUBOPTIMAL. We want to call it directly
> > > > // if rcu_blocking_is_gp() == T, but it has might_sleep().
> > >
> > > Careful! This optimization works only for RCU-sched and RCU-bh.
> > > With normal RCU, you can be tripped up by tasks preempted within RCU
> > > read-side critical sections should CONFIG_PREEMPT=y.
> >
> > Yes, thanks, I understand ;) another reason why I do not want to add
> > this optimization into the initial version.
>
> So I should take this as a request to export rcu_blocking_is_gp()?
Would be nice ;) Or we can do something else. Nevermind, this needs
another discussion.
> > > > void rcu_sync_dtor(struct rcu_sync *rsp)
> > > > {
> > > > int gp_state;
> > > >
> > > > BUG_ON(rsp->gp_count);
> > > > BUG_ON(rsp->gp_state == GP_PASSED);
> > > >
> > > > spin_lock_irq(&rsp->rss_lock);
> > > > if (rsp->gp_state == GP_REPLAY)
> > > > rsp->gp_state = GP_EXIT;
> > >
> > > OK, this ensures that the .wait() below will wait for the callback, but
> > > it might result in some RCU read-side critical sections still being in
> > > flight after rcu_sync_dtor() completes.
> >
> > Hmm. Obviously, the caller should prevent this somehow or it is simply
> > buggy. Or I misunderstood.
>
> Hard to say without knowing what the permitted use cases are...
>
> Me, I would make rcu_sync_dtor() wait the extra grace period in this case.
> It should be a low-probability race, and it reduces the _dtor-time
> state space.
>
> What it looks like you are saying is that the caller must not only ensure
> that there will never again be a __rcu_sync_enter(), rcu_sync_enter(),
> or rcu_sync_exit() (or, I suppose, rcu_sync_dtor()) for this rcu_sync
> structure,
Yes, and
> but must also ensure that any relevant RCU read-side critical
> sections have completed.
Ah, now I understand your concerns. Yes, yes, sure. The caller must
ensure that all RCU read-side critical sections which might look at this
rcu_sync via rcu_sync_is_idle() have completed.
Currently the only caller of dtor() is percpu_free_rwsem(). So if you do,
say,
struct percpu_rw_semaphore *sem = kmalloc(...);
...
percpu_free_rwsem(sem);
kfree(sem);
you obviously need to ensure that percpu_free_rwsem() can't be called
before all readers fully complete their percpu_down_read/percpu_up_read
critical sections, this includes the RCU read-side critical sections.
And this doesn't doesn't really differ from the plain rw_semaphore.
And can't resist... let me add another "TODO" note ;) we actually want
to improve it a bit (probably just a "bool wait" arg) and kill the ugly
super_block->destroy_work which currently does percpu_free_rwsem(). This
should be simple.
Oleg.
next prev parent reply other threads:[~2016-07-21 17:34 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-14 18:25 [PATCH 0/2] locking/percpu-rwsem: Optimizations/tweaks Peter Zijlstra
2016-07-14 18:25 ` [PATCH 1/2] locking/percpu-rwsem: Optimize readers and reduce global impact Peter Zijlstra
2016-07-15 16:30 ` Oleg Nesterov
2016-07-15 19:47 ` Peter Zijlstra
2016-07-18 18:23 ` kbuild test robot
2016-07-18 22:51 ` kbuild test robot
2016-07-14 18:25 ` [PATCH 2/2] locking/percpu-rwsem: Introduce bias knob Peter Zijlstra
2016-07-14 18:37 ` Peter Zijlstra
2016-07-14 18:43 ` Oleg Nesterov
2016-07-14 18:56 ` Peter Zijlstra
2016-07-14 19:20 ` Peter Zijlstra
2016-07-14 19:29 ` Paul E. McKenney
2016-07-14 19:38 ` Peter Zijlstra
2016-07-14 19:54 ` Paul E. McKenney
2016-07-15 13:27 ` Oleg Nesterov
2016-07-15 13:39 ` Paul E. McKenney
2016-07-15 13:45 ` Oleg Nesterov
2016-07-15 15:38 ` Paul E. McKenney
2016-07-15 16:49 ` Oleg Nesterov
2016-07-15 18:01 ` Paul E. McKenney
2016-07-16 17:10 ` [PATCH] rcu_sync: simplify the state machine, introduce __rcu_sync_enter() Oleg Nesterov
2016-07-16 18:40 ` Oleg Nesterov
2016-07-18 11:54 ` Peter Zijlstra
2016-07-18 13:44 ` Oleg Nesterov
2016-07-19 20:50 ` Paul E. McKenney
2016-07-20 15:13 ` Oleg Nesterov
2016-07-20 20:58 ` Paul E. McKenney
2016-07-21 17:34 ` Oleg Nesterov [this message]
2016-07-20 17:16 ` Oleg Nesterov
2016-07-20 21:31 ` Paul E. McKenney
2016-07-21 17:34 ` Oleg Nesterov
2016-07-22 3:26 ` Paul E. McKenney
2016-07-25 17:01 ` Oleg Nesterov
2016-07-25 17:05 ` John Stultz
2016-07-25 17:26 ` Oleg Nesterov
2016-08-09 8:48 ` Peter Zijlstra
2016-07-25 17:49 ` Paul E. McKenney
2016-07-15 13:42 ` [PATCH 2/2] locking/percpu-rwsem: Introduce bias knob Oleg Nesterov
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=20160721173412.GA22488@redhat.com \
--to=oleg@redhat.com \
--cc=ccross@google.com \
--cc=dimitrysh@google.com \
--cc=john.stultz@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=paulmck@linux.vnet.ibm.com \
--cc=peterz@infradead.org \
--cc=romlem@google.com \
--cc=tj@kernel.org \
--cc=tkjos@google.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.