]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
maple_tree: Start using mte_slots more
authorLiam R. Howlett <Liam.Howlett@Oracle.com>
Tue, 8 Sep 2020 16:56:31 +0000 (12:56 -0400)
committerLiam R. Howlett <Liam.Howlett@Oracle.com>
Fri, 30 Oct 2020 19:11:19 +0000 (15:11 -0400)
Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
lib/maple_tree.c

index d163eaee08988cd563a39a191c1ac33c759f36f9..e6b7e2ecb2add4d2cf0e2e1943d10e1c37ab2558 100644 (file)
@@ -584,38 +584,29 @@ static inline void __rcu **ma_get_slots(struct maple_node *mn,
 }
 
 static inline struct maple_enode *ma_get_slot(
-               const struct maple_node *mn, unsigned char slot,
+               struct maple_node *mn, unsigned char offset,
                enum maple_type type, struct maple_tree *mtree)
 {
-       switch (type) {
-       default:
-       case maple_arange_64:
-               return rcu_dereference_check(mn->ma64.slot[slot],
-                               lockdep_is_held(&mtree->ma_lock));
-       case maple_range_64:
-       case maple_leaf_64:
-               return rcu_dereference_check(mn->mr64.slot[slot],
-                               lockdep_is_held(&mtree->ma_lock));
-       case maple_dense:
-               return rcu_dereference_check(mn->slot[slot],
+       void **slots = ma_get_slots(mn, type);
+
+       return rcu_dereference_check(slots[offset],
                                lockdep_is_held(&mtree->ma_lock));
-       }
 }
 
 static inline struct maple_enode *_mte_get_slot(
-               const struct maple_enode *mn, unsigned char slot,
+               struct maple_enode *mn, unsigned char slot,
                enum maple_type type, struct maple_tree *mtree)
 {
        return ma_get_slot(mte_to_node(mn), slot, type, mtree);
 }
 
-static inline struct maple_enode *mte_get_slot(const struct maple_enode *mn,
+static inline struct maple_enode *mte_get_slot(struct maple_enode *mn,
                 unsigned char slot, struct maple_tree *mtree)
 {
        return _mte_get_slot(mn, slot, mte_node_type(mn), mtree);
 }
 
-static inline struct maple_enode *mas_get_slot(const struct ma_state *mas,
+static inline struct maple_enode *mas_get_slot(struct ma_state *mas,
                unsigned char slot)
 {
        return mte_get_slot(mas->node, slot, mas->tree);
@@ -1057,10 +1048,11 @@ static inline unsigned long mas_leaf_max_gap(struct ma_state *mas)
        unsigned long gap = 0;
        void *entry = NULL;
        int i;
+       void **slots = ma_get_slots(mte_to_node(mas->node), mt);
 
        if (ma_is_dense(mt)) {
                for (i = 0; i < mt_slot_count(mas->node); i++) {
-                       entry = mas_get_slot(mas, i);
+                       entry = slots[i];
                        if (entry) {
                                if (gap > max_gap)
                                        max_gap = gap;
@@ -1081,8 +1073,7 @@ static inline unsigned long mas_leaf_max_gap(struct ma_state *mas)
                        pend = mas->max;
 
                gap = pend - pstart + 1;
-               entry = mas_get_slot(mas, i);
-
+               entry = slots[i];
                if (entry)
                        goto next;
 
@@ -1196,19 +1187,20 @@ static inline void mas_update_gap(struct ma_state *mas)
 static inline unsigned long mas_first_node(struct ma_state *mas,
                unsigned long limit)
 {
-       int slot = mas_offset(mas) - 1;
-       unsigned char count = mt_slot_count(mas->node);
+       int offset = mas_offset(mas) - 1;
+       enum maple_type mt = mte_node_type(mas->node);
        unsigned long pivot, min = mas->min;
+       void **slots = ma_get_slots(mte_to_node(mas->node), mt);
 
-       while (++slot < count) {
+       while (++offset < mt_slots[mt]) {
                struct maple_enode *mn;
 
-               pivot = mas_safe_pivot(mas, slot);
+               pivot = _mas_safe_pivot(mas, offset, mt);
                if (pivot > limit)
                        goto no_entry;
 
-               mn = mas_get_slot(mas, slot);
-
+               mn = rcu_dereference_check(slots[offset],
+                               lockdep_is_held(mas->tree->ma_lock));
                if (!mn) {
                        min = pivot + 1;
                        continue;
@@ -1220,7 +1212,7 @@ static inline unsigned long mas_first_node(struct ma_state *mas,
                        mas->min = min;
                        mas->node = mn;
                }
-               mas_set_offset(mas, slot);
+               mas_set_offset(mas, offset);
                return pivot;
        }
 
@@ -1339,18 +1331,20 @@ static inline void mas_replace(struct ma_state *mas, bool advanced)
  */
 static inline bool mas_new_child(struct ma_state *mas, struct ma_state *child)
 {
-       unsigned char slot, end = mt_slot_count(mas->node);
+       enum maple_type mt = mte_node_type(mas->node);
+       unsigned char offset;
        struct maple_enode *entry;
+       void **slots = ma_get_slots(mte_to_node(mas->node), mt);
 
-       for (slot = mas_offset(mas); slot < end; slot++) {
-               entry = mas_get_slot(mas, slot);
+       for (offset= mas_offset(mas); offset < mt_slots[mt]; offset++) {
+               entry = slots[offset];
                if (!entry) // end of node data.
                        break;
 
                if (mte_parent(entry) == mas_mn(mas)) {
-                       mas_set_offset(mas, slot);
+                       mas_set_offset(mas, offset);
                        mas_dup_state(child, mas);
-                       mas_set_offset(mas, slot + 1);
+                       mas_set_offset(mas, offset + 1);
                        mas_descend(child);
                        return true;
                }
@@ -1476,9 +1470,11 @@ static inline void mas_mab_cp(struct ma_state *mas, unsigned char mas_start,
                        unsigned char mab_start)
 {
        int i, j;
+       void **slots = ma_get_slots(mte_to_node(mas->node),
+                                   mte_node_type(mas->node));
 
        for (i = mas_start, j = mab_start; i <= mas_end; i++, j++) {
-               b_node->slot[j] = mas_get_slot(mas, i);
+               b_node->slot[j] = slots[i];
                if (!mte_is_leaf(mas->node) && mt_is_alloc(mas->tree))
                        b_node->gap[j] = mte_get_gap(mas->node, i);