All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-mm@kvack.org" <linux-mm@kvack.org>,
	"minchan.kim@gmail.com" <minchan.kim@gmail.com>,
	cl@linux-foundation.org
Subject: Re: [RFC PATCH] asynchronous page fault.
Date: Sun, 27 Dec 2009 12:19:56 +0100	[thread overview]
Message-ID: <1261912796.15854.25.camel@laptop> (raw)
In-Reply-To: <20091225105140.263180e8.kamezawa.hiroyu@jp.fujitsu.com>

On Fri, 2009-12-25 at 10:51 +0900, KAMEZAWA Hiroyuki wrote:
> Index: linux-2.6.33-rc2/lib/rbtree.c
> ===================================================================
> --- linux-2.6.33-rc2.orig/lib/rbtree.c
> +++ linux-2.6.33-rc2/lib/rbtree.c
> @@ -30,19 +30,19 @@ static void __rb_rotate_left(struct rb_n
>  
>         if ((node->rb_right = right->rb_left))
>                 rb_set_parent(right->rb_left, node);
> -       right->rb_left = node;
> +       rcu_assign_pointer(right->rb_left, node);
>  
>         rb_set_parent(right, parent);
>  
>         if (parent)
>         {
>                 if (node == parent->rb_left)
> -                       parent->rb_left = right;
> +                       rcu_assign_pointer(parent->rb_left, right);
>                 else
> -                       parent->rb_right = right;
> +                       rcu_assign_pointer(parent->rb_right, right);
>         }
>         else
> -               root->rb_node = right;
> +               rcu_assign_pointer(root->rb_node, right);
>         rb_set_parent(node, right);
>  }
>  
> @@ -53,19 +53,19 @@ static void __rb_rotate_right(struct rb_
>  
>         if ((node->rb_left = left->rb_right))
>                 rb_set_parent(left->rb_right, node);
> -       left->rb_right = node;
> +       rcu_assign_pointer(left->rb_right, node);
>  
>         rb_set_parent(left, parent);
>  
>         if (parent)
>         {
>                 if (node == parent->rb_right)
> -                       parent->rb_right = left;
> +                       rcu_assign_pointer(parent->rb_right, left);
>                 else
> -                       parent->rb_left = left;
> +                       rcu_assign_pointer(parent->rb_left, left);
>         }
>         else
> -               root->rb_node = left;
> +               rcu_assign_pointer(root->rb_node, left);
>         rb_set_parent(node, left);
>  }


Consider the tree rotation:


           Q                        P
         /   \                    /   \
       P       C                A       Q
     /   \                            /   \
   A       B                        B       C


Since this comprises of 3 assignments (assuming right rotation):

  Q.left = B
  P.right = Q
  parent = P

it is non-atomic. This in turn means that any lock-less decent into the
tree will be able to miss a whole subtree or worse (imagine us being at
Q, needing to go to A, then the rotation happens, and all we can choose
from is B or C).

Your changelog states as much.

"Even if RB-tree rotation occurs while we walk tree for look-up, we just
miss vma without oops."

However, since this is the case, do we still need the
rcu_assign_pointer() conversion your patch does? All I can see it do is
slow down all RB-tree users, without any gain.


WARNING: multiple messages have this Message-ID (diff)
From: Peter Zijlstra <peterz@infradead.org>
To: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-mm@kvack.org" <linux-mm@kvack.org>,
	"minchan.kim@gmail.com" <minchan.kim@gmail.com>,
	cl@linux-foundation.org
Subject: Re: [RFC PATCH] asynchronous page fault.
Date: Sun, 27 Dec 2009 12:19:56 +0100	[thread overview]
Message-ID: <1261912796.15854.25.camel@laptop> (raw)
In-Reply-To: <20091225105140.263180e8.kamezawa.hiroyu@jp.fujitsu.com>

On Fri, 2009-12-25 at 10:51 +0900, KAMEZAWA Hiroyuki wrote:
> Index: linux-2.6.33-rc2/lib/rbtree.c
> ===================================================================
> --- linux-2.6.33-rc2.orig/lib/rbtree.c
> +++ linux-2.6.33-rc2/lib/rbtree.c
> @@ -30,19 +30,19 @@ static void __rb_rotate_left(struct rb_n
>  
>         if ((node->rb_right = right->rb_left))
>                 rb_set_parent(right->rb_left, node);
> -       right->rb_left = node;
> +       rcu_assign_pointer(right->rb_left, node);
>  
>         rb_set_parent(right, parent);
>  
>         if (parent)
>         {
>                 if (node == parent->rb_left)
> -                       parent->rb_left = right;
> +                       rcu_assign_pointer(parent->rb_left, right);
>                 else
> -                       parent->rb_right = right;
> +                       rcu_assign_pointer(parent->rb_right, right);
>         }
>         else
> -               root->rb_node = right;
> +               rcu_assign_pointer(root->rb_node, right);
>         rb_set_parent(node, right);
>  }
>  
> @@ -53,19 +53,19 @@ static void __rb_rotate_right(struct rb_
>  
>         if ((node->rb_left = left->rb_right))
>                 rb_set_parent(left->rb_right, node);
> -       left->rb_right = node;
> +       rcu_assign_pointer(left->rb_right, node);
>  
>         rb_set_parent(left, parent);
>  
>         if (parent)
>         {
>                 if (node == parent->rb_right)
> -                       parent->rb_right = left;
> +                       rcu_assign_pointer(parent->rb_right, left);
>                 else
> -                       parent->rb_left = left;
> +                       rcu_assign_pointer(parent->rb_left, left);
>         }
>         else
> -               root->rb_node = left;
> +               rcu_assign_pointer(root->rb_node, left);
>         rb_set_parent(node, left);
>  }


