History

maple_tree: avoid extra gap calculation

Prior to ending the ascension loop of larger operations like split, rebalance, and spanning store the gap in the node had been calculated. Once the node is inserted into the tree, the gap is recalculated in mas_update_gap(). This can be avoided by creating a helper for mas_update_gap() that accepts the known gap value, which reduces the operations required for gap updating path.

Liam R. Howlett (Oracle) committed 2 months ago

Commit 4e4fe9d1 parent 00f67811 file · +17 −11Browse files

Showing the changes to lib (1 of 1 file). Show all

Unified · Split

lib/maple_tree.c+17−11
@@ -1566,14 +1566,26 @@ ascend: · 1565 unmodified lines
15661566 goto ascend;
15671567 }
15681568
1569+static __always_inline void mas_update_gap_known(struct ma_state *mas,
1570+ unsigned long gap)
1571+{
1572+ unsigned char pslot;
1573+ unsigned long p_gap;
1574+
1575+ pslot = mte_parent_slot(mas->node);
1576+ p_gap = ma_gaps(mte_parent(mas->node),
1577+ mas_parent_type(mas, mas->node))[pslot];
1578+
1579+ if (p_gap != gap)
1580+ mas_parent_gap(mas, pslot, gap);
1581+}
1582+
15691583 /*
15701584 * mas_update_gap() - Update a nodes gaps and propagate up if necessary.
15711585 * @mas: the maple state.
15721586 */
15731587 static inline void mas_update_gap(struct ma_state *mas)
15741588 {
1575− unsigned char pslot;
1576− unsigned long p_gap;
15771589 unsigned long max_gap;
15781590
15791591 if (!mt_is_alloc(mas->tree))
@@ -1583,13 +1595,7 @@ static inline void mas_update_gap(struct ma_state *mas) · 3 unmodified lines
15831595 return;
15841596
15851597 max_gap = mas_max_gap(mas);
1586−
1587− pslot = mte_parent_slot(mas->node);
1588− p_gap = ma_gaps(mte_parent(mas->node),
1589− mas_parent_type(mas, mas->node))[pslot];
1590−
1591− if (p_gap != max_gap)
1592− mas_parent_gap(mas, pslot, max_gap);
1598+ mas_update_gap_known(mas, max_gap);
15931599 }
15941600
15951601 /*
@@ -2137,8 +2143,8 @@ static inline void mas_wmb_replace(struct ma_state *mas, struct maple_copy *cp) · 541 unmodified lines
21372143 mas->node = mt_slot_locked(mas->tree, cp->slot, 0);
21382144 /* Insert the new data in the tree */
21392145 mas_topiary_replace(mas, old_enode, cp->height);
2140− if (!mte_is_leaf(mas->node))
2141− mas_update_gap(mas);
2146+ if (mt_is_alloc(mas->tree) && !mte_is_root(mas->node))
2147+ mas_update_gap_known(mas, cp->gap[0]);
21422148
21432149 mtree_range_walk(mas);
21442150 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t