From 57711d6ffd8e209197e408178574f29ea353652f Mon Sep 17 00:00:00 2001 From: "Liam R. Howlett" Date: Mon, 28 Sep 2020 16:27:00 -0400 Subject: [PATCH] maple_tree: optimize root expand Signed-off-by: Liam R. Howlett --- lib/maple_tree.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index c6dd92c9c6c4..bc83da3ba676 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -2698,6 +2698,9 @@ static inline int mas_root_expand(struct ma_state *mas, void *entry) { void *contents = mas_root_locked(mas); enum maple_type type = maple_leaf_64; + struct maple_node *node; + void **slots; + unsigned long *pivots; int slot = 0; @@ -2705,20 +2708,23 @@ static inline int mas_root_expand(struct ma_state *mas, void *entry) if (mas_is_err(mas)) return 0; - mas->node = mt_mk_node(mas_next_alloc(mas), type); + node = mas_next_alloc(mas); + pivots = ma_pivots(node, type); + slots = ma_slots(node, type); + mas->node = mt_mk_node(node, type); mas_mn(mas)->parent = ma_parent_ptr( ((unsigned long)mas->tree | MA_ROOT_PARENT)); if (contents) - mte_set_slot(mas->node, slot++, contents); + slots[slot++] = contents; if (!mas->index && slot) slot--; else if (mas->index > 1) - mte_set_pivot(mas->node, slot++, mas->index - 1); + pivots[slot++] = mas->index - 1; - mte_set_slot(mas->node, slot, entry); - mte_set_pivot(mas->node, slot++, mas->last); + slots[slot] = entry; + pivots[slot++] = mas->last; /* swap the new root into the tree */ rcu_assign_pointer(mas->tree->ma_root, mte_mk_root(mas->node)); mas->depth = 1; @@ -4167,8 +4173,8 @@ static inline void *_mas_next(struct ma_state *mas, unsigned long limit, return NULL; if (mas_is_start(mas)) {// First run. - *range_start = 0; mas_start(mas); + *range_start = 0; entry = mas_range_load(mas, range_start, &range_max); mas->last = range_max; if (entry) -- 2.50.1