From 70c573d1504f7b0f52472d96f78cb935286a5de6 Mon Sep 17 00:00:00 2001 From: "Liam R. Howlett" Date: Tue, 22 Sep 2020 15:35:39 -0400 Subject: [PATCH] maple_tree: Optimize mab_mas_cp to use ma_pivots and ma_slots Signed-off-by: Liam R. Howlett --- lib/maple_tree.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 2742a0a54236..ec1f782d2a68 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -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); -- 2.50.1