Skip to contentSkip to conversation

lib/rbtree: set successor's parent unconditionally

PATCH In review Wei Yang 3 participants 6 messages Oct 28, 2019

lore
Share & tools
lore

Wei Yang

author
#0 lore raw

PATCH v2 1/2 lib/rbtree: set successor's parent unconditionally

Both in Case 2 and 3, we exchange n and s. This mean no matter whether child2 is NULL or not, successor's parent should be assigned to node's.

This patch takes this step out to make it explicit and reduce the ambiguity.

Besides, this step reduces some symbol size like rb_erase().

   KERN_CONFIG       upstream       patched
   OPT_FOR_PERF      877            870
   OPT_FOR_SIZE      635            621
---
 include/linux/rbtree_augmented.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
include/linux/rbtree_augmented.h +1 -2
index fdd421b8d9ae..99c42e1a74b8 100644
@@ -283,14 +283,13 @@ __rb_erase_augmented(struct rb_node *node, struct rb_root *root,
 		__rb_change_child(node, successor, tmp, root);
 
 		if (child2) {
-			successor->__rb_parent_color = pc;
 			rb_set_parent_color(child2, parent, RB_BLACK);
 			rebalance = NULL;
 		} else {
 			unsigned long pc2 = successor->__rb_parent_color;
-			successor->__rb_parent_color = pc;
 			rebalance = __rb_is_black(pc2) ? parent : NULL;
 		}
+		successor->__rb_parent_color = pc;
 		tmp = successor;
 	}
 
Signature · 1 line
2.17.1
author
#1 lore raw

PATCH v2 2/2 lib/rbtree: get successor's color directly

After move parent assignment out, we can check the color directly.

---
 include/linux/rbtree_augmented.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
include/linux/rbtree_augmented.h +1 -2
index 99c42e1a74b8..724b0d036b57 100644
@@ -286,8 +286,7 @@ __rb_erase_augmented(struct rb_node *node, struct rb_root *root,
 			rb_set_parent_color(child2, parent, RB_BLACK);
 			rebalance = NULL;
 		} else {
-			unsigned long pc2 = successor->__rb_parent_color;
-			rebalance = __rb_is_black(pc2) ? parent : NULL;
+			rebalance = rb_is_black(successor) ? parent : NULL;
 		}
 		successor->__rb_parent_color = pc;
 		tmp = successor;
Signature · 1 line
2.17.1
Reviewed-by on v2 1/2
#3 lore raw
In reply to Wei Yang

Code looks fine, for both commits in this series. Please make sure to double check that lib/rbtree_test does not show any performance regressions, but assuming they don't, looks great !

Quoted 41 lines · Wei Yang

Both in Case 2 and 3, we exchange n and s. This mean no matter whether child2 is NULL or not, successor's parent should be assigned to node's.

This patch takes this step out to make it explicit and reduce the ambiguity.

Besides, this step reduces some symbol size like rb_erase().

   KERN_CONFIG       upstream       patched
   OPT_FOR_PERF      877            870
   OPT_FOR_SIZE      635            621
---
 include/linux/rbtree_augmented.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
include/linux/rbtree_augmented.h +1 -3
index fdd421b8d9ae..99c42e1a74b8 100644
@@ -283,14 +283,13 @@ __rb_erase_augmented(struct rb_node *node, struct rb_root *root,
                __rb_change_child(node, successor, tmp, root);
 
                if (child2) {
-                       successor->__rb_parent_color = pc;
                        rb_set_parent_color(child2, parent, RB_BLACK);
                        rebalance = NULL;
                } else {
                        unsigned long pc2 = successor->__rb_parent_color;
-                       successor->__rb_parent_color = pc;
                        rebalance = __rb_is_black(pc2) ? parent : NULL;
                }
+               successor->__rb_parent_color = pc;
                tmp = successor;
        }
 
--

2.17.1

Signature · 2 lines
Michel "Walken" Lespinasse
A program is never fully debugged until the last user dies.
author
#4 lore raw
Quoted 4 lines · Michel Lespinasse

Code looks fine, for both commits in this series. Please make sure to double check that lib/rbtree_test does not show any performance regressions, but assuming they don't, looks great !

Thanks :-)

Quoted 49 lines
Quoted 41 lines · Wei Yang

Both in Case 2 and 3, we exchange n and s. This mean no matter whether child2 is NULL or not, successor's parent should be assigned to node's.

This patch takes this step out to make it explicit and reduce the ambiguity.

Besides, this step reduces some symbol size like rb_erase().

   KERN_CONFIG       upstream       patched
   OPT_FOR_PERF      877            870
   OPT_FOR_SIZE      635            621
---
 include/linux/rbtree_augmented.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
include/linux/rbtree_augmented.h +1 -3
index fdd421b8d9ae..99c42e1a74b8 100644
@@ -283,14 +283,13 @@ __rb_erase_augmented(struct rb_node *node, struct rb_root *root,
                __rb_change_child(node, successor, tmp, root);
 
                if (child2) {
-                       successor->__rb_parent_color = pc;
                        rb_set_parent_color(child2, parent, RB_BLACK);
                        rebalance = NULL;
                } else {
                        unsigned long pc2 = successor->__rb_parent_color;
-                       successor->__rb_parent_color = pc;
                        rebalance = __rb_is_black(pc2) ? parent : NULL;
                }
+               successor->__rb_parent_color = pc;
                tmp = successor;
        }
 
--

2.17.1

Signature · 2 lines
Michel "Walken" Lespinasse
A program is never fully debugged until the last user dies.
Signature · 2 lines
Wei Yang
Help you, Help me
Acked-by on v2 1/2
#5 lore raw
In reply to Wei Yang
Quoted 6 lines · Wei Yang

Both in Case 2 and 3, we exchange n and s. This mean no matter whether child2 is NULL or not, successor's parent should be assigned to node's.

This patch takes this step out to make it explicit and reduce the ambiguity.

Quoted 7 lines

Besides, this step reduces some symbol size like rb_erase().

   KERN_CONFIG       upstream       patched
   OPT_FOR_PERF      877            870
   OPT_FOR_SIZE      635            621