All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexandru Moise <00moses.alexander00@gmail.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: linux-kernel@vger.kernel.org, akpm@linux-foundation.org,
	dhowells@redhat.com, keescook@chromium.org, fykcee1@gmail.com
Subject: Re: Question regarding Linux implementation of rbtrees
Date: Fri, 14 Apr 2017 11:34:17 +0200	[thread overview]
Message-ID: <20170414093417.GA8306@gmail.com> (raw)
In-Reply-To: <20170414085132.w6vwx6gqwrdrnx3x@hirez.programming.kicks-ass.net>

On Fri, Apr 14, 2017 at 10:51:32AM +0200, Peter Zijlstra wrote:
> On Fri, Apr 14, 2017 at 12:24:55AM +0200, Alexandru Moise wrote:
> > Seeing as RB_RED is defined to be 0 in include/linux/rbtree_augmented.h
> > A call of this form: rb_set_parent_color(node, parent, RB_RED);
> > as seen in __rb_insert would only end up reassigning the parent "color"
> > (which is the parent pointer value cast to unsigned long) OR'd with 0.
> > Which would mean that nothing would really change regarding the parent's
> > "color". So, that would lead one to think that the diagram at case 2 showing
> > the grandparent's color going from black to red could not be completely accurate
> > as the Linux implementation presently stands.
> > 
> > Could the maintainers provide an answer as to why the below patch is the
> > __wrong__ thing to do? Apart from the obvious "the values of the macros
> > might change in the future".
> > 
> > Thanks,
> > ../Alex
> > ---
> >  lib/rbtree.c | 4 ----
> >  1 file changed, 4 deletions(-)
> > 
> > diff --git a/lib/rbtree.c b/lib/rbtree.c
> > index 4ba2828a67c0..6b540be4dda4 100644
> > --- a/lib/rbtree.c
> > +++ b/lib/rbtree.c
> > @@ -135,7 +135,6 @@ __rb_insert(struct rb_node *node, struct rb_root *root,
> >  				rb_set_parent_color(parent, gparent, RB_BLACK);
> >  				node = gparent;
> >  				parent = rb_parent(node);
> > -				rb_set_parent_color(node, parent, RB_RED);
> >  				continue;
> >  			}
> >  
> 
> So who would clear the bit then? The point here is (IIRC) that node is
> black and needs to become red.

Now I've read it again and realized that it's actually in rb_parent() that
the bit gets cleared and all rb_set_parent_color() does is assign the new
pointer cast to ulong to the node's color. I was expecting that the bit would be cleared
in rb_set_parent_color().

Sorry for the noise.

../Alex

      reply	other threads:[~2017-04-14  9:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-13 22:24 Question regarding Linux implementation of rbtrees Alexandru Moise
2017-04-14  8:51 ` Peter Zijlstra
2017-04-14  9:34   ` Alexandru Moise [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=20170414093417.GA8306@gmail.com \
    --to=00moses.alexander00@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=dhowells@redhat.com \
    --cc=fykcee1@gmail.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterz@infradead.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 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.