From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Lai Jiangshan <laijs@cn.fujitsu.com>,
Andrew Morton <akpm@linux-foundation.org>,
linux-arch@vger.kernel.org,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [RFC PATCH]rcu,alpha: avoid smp_read_barrier_depends in rcu_dereference when pointer==NULL
Date: Sat, 21 Jun 2008 12:26:46 -0700 [thread overview]
Message-ID: <20080621192646.GA22569@linux.vnet.ibm.com> (raw)
In-Reply-To: <1214052746.3223.218.camel@lappy.programming.kicks-ass.net>
On Sat, Jun 21, 2008 at 02:52:25PM +0200, Peter Zijlstra wrote:
> On Sat, 2008-06-21 at 17:54 +0800, Lai Jiangshan wrote:
> > Hi, Paul and Alpha hackers
> >
> > memory barrier is expensive, I think it's worth that adding an if-statement
> > to avoid it when pointer == NULL.
> >
> > This patch change nothing in UP or in other architectures for compiler's
> > optimization.
>
> I suspect this optimization is invalid in the case where the loaded
> value is used as an offset (either pointer or array index). But I'm
> afraid I'll have to defer to Paul for explanations..
What Peter said!
There are cases where the argument to rcu_dereference() is an array
index rather than a pointer. In that case, zero is a perfectly valid
array index and requires a memory barrier on Alpha. Given that the
smp_read_barrier_depends() primitive is very nearly (but not quite)
a no-op on non-Alpha machines, it will also be necessary to carefully
check the generated code to make sure that we are not slowing down the
common non-Alpha machines to help out the very rare Alpha machines.
Some months ago, we attempted to add a similar check to
rcu_assign_pointer(), but we were unable to find an approach that handled
all the cases currently in the Linux kernel, even when we introduced a
special-case primitive for array indexes. Please note that we did not
prove it impossible, but rather decided that it was consuming more time
and energy than was warranted.
Thanx, Paul
PS. I have not forgotten about your earlier patch to the list structures
used by classic RCU -- but I am still curious to know the results
of the more-harsh testing that I suggested.
> > Thanks, Lai Jiangshan
> >
> >
> > Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
> > ---
> > diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
> > index d42dbec..8979f29 100644
> > --- a/include/linux/rcupdate.h
> > +++ b/include/linux/rcupdate.h
> > @@ -143,7 +143,8 @@ struct rcu_head {
> >
> > #define rcu_dereference(p) ({ \
> > typeof(p) _________p1 = ACCESS_ONCE(p); \
> > - smp_read_barrier_depends(); \
> > + if (_________p1) \
> > + smp_read_barrier_depends(); \
> > (_________p1); \
> > })
> >
> >
> >
> >
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at http://vger.kernel.org/majordomo-info.html
> > Please read the FAQ at http://www.tux.org/lkml/
>
prev parent reply other threads:[~2008-06-21 19:26 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-21 9:54 [RFC PATCH]rcu,alpha: avoid smp_read_barrier_depends in rcu_dereference when pointer==NULL Lai Jiangshan
2008-06-21 12:52 ` Peter Zijlstra
2008-06-21 19:26 ` Paul E. McKenney [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=20080621192646.GA22569@linux.vnet.ibm.com \
--to=paulmck@linux.vnet.ibm.com \
--cc=a.p.zijlstra@chello.nl \
--cc=akpm@linux-foundation.org \
--cc=laijs@cn.fujitsu.com \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox