From: Nick Piggin <npiggin@suse.de>
To: Lai Jiangshan <laijs@cn.fujitsu.com>
Cc: Nick Piggin <nickpiggin@yahoo.com.au>,
Andrew Morton <akpm@linux-foundation.org>,
"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
Luis Carlos Cobo <luisca@cozybit.com>,
Steve Whitehouse <SteveW@acm.org>,
Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
torvalds@linux-foundation.org
Subject: Re: [PATCH]rcu,inet,fib_trie,route,radix-tree,DECnet,mac80211: fix meaningless rcu_dereference(local_var)
Date: Mon, 23 Jun 2008 10:48:46 +0200 [thread overview]
Message-ID: <20080623084846.GA6899@wotan.suse.de> (raw)
In-Reply-To: <485F3638.5010305@cn.fujitsu.com>
On Mon, Jun 23, 2008 at 01:35:52PM +0800, Lai Jiangshan wrote:
> Add CC: Linus Torvalds
>
> Nick Piggin wrote:
> > On Saturday 21 June 2008 19:54, Lai Jiangshan wrote:
> >
> >> diff --git a/lib/radix-tree.c b/lib/radix-tree.c
> >> index 169a2f8..bfae4e2 100644
> >> --- a/lib/radix-tree.c
> >> +++ b/lib/radix-tree.c
> >> @@ -703,9 +703,9 @@ __lookup(struct radix_tree_node *slot, void **results,
> >> unsigned long index, for (i = index & RADIX_TREE_MAP_MASK; i <
> >> RADIX_TREE_MAP_SIZE; i++) { struct radix_tree_node *node;
> >> index++;
> >> - node = slot->slots[i];
> >> + node = rcu_dereference(slot->slots[i]);
> >> if (node) {
> >> - results[nr_found++] = rcu_dereference(node);
> >> + results[nr_found++] = node;
> >> if (nr_found == max_items)
> >> goto out;
> >> }
> >> @@ -815,7 +815,7 @@ __lookup_tag(struct radix_tree_node *slot, void
> >> **results, unsigned long index, index++;
> >> if (!tag_get(slot, tag, j))
> >> continue;
> >> - node = slot->slots[j];
> >> + node = rcu_dereference(slot->slots[j]);
> >> /*
> >> * Even though the tag was found set, we need to
> >> * recheck that we have a non-NULL node, because
> >> @@ -827,7 +827,6 @@ __lookup_tag(struct radix_tree_node *slot, void
> >> **results, unsigned long index, * rely on its value remaining the same).
> >> */
> >> if (node) {
> >> - node = rcu_dereference(node);
> >> results[nr_found++] = node;
> >> if (nr_found == max_items)
> >> goto out;
> >
> > This was done like this IIRC to avoid the barrier when possible.
> >
> >
> >
> This(http://lkml.org/lkml/2008/4/20/217) shows why rcu_dereference(local_var)
> is meaningless. And why not use smp_read_barrier_depends() here?
It is "meaningless" in that it isn't being applied as the API is supposed
to, however it does provide the barrier that's required. I guess read
barrier depends could just be used instead, although I like the self
commenting nature of the rcu_dereference, even if it is not quite applied
correctly, the reader can easily see the intention.
I *think* it should even do the right thing WRT the access_once macro here,
and cause node not to be reloaded from source, but I could be wrong on that.
> I guessed somebody use rcu_dereference(local_var) in if-statements to avoid the
> barrier when possible, and I made this patch(http://lkml.org/lkml/2008/6/21/29),
> but it is incorrect.
So it doesn't help me ;)
I'm not sure what the best way to go is, but I would ask Paul for ideas
if he's not too busy.
In reality, the barriers probably don't matter much (but I'd really love
to have an Alpha to test it on :)), but I still try to avoid them as much
as possible. For the radix-tree as used by pagecache, it is a completely
usual operation to lookup non existing elements, so we are talking about
a fastpath of sorts...
next prev parent reply other threads:[~2008-06-23 8:49 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-21 9:54 [PATCH]rcu,inet,fib_trie,route,radix-tree,DECnet,mac80211: fix meaningless rcu_dereference(local_var) Lai Jiangshan
2008-06-23 2:36 ` Nick Piggin
2008-06-23 5:35 ` Lai Jiangshan
2008-06-23 8:48 ` Nick Piggin [this message]
2008-06-23 10:01 ` Paul E. McKenney
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=20080623084846.GA6899@wotan.suse.de \
--to=npiggin@suse.de \
--cc=SteveW@acm.org \
--cc=akpm@linux-foundation.org \
--cc=kuznet@ms2.inr.ac.ru \
--cc=laijs@cn.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luisca@cozybit.com \
--cc=nickpiggin@yahoo.com.au \
--cc=paulmck@linux.vnet.ibm.com \
--cc=torvalds@linux-foundation.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