Consider the tree rotation:


           Q                        P
         /   \                    /   \
       P       C                A       Q
     /   \                            /   \
   A       B                        B       C


Since this comprises of 3 assignments (assuming right rotation):

  Q.left = B
  P.right = Q
  parent = P

it is non-atomic. This in turn means that any lock-less decent into the
tree will be able to miss a whole subtree or worse (imagine us being at
Q, needing to go to A, then the rotation happens, and all we can choose
from is B or C).

Your changelog states as much.

"Even if RB-tree rotation occurs while we walk tree for look-up, we just
miss vma without oops."

However, since this is the case, do we still need the
rcu_assign_pointer() conversion your patch does? All I can see it do is
slow down all RB-tree users, without any gain.

--
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>

  parent reply	other threads:[~2009-12-27 11:20 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-25  1:51 [RFC PATCH] asynchronous page fault KAMEZAWA Hiroyuki
2009-12-27  9:47 ` Minchan Kim
2009-12-27  9:47   ` Minchan Kim
2009-12-27 23:59   ` KAMEZAWA Hiroyuki
2009-12-27 23:59     ` KAMEZAWA Hiroyuki
2009-12-27 11:19 ` Peter Zijlstra [this message]
2009-12-27 11:19   ` Peter Zijlstra
2009-12-28  0:00   ` KAMEZAWA Hiroyuki
2009-12-28  0:00     ` KAMEZAWA Hiroyuki
2009-12-28  0:57   ` Balbir Singh
2009-12-28  0:57     ` Balbir Singh
2009-12-28  1:05     ` KAMEZAWA Hiroyuki
2009-12-28  1:05       ` KAMEZAWA Hiroyuki
2009-12-28  2:58       ` Balbir Singh
2009-12-28  2:58         ` Balbir Singh
2009-12-28  3:13         ` KAMEZAWA Hiroyuki
2009-12-28  3:13           ` KAMEZAWA Hiroyuki
2009-12-28  8:34         ` Peter Zijlstra
2009-12-28  8:34           ` Peter Zijlstra
2009-12-28  8:32     ` Peter Zijlstra
2009-12-28  8:32       ` Peter Zijlstra
2009-12-29  9:54       ` Balbir Singh
2009-12-29  9:54         ` Balbir Singh
2009-12-27 12:03 ` Peter Zijlstra
2009-12-27 12:03   ` Peter Zijlstra
2009-12-28  0:36   ` KAMEZAWA Hiroyuki
2009-12-28  0:36     ` KAMEZAWA Hiroyuki
2009-12-28  1:19     ` KAMEZAWA Hiroyuki
2009-12-28  1:19       ` KAMEZAWA Hiroyuki
2009-12-28  8:30     ` Peter Zijlstra
2009-12-28  8:30       ` Peter Zijlstra
2009-12-28  9:58       ` KAMEZAWA Hiroyuki
2009-12-28  9:58         ` KAMEZAWA Hiroyuki
2009-12-28 10:30         ` Peter Zijlstra
2009-12-28 10:30           ` Peter Zijlstra
2009-12-28 10:40           ` Peter Zijlstra
2009-12-28 10:40             ` Peter Zijlstra
2010-01-02 16:14             ` Peter Zijlstra
2010-01-02 16:14               ` Peter Zijlstra
2010-01-04  3:02               ` Paul E. McKenney
2010-01-04  3:02                 ` Paul E. McKenney
2010-01-04  7:53                 ` Peter Zijlstra
2010-01-04  7:53                   ` Peter Zijlstra
2010-01-04 15:55                   ` Paul E. McKenney
2010-01-04 15:55                     ` Paul E. McKenney
2010-01-04 16:02                     ` Peter Zijlstra
2010-01-04 16:02                       ` Peter Zijlstra
2010-01-04 16:56                       ` Paul E. McKenney
2010-01-04 16:56                         ` Paul E. McKenney
2010-01-04 13:48               ` [RFC PATCH -v2] speculative " Peter Zijlstra
2010-01-04 13:48                 ` Peter Zijlstra
2009-12-28 10:57           ` [RFC PATCH] asynchronous " KAMEZAWA Hiroyuki
2009-12-28 10:57             ` KAMEZAWA Hiroyuki
2009-12-28 11:06             ` Peter Zijlstra
2009-12-28 11:06               ` Peter Zijlstra
2009-12-28  8:55     ` Peter Zijlstra
2009-12-28  8:55       ` Peter Zijlstra
2009-12-28 10:08       ` KAMEZAWA Hiroyuki
2009-12-28 10:08         ` KAMEZAWA Hiroyuki
2009-12-28 11:43     ` Peter Zijlstra
2009-12-28 11:43       ` Peter Zijlstra
2010-01-02 21:45 ` Benjamin Herrenschmidt
2010-01-02 21:45   ` Benjamin Herrenschmidt

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=1261912796.15854.25.camel@laptop \
    --to=peterz@infradead.org \
    --cc=cl@linux-foundation.org \
    --cc=kamezawa.hiroyu@jp.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=minchan.kim@gmail.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 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.