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

Unified · Split

lib/maple_tree.c+17−11
@@ -1566,14 +1566,26 @@ ascend: · 1565 unmodified lines
1566 goto ascend;1566 goto ascend;
1567}1567}
1568 1568
1569static __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
1569/*1583/*
1570 * mas_update_gap() - Update a nodes gaps and propagate up if necessary.1584 * mas_update_gap() - Update a nodes gaps and propagate up if necessary.
1571 * @mas: the maple state.1585 * @mas: the maple state.
1572 */1586 */
1573static inline void mas_update_gap(struct ma_state *mas)1587static inline void mas_update_gap(struct ma_state *mas)
1574{1588{
1575 unsigned char pslot;
1576 unsigned long p_gap;
1577 unsigned long max_gap;1589 unsigned long max_gap;
1578 1590
1579 if (!mt_is_alloc(mas->tree))1591 if (!mt_is_alloc(mas->tree))
@@ -1583,13 +1595,7 @@ static inline void mas_update_gap(struct ma_state *mas) · 3 unmodified lines
1583 return;1595 return;
1584 1596
1585 max_gap = mas_max_gap(mas);1597 max_gap = mas_max_gap(mas);
1586 1598 mas_update_gap_known(mas, max_gap);
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);
1593}1599}
1594 1600
1595/*1601/*
@@ -2137,8 +2143,8 @@ static inline void mas_wmb_replace(struct ma_state *mas, struct maple_copy *cp) · 541 unmodified lines
2137 mas->node = mt_slot_locked(mas->tree, cp->slot, 0);2143 mas->node = mt_slot_locked(mas->tree, cp->slot, 0);
2138 /* Insert the new data in the tree */2144 /* Insert the new data in the tree */
2139 mas_topiary_replace(mas, old_enode, cp->height);2145 mas_topiary_replace(mas, old_enode, cp->height);
2140 if (!mte_is_leaf(mas->node))2146 if (mt_is_alloc(mas->tree) && !mte_is_root(mas->node))
2141 mas_update_gap(mas);2147 mas_update_gap_known(mas, cp->gap[0]);
2142 2148
2143 mtree_range_walk(mas);2149 mtree_range_walk(mas);
2144}2150}

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