]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
maple_tree: Some clean up of comments and mte_set_pivot(), etc
authorLiam R. Howlett <Liam.Howlett@oracle.com>
Fri, 26 Nov 2021 15:23:11 +0000 (10:23 -0500)
committerLiam R. Howlett <Liam.Howlett@oracle.com>
Fri, 26 Nov 2021 15:23:11 +0000 (10:23 -0500)
Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
lib/maple_tree.c

index d4419fd5059490ae6990789dafb772e30e1dd06d..5aa6825f7232d15a3c9e09fb7e85cebe58eba783 100644 (file)
@@ -685,40 +685,30 @@ mas_logical_pivot(struct ma_state *mas, unsigned long *pivots,
 }
 
 /*
- * ma_set_pivot() - Set a pivot to a value.
- * @mn: The maple node
+ * mte_set_pivot() - Set a pivot to a value in an encoded maple node.
+ * @mn: The encoded maple node
  * @piv: The pivot offset
- * @type: The maple node type
  * @val: The value of the pivot
  */
-static inline void ma_set_pivot(struct maple_node *mn, unsigned char piv,
-               enum maple_type type, unsigned long val)
+static inline void mte_set_pivot(struct maple_enode *mn, unsigned char piv,
+                               unsigned long val)
 {
-       BUG_ON(piv >= mt_pivots[type]);
+       struct maple_node *node = mte_to_node(mn);
+       enum maple_type type = mte_node_type(mn);
 
+       BUG_ON(piv >= mt_pivots[type]);
        switch (type) {
        default:
        case maple_range_64:
        case maple_leaf_64:
-               (&mn->mr64)->pivot[piv] = val;
+               (&node->mr64)->pivot[piv] = val;
                break;
        case maple_arange_64:
-               (&mn->ma64)->pivot[piv] = val;
+               (&node->ma64)->pivot[piv] = val;
        case maple_dense:
                break;
        }
-}
 
-/*
- * mte_set_pivot() - Set a pivot to a value in an encoded maple node.
- * @mn: The encoded maple node
- * @piv: The pivot offset
- * @val: The value of the pivot
- */
-static inline void mte_set_pivot(struct maple_enode *mn, unsigned char piv,
-                               unsigned long val)
-{
-       return ma_set_pivot(mte_to_node(mn), piv, mte_node_type(mn), val);
 }
 
 /*
@@ -916,6 +906,7 @@ static inline void mas_free(struct ma_state *mas, struct maple_enode *used);
 
 /*
  * mas_mat_free() - Free all nodes in a dead list.
+ * @mas - the maple state
  * @mat - the ma_topiary linked list of dead nodes to free.
  *
  * Free walk a dead list.
@@ -933,6 +924,7 @@ static void mas_mat_free(struct ma_state *mas, struct ma_topiary *mat)
 
 /*
  * mas_mat_destroy() - Free all nodes and subtrees in a dead list.
+ * @mas - the maple state
  * @mat - the ma_topiary linked list of dead nodes to free.
  *
  * Destroy walk a dead list.
@@ -1304,6 +1296,16 @@ done:
        return entry;
 }
 
+/*
+ * ma_data_end() - Find the end of the data in a node.
+ * @node: The maple node
+ * @type: The maple node type
+ * @pivots: The array of pivots in the node
+ * @max: The maximum value in the node
+ *
+ * Uses metadata to find the end of the data when possible.
+ * Return: The zero indexed last slot with data (may be null).
+ */
 static inline unsigned char ma_data_end(struct maple_node *node,
                                        enum maple_type type,
                                        unsigned long *pivots,
@@ -1323,6 +1325,7 @@ static inline unsigned char ma_data_end(struct maple_node *node,
 
        return mt_pivots[type];
 }
+
 /*
  * mas_data_end() - Find the end of the data (slot).
  * @mas: the maple state
@@ -1594,11 +1597,13 @@ static inline void mas_adopt_children(struct ma_state *mas,
                struct maple_enode *parent)
 {
        enum maple_type type = mte_node_type(parent);
-       void __rcu **slots = ma_slots(mte_to_node(mas->node), type);
+       struct maple_node *node = mas_mn(mas);
+       void __rcu **slots = ma_slots(node, type);
+       unsigned long *pivots = ma_pivots(node, type);
        struct maple_enode *child;
        unsigned char offset;
 
-       offset = mas_data_end(mas);
+       offset = ma_data_end(node, type, pivots, mas->max);
        do {
                child = mas_slot_locked(mas, slots, offset);
                mte_set_parent(child, parent, offset);
@@ -1656,6 +1661,7 @@ static inline bool mas_new_child(struct ma_state *mas, struct ma_state *child)
        enum maple_type mt;
        unsigned char offset;
        unsigned char end;
+       unsigned long *pivots;
        struct maple_enode *entry;
        struct maple_node *node;
        void __rcu **slots;
@@ -1663,7 +1669,8 @@ static inline bool mas_new_child(struct ma_state *mas, struct ma_state *child)
        mt = mte_node_type(mas->node);
        node = mas_mn(mas);
        slots = ma_slots(node, mt);
-       end = mas_data_end(mas);
+       pivots = ma_pivots(node, mt);
+       end = ma_data_end(node, mt, pivots, mas->max);
        for (offset = mas->offset; offset <= end; offset++) {
                entry = mas_slot_locked(mas, slots, offset);
                if (mte_parent(entry) == node) {
@@ -4332,11 +4339,11 @@ static inline int mas_next_node(struct ma_state *mas, struct maple_node *node,
                offset = mas->offset;
                level++;
                node = mas_mn(mas);
-       } while (unlikely(offset == mas_data_end(mas)));
+               mt = mte_node_type(mas->node);
+               pivots = ma_pivots(node, mt);
+       } while (unlikely(offset == ma_data_end(node, mt, pivots, mas->max)));
 
-       mt = mte_node_type(mas->node);
        slots = ma_slots(node, mt);
-       pivots = ma_pivots(node, mt);
        pivot = mas_safe_pivot(mas, pivots, ++offset, mt);
        while (unlikely(level > 1)) {
                /* Descend, if necessary */