]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
maple_tree: Optimize mab_mas_cp to use ma_pivots and ma_slots
authorLiam R. Howlett <Liam.Howlett@Oracle.com>
Tue, 22 Sep 2020 19:35:39 +0000 (15:35 -0400)
committerLiam R. Howlett <Liam.Howlett@Oracle.com>
Fri, 30 Oct 2020 19:12:06 +0000 (15:12 -0400)
Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
lib/maple_tree.c

index 2742a0a542365d993dce59f3b55a0d5421e5692c..ec1f782d2a6836b3021f97b0f93275438eba289c 100644 (file)
@@ -1434,6 +1434,7 @@ static inline void mas_mab_cp(struct ma_state *mas, unsigned char mas_start,
        enum maple_type mt = mte_node_type(mas->node);
        struct maple_node *node = mte_to_node(mas->node);
        void **slots = ma_slots(node, mt);
+       unsigned long *pivots = ma_pivots(node, mt);
        unsigned long *gaps = NULL;
        int i, j;
 
@@ -1442,15 +1443,11 @@ static inline void mas_mab_cp(struct ma_state *mas, unsigned char mas_start,
 
        for (i = mas_start, j = mab_start; i <= mas_end; i++, j++) {
                b_node->slot[j] = mas_slot_protected(mas, slots, i);
+               b_node->pivot[j] = _mas_safe_pivot(mas, pivots, i, mt);
 
                if (gaps)
                        b_node->gap[j] = gaps[i];
 
-               if (i < mt_pivots[mt])
-                       b_node->pivot[j] = mas_safe_pivot(mas, i);
-               else
-                       b_node->pivot[j] = mas->max;
-
                if ((mas->max == b_node->pivot[j]) ||
                    (j && !b_node->pivot[j])) {       // end of node.
                        j++;
@@ -1462,7 +1459,6 @@ static inline void mas_mab_cp(struct ma_state *mas, unsigned char mas_start,
 
 /*
  * mab_mas_cp() - Copy data from maple_big_node to a maple encoded node.
- *
  * @b_node: the maple_big_node that has the data
  * @mab_start: the start location in @b_node.
  * @mab_end: The end location in @b_node (inclusively)
@@ -1473,20 +1469,27 @@ static inline void mab_mas_cp(struct maple_big_node *b_node,
                              struct ma_state *mas)
 {
        int i, j = 0;
+       enum maple_type mt = mte_node_type(mas->node);
+       struct maple_node *node = mte_to_node(mas->node);
+       void **slots = ma_slots(node, mt);
+       unsigned long *pivots = ma_pivots(node, mt);
+       unsigned long *gaps = NULL;
+
+       if (!ma_is_leaf(mt) && mt_is_alloc(mas->tree))
+               gaps = ma_gaps(mas_mn(mas), mt);
 
        for (i = mab_start; i <= mab_end; i++, j++) {
                if (j && !b_node->pivot[i])
                        break;
 
-               mas->max = b_node->pivot[i];
-               mte_set_slot(mas->node, j, b_node->slot[i]);
+               rcu_assign_pointer(slots[j], b_node->slot[i]);
+               if (j < mt_pivots[mt])
+                       pivots[j] = b_node->pivot[i];
 
-               if (j < mt_pivot_count(mas->node))
-                       mte_set_pivot(mas->node, j, b_node->pivot[i]);
-
-               if (!mte_is_leaf(mas->node) && mt_is_alloc(mas->tree))
-                       mte_set_gap(mas->node, j, b_node->gap[i]);
+               if (gaps)
+                       gaps[j] = b_node->gap[i];
        }
+       mas->max = b_node->pivot[--i];
 }
 
 /*
@@ -2366,7 +2369,7 @@ static inline bool _mas_split_final_node(struct maple_subtree_state *mast,
 static inline bool mas_split_final_node(struct maple_subtree_state *mast,
                                        struct ma_state *mas, int height)
 {
-       if (height <= mas->full_cnt)
+       if (mt_slots[mast->bn->type] <= mast->bn->b_end)
                return false;
 
        return _mas_split_final_node(mast, mas, height);