]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
maple_tree: Optimizations on mas_data_end and mas_rev_awalk
authorLiam R. Howlett <Liam.Howlett@Oracle.com>
Fri, 4 Sep 2020 19:17:57 +0000 (15:17 -0400)
committerLiam R. Howlett <Liam.Howlett@Oracle.com>
Fri, 30 Oct 2020 19:11:07 +0000 (15:11 -0400)
Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
include/linux/maple_tree.h
lib/maple_tree.c

index d300386695236f1348c5e541684fe687a327721b..560a5de8fe77a0e9534c2a869e0965406d06e8dc 100644 (file)
@@ -37,7 +37,6 @@
 #define MAPLE_SPARSE16_SLOTS   24      /* 248 bytes */
 #define MAPLE_SPARSE9_SLOTS    27      /* 256 bytes */
 #define MAPLE_SPARSE6_SLOTS    30      /* 256 bytes */
-#define MA_NODE_PER_PAGE        16
 #else
 #define MAPLE_NODE_SLOTS       15      /* 128 bytes including ->parent */
 #define MAPLE_RANGE64_SLOTS    8       /* 128 bytes */
@@ -50,9 +49,9 @@
 #define MAPLE_SPARSE16_SLOTS   12      /* 128 bytes */
 #define MAPLE_SPARSE9_SLOTS    13      /* 127 bytes */
 #define MAPLE_SPARSE6_SLOTS    14      /* 128 bytes */
-#define MA_NODE_PER_PAGE       32
 #endif // End NODE256
 
+#define MA_MAX_ALLOC           127
 #else
 /* Need to do corresponding calculations for 32-bit kernels */
 #endif
index 9af32117ebc2f513ea971bbd1a41ec3f46af9bff..a010d1f8fc2998cba98c044d2842effb726c6109 100644 (file)
@@ -1131,15 +1131,11 @@ static inline unsigned char mas_data_end(const struct ma_state *mas)
        enum maple_type type = mte_node_type(mas->node);
        unsigned long piv = mas->min;
 
-       for (; slot < mt_slots[type]; slot++) {
+       while (slot < mt_slots[type]) {
                piv = _mas_get_safe_pivot(mas, slot, type);
                if (piv >= mas->max)
                        break;
-
-               if (!piv && slot) {
-                       slot--;
-                       break;
-               }
+               slot++;
        }
 
        return slot;
@@ -3913,20 +3909,8 @@ static inline void mas_rev_awalk(struct ma_state *mas, unsigned long size)
 {
        struct maple_enode *last = NULL;
 
-       mas_start(mas);
-       if (mas_is_none(mas)) {
-               mas_set_offset(mas, MAPLE_NODE_SLOTS);
-               return;
-       }
-
-       if (mas_is_ptr(mas))
-               return;
-       if (mas_is_err(mas))
-               return;
-
        mas_set_offset(mas, mas_data_end(mas));
 
-
        /* There are 4 options:
         * go to child (descend)
         * go back to parent (ascend)
@@ -4054,9 +4038,9 @@ void mas_set_rev_index(struct ma_state *mas, unsigned long size)
        mas->index = mas->last - size + 1;
 }
 
-static void _mas_empty_or_single_empty_area(struct ma_state *mas,
-               unsigned long min, unsigned long max, unsigned long size,
-               bool fwd)
+static void _mas_sparse_area(struct ma_state *mas,
+                            unsigned long min, unsigned long max,
+                            unsigned long size, bool fwd)
 {
        unsigned long start = 0;
 
@@ -4084,7 +4068,7 @@ static inline int _mas_get_empty_area(struct ma_state *mas,
 
        // Empty set.
        if (mas_is_none(mas) || mas_is_ptr(mas)) {
-               _mas_empty_or_single_empty_area(mas, min, max, size, forward);
+               _mas_sparse_area(mas, min, max, size, forward);
                return 0;
        }
 
@@ -4458,7 +4442,7 @@ static inline struct maple_enode *mas_dup_node(struct ma_state *oldmas,
 static inline void mas_dup_alloc(struct ma_state *mas, int *node_cnt)
 {
 
-       int alloc_cnt = min(*node_cnt, MA_NODE_PER_PAGE);
+       int alloc_cnt = min(*node_cnt, MA_MAX_ALLOC);
        /* Allocate nodes for new tree.  Maximum will be 16 ** height */
        *node_cnt -= alloc_cnt;
        mas_node_cnt(mas, alloc_cnt);
@@ -4470,10 +4454,9 @@ static inline void mas_dup_children(struct ma_state *mas, int *node_cnt)
 {
        struct maple_node *child;
        struct maple_enode *oldchild, *echild;
-       unsigned char slot, end;
+       unsigned char slot, end = mt_slot_count(mas->node);
        int allocated = mas_get_alloc_cnt(mas);
 
-       end = mas_data_end(mas) + 1;
        if (allocated < end) {
                mas->span_enode = mas->node;
                *node_cnt += allocated;