]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
maple_tree: Make allocations node size agnostic
authorLiam R. Howlett <Liam.Howlett@Oracle.com>
Fri, 7 Aug 2020 18:29:45 +0000 (14:29 -0400)
committerLiam R. Howlett <Liam.Howlett@Oracle.com>
Fri, 30 Oct 2020 19:09:07 +0000 (15:09 -0400)
Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
lib/maple_tree.c
lib/test_maple_tree.c

index 7451cc319d6ef45a9d041b47097688568128a2af..4abaf15c3ee4fd97eebc946d73f012d4b972b855 100644 (file)
@@ -892,16 +892,16 @@ static inline struct maple_node *mas_next_alloc(struct ma_state *ms)
        mn = mas_get_alloc(ms);
        if (cnt == 1) {
                ms->alloc = NULL;
-       } else if (cnt <= 16) {
+       } else if (cnt <= MAPLE_NODE_SLOTS + 1) {
                cnt -= 2;
                smn = mn->slot[cnt];
                mn->slot[cnt] = NULL;
                mn = smn;
-       } else if (cnt > 16) {
+       } else if (cnt > MAPLE_NODE_SLOTS + 1) {
                cnt -= 2;
-               smn = mn->slot[(cnt / 15) - 1];
-               mn = smn->slot[(cnt % 15)];
-               smn->slot[cnt % 15] = NULL;
+               smn = mn->slot[(cnt / MAPLE_NODE_SLOTS) - 1];
+               mn = smn->slot[(cnt % MAPLE_NODE_SLOTS)];
+               smn->slot[cnt % MAPLE_NODE_SLOTS] = NULL;
        }
 
        return mn;
@@ -916,15 +916,15 @@ static inline void mas_push_node(struct ma_state *mas, struct maple_enode *used)
        cnt = mas_get_alloc_cnt(mas);
        if (cnt == 0) {
                mas->alloc = reuse;
-       } else if (cnt <= 15) {
+       } else if (cnt <= MAPLE_NODE_SLOTS) {
                cnt--;
                node->slot[cnt] = reuse;
        } else {
                struct maple_node *smn;
 
                cnt--;
-               smn = node->slot[(cnt/15) - 1];
-               smn->slot[cnt % 15] = reuse;
+               smn = node->slot[(cnt/MAPLE_NODE_SLOTS) - 1];
+               smn->slot[cnt % MAPLE_NODE_SLOTS] = reuse;
        }
        cnt = mas_get_alloc_cnt(mas);
 
index 389da4399f2b84b66d87dc138a53a5f5752cd230..1c9d8a1c5331d81758b933276e7871df4468e944 100644 (file)
@@ -190,7 +190,7 @@ static noinline void check_new_node(struct maple_tree *mt)
 {
 
        struct maple_node *mn, *smn;
-       int cnt = 0;
+       int i, j, total, full_slots, cnt = 0;
 
        MA_STATE(mas, mt, 0, 0);
 
@@ -250,41 +250,30 @@ static noinline void check_new_node(struct maple_tree *mt)
        mas_nomem(&mas, GFP_KERNEL);
 
        // Set allocation request to 127.
-       mas_node_cnt(&mas, 127);
-       // Drop the lock and allocate 3 nodes.
+       total = 127;
+       full_slots = (total - MAPLE_NODE_SLOTS) / MAPLE_NODE_SLOTS;
+       mas_node_cnt(&mas, total);
+       // Drop the lock and allocate 127 nodes.
        mas_nomem(&mas, GFP_KERNEL);
        mn = mas_get_alloc(&mas);
        MT_BUG_ON(mt, mn == NULL);
        cnt++;
-       for (int i = 0; i < 7; i++) {
+       for (i = 0; i < MAPLE_NODE_SLOTS; i++) {
+               j = 0;
                smn = mn->slot[i];
                MT_BUG_ON(mt, smn == NULL);
                cnt++;
-               for (int j = 0; j < 15; j++) {
+               while ((i < full_slots) && (j < MAPLE_NODE_SLOTS)) {
                        MT_BUG_ON(mt, smn->slot[j] == NULL);
                        cnt++;
+                       j++;
                }
        }
-
-       smn = mn->slot[7];
-       cnt++;
-       MT_BUG_ON(mt, smn == NULL);
-       for (int j = 0; j < 6; j++) {
-               MT_BUG_ON(mt, smn->slot[j] == NULL);
-               cnt++;
-       }
-
-       for (int i = 8; i < 15; i++) {
-               MT_BUG_ON(mt, mn->slot[i] == NULL);
-               cnt++;
-       }
-
        MT_BUG_ON(mt, mas_get_alloc_cnt(&mas) != 127);
        mas_nomem(&mas, GFP_KERNEL); // Free.
-       MT_BUG_ON(mt, mas_get_alloc_cnt(&mas) != 0);
-       for (int i = 1; i < 128; i++) {
-               int j;
 
+       MT_BUG_ON(mt, mas_get_alloc_cnt(&mas) != 0);
+       for (i = 1; i < 128; i++) {
                mas_node_cnt(&mas, i); // Request
                mas_nomem(&mas, GFP_KERNEL); // Fill request
                MT_BUG_ON(mt, mas_get_alloc_cnt(&mas) != i); // check request filled
@@ -295,9 +284,8 @@ static noinline void check_new_node(struct maple_tree *mt)
                }
                MT_BUG_ON(mt, mas_get_alloc_cnt(&mas) != 0);
        }
-       for (int i = 1; i < 128; i++) {
-               int j;
 
+       for (i = 1; i < 128; i++) {
                MA_STATE(mas2, mt, 0, 0);
                mas_node_cnt(&mas, i); // Request
                mas_nomem(&mas, GFP_KERNEL); // Fill request