public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: David Howells <dhowells@redhat.com>
Cc: linux-afs@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Introduce rb_replace_node_rcu()
Date: Fri, 1 Jul 2016 09:22:38 +0200	[thread overview]
Message-ID: <20160701072238.GK30921@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <1412.1467356887@warthog.procyon.org.uk>

On Fri, Jul 01, 2016 at 08:08:07AM +0100, David Howells wrote:

> Should I also reorder rb_replace_node() whilst
> I'm at it so that the new node is initialised first (it shouldn't make a
> difference, I know)?

Might as well, I can't imagine that making a performance difference and
keeping the general structure of things similar helps avoid confusion.

> commit 812667d2a82a6a8fe35a44e951e8b1515b04696a
> Author: David Howells <dhowells@redhat.com>
> Date:   Fri Jul 1 07:53:51 2016 +0100
> 
>     Introduce rb_replace_node_rcu()
>     
>     Implement an RCU-safe variant of rb_replace_node().
>     
>     Signed-off-by: David Howells <dhowells@redhat.com>
>     cc: Peter Zijlstra <peterz@infradead.org>

One little niggle below, but:

Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>


> diff --git a/lib/rbtree.c b/lib/rbtree.c
> index 1356454e36de..59eb906c6c3b 100644
> --- a/lib/rbtree.c
> +++ b/lib/rbtree.c
> @@ -551,6 +551,25 @@ void rb_replace_node(struct rb_node *victim, struct rb_node *new,
>  }
>  EXPORT_SYMBOL(rb_replace_node);
>  
> +void rb_replace_node_rcu(struct rb_node *victim, struct rb_node *new,
> +			 struct rb_root *root)
> +{
> +	struct rb_node *parent = rb_parent(victim);
> +
> +	/* Copy the pointers/colour from the victim to the replacement */
> +	*new = *victim;
> +
> +	/* Set the surrounding nodes to point to the replacement */
> +	if (victim->rb_left)
> +		rb_set_parent(victim->rb_left, new);
> +	if (victim->rb_right)
> +		rb_set_parent(victim->rb_right, new);
> +
> +	/* Set the onward pointer last with an RCU barrier */

Maybe also explain _why_ this needs to be last. Its obvious now and to
us, but it might safe some head scratching later.

> +	__rb_change_child_rcu(victim, new, parent, root);
> +}
> +EXPORT_SYMBOL(rb_replace_node_rcu);

  reply	other threads:[~2016-07-01  7:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-01  7:08 [PATCH] Introduce rb_replace_node_rcu() David Howells
2016-07-01  7:22 ` Peter Zijlstra [this message]
2016-07-01  8:08   ` David Howells
2016-07-01  8:14     ` Peter Zijlstra

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=20160701072238.GK30921@twins.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=dhowells@redhat.com \
    --cc=linux-afs@lists.infradead.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