From: Nick Piggin <nickpiggin@yahoo.com.au>
To: Balbir Singh <bsingharora@gmail.com>
Cc: Nick Piggin <npiggin@suse.de>,
Linux Kernel <linux-kernel@vger.kernel.org>,
Linux Memory Management <linux-mm@kvack.org>,
Paul McKenney <paul.mckenney@us.ibm.com>
Subject: Re: [patch 1/3] radix tree: RCU lockless read-side
Date: Tue, 14 Mar 2006 16:16:03 +1100 [thread overview]
Message-ID: <44165193.2050302@yahoo.com.au> (raw)
In-Reply-To: <661de9470603131932h7ff99aacgde3911ae82b77dc8@mail.gmail.com>
Balbir Singh wrote:
>>The "slots" member is an array, not an RCU assigned pointer. As such, after
>>doing rcu_dereference(slot), you can access slot->slots[i] without further
>>memory barriers I think?
>>
>>But I agree that code now is a bit inconsistent. I've cleaned things up a
>>bit in my tree now... but perhaps it is easier if you send a patch to show
>>what you mean (because sometimes I'm a bit dense, I'm afraid).
>>
>
>
> Fro starters, I do not think your dense at all.
>
I'm glad you think so ;)
> Hmm... slot/slots is quite confusing name. I was referring to slot and
> ended up calling it slots. The point I am contending is that
> rcu_derefence(slot->slots[i]) should happen.
>
> <snippet>
> + __s = rcu_dereference(slot->slots[i]);
> + if (__s != NULL)
> break;
> </snippet>
>
> If we break from the loop because __s != NULL. Then in the snippet below
>
This is a little confusing, because technically I don't think it needs to
rcu_dereference here, either, only when we actually want to dereference
__s and read the data the other end.
rcu_dereference is perhaps an awkward interface for optimising this case.
#define rcu_make_pointer_safe_to_follow(ptr) smp_read_barrier_depends()
or
#define rcu_follow_pointer(ptr) ({ smp_read_barrier_depends(); *ptr; })
might be better
__s = slot->slots[i];
if (__s != NULL) {
rcu_make_pointer_safe_to_follow(__s);
...
Would allow the barrier to be skipped if we're not going to follow the
pointer.
> <snippet>
> /* Bottom level: grab some items */
> for (i = index & RADIX_TREE_MAP_MASK; i < RADIX_TREE_MAP_SIZE; i++) {
> index++;
> if (slot->slots[i]) {
> - results[nr_found++] = slot->slots[i];
> + results[nr_found++] = &slot->slots[i];
> if (nr_found == max_items)
> goto out;
> }
> </snippet>
>
> We do not use __s above. "slot->slots[i]" is not rcu_derefenced() in
> this case because we broke out of the loop above with __s being not
> NULL. Another issue is - is it good enough to rcu_derefence() slot
> once? Shouldn't all uses of *slot->* be rcu derefenced?
>
Yes, slot is a local pointer, the address it points to will not change,
so once we have loaded it and issued the read barrier, we can follow it
from then on and reads will not find stale values.
> <suggestion (WARNING: patch has spaces and its not compiled)>
> /* Bottom level: grab some items */
> for (i = index & RADIX_TREE_MAP_MASK; i < RADIX_TREE_MAP_SIZE; i++) {
> index++;
> - if (slot->slots[i]) {
> - results[nr_found++] = slot->slots[i];
> + __s = rcu_dereference(slot->slots[i]);
> + if (__s) {
> + /* This is tricky, cannot take the address of __s
> or rcu_derefence() */
> + results[nr_found++] = &slot->slots[i];
> if (nr_found == max_items)
> goto out;
> }
> </suggestion>
>
> I hope I am making sense.
>
In this case I think we do not need a barrier because we are only looking
at the pointer (whether it is NULL or not), rather than following it down.
Paul may be able to jump in at this point.
I'll release a new patchset in the next couple of days and try to be more
consisten with the barriers which will hopefully make things less confusing.
Thanks,
Nick
--
SUSE Labs, Novell Inc.
Send instant messages to your online friends http://au.messenger.yahoo.com
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2006-03-14 5:16 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-03-10 15:18 A lockless pagecache for Linux Nick Piggin
2006-03-10 15:18 ` [patch 1/3] radix tree: RCU lockless read-side Nick Piggin
2006-03-11 8:22 ` Balbir Singh
2006-03-11 8:48 ` Nick Piggin
2006-03-13 3:04 ` Balbir Singh
2006-03-13 3:11 ` Nick Piggin
2006-03-13 15:24 ` Balbir Singh
2006-03-13 22:37 ` Nick Piggin
2006-03-14 3:32 ` Balbir Singh
2006-03-14 5:16 ` Nick Piggin [this message]
2006-03-13 6:40 ` Nick Piggin
2006-03-10 15:18 ` [patch 2/3] mm: speculative get_page Nick Piggin
2006-03-10 15:18 ` [patch 3/3] mm: lockless pagecache lookups Nick Piggin
2006-03-10 15:18 ` [patch 4/3] mm: lockless optimisations Nick Piggin
2006-03-10 15:18 ` [patch 5/3] mm: spinlock tree_lock Nick Piggin
2006-03-13 23:35 ` A lockless pagecache for Linux Christoph Lameter
2006-03-14 4:14 ` Nick Piggin
2006-03-14 12:59 ` Wu Fengguang
2006-04-04 9:31 [patch 0/3] lockless pagecache Nick Piggin
2006-04-04 9:31 ` [patch 1/3] radix tree: RCU lockless read-side Nick Piggin
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=44165193.2050302@yahoo.com.au \
--to=nickpiggin@yahoo.com.au \
--cc=bsingharora@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=npiggin@suse.de \
--cc=paul.mckenney@us.ibm.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox