]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
mmap: mmap_region() Remove mas_reset() as it will happen if needed
authorLiam R. Howlett <Liam.Howlett@Oracle.com>
Thu, 26 Nov 2020 00:49:08 +0000 (19:49 -0500)
committerLiam R. Howlett <Liam.Howlett@Oracle.com>
Tue, 5 Jan 2021 17:33:29 +0000 (12:33 -0500)
Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
lib/maple_tree.c
lib/test_maple_tree.c
mm/mmap.c

index 8fbd063d78631fd19fb4e6c9bcd7b0c714f0e201..596b6eb7429dab099c8f50d8b94e9f1630d7976f 100644 (file)
@@ -519,7 +519,7 @@ mas_safe_pivot(const struct ma_state *mas, unsigned char piv)
 static inline unsigned long
 mas_safe_min(struct ma_state *mas, unsigned long *pivots, unsigned char piv)
 {
-       if (!piv)
+       if (unlikely(!piv))
                return mas->min;
 
        return pivots[piv - 1] + 1;
@@ -3070,14 +3070,14 @@ static inline bool __mas_walk(struct ma_state *mas, unsigned long *range_min,
                mas->depth++;
 
                mas_node_walk(mas, type, range_min, range_max);
-               if (ma_is_leaf(type)) // Leaf.
+               if (unlikely(ma_is_leaf(type)))
                        return true;
 
                next = mas_get_slot(mas, mas->offset);
                if (!next)
                        return false;
 
-               // Traverse.
+               // Descend.
                mas->max = *range_max;
                mas->min = *range_min;
                mas->node = next;
@@ -3819,7 +3819,7 @@ bool _mas_rev_awalk(struct ma_state *mas, unsigned long size)
 {
        enum maple_type type = mte_node_type(mas->node);
        struct maple_node *node = mas_mn(mas);
-       unsigned long *pivots, *gaps;
+       unsigned long *pivots, *gaps = NULL;
        void **slots;
        unsigned long gap, max, min;
 
@@ -3840,6 +3840,7 @@ bool _mas_rev_awalk(struct ma_state *mas, unsigned long size)
                if (mas->last < min)
                        continue;
 
+
                if (mas->index > max) {
                        mas_set_err(mas, -EBUSY);
                        return false;
@@ -3967,8 +3968,7 @@ static inline bool _mas_walk(struct ma_state *mas, unsigned long *range_min,
                goto not_found;
 
        if (mas_is_ptr(mas)) {
-               *range_min = 0;
-               *range_max = 0;
+               *range_min = *range_max = 0;
                if (!mas->index)
                        return true;
 
index 33fb7ee3d766af34c5a7e7532a777504d8f824cf..9d264d3cd4620f49dc4f09dbe73061c0d3c7284f 100644 (file)
@@ -12,6 +12,7 @@
 #define CONFIG_DEBUG_MAPLE_TREE
 //#define BENCH_SLOT_STORE
 //#define BENCH_NODE_STORE
+//#define BENCH_AWALK
 //#define BENCH_WALK
 //#define BENCH_FORK
 static
@@ -35318,6 +35319,23 @@ static noinline void bench_node_store(struct maple_tree *mt)
 }
 #endif
 
+#if defined(BENCH_AWALK)
+static noinline void bench_awalk(struct maple_tree *mt)
+{
+       int i, max = 2500, count = 30000000;
+       MA_STATE(mas, mt, 1470, 1470);
+
+       for (i = 0; i < max; i += 10)
+               mtree_store_range(mt, i, i + 5, xa_mk_value(i), GFP_KERNEL);
+
+       mtree_store_range(mt, 1470, 1475, NULL, GFP_KERNEL);
+
+       for (i = 0; i < count; i++) {
+               mas_get_empty_area_rev(&mas, 0, 2000, 10);
+               mas_reset(&mas);
+       }
+}
+#endif
 #if defined(BENCH_WALK)
 static noinline void bench_walk(struct maple_tree *mt)
 {
@@ -35433,6 +35451,13 @@ static int maple_tree_seed(void)
        mtree_destroy(&tree);
        goto skip;
 #endif
+#if defined(BENCH_AWALK)
+#define BENCH
+       mtree_init(&tree, MAPLE_ALLOC_RANGE);
+       bench_awalk(&tree);
+       mtree_destroy(&tree);
+       goto skip;
+#endif
 #if defined(BENCH_WALK)
 #define BENCH
        mtree_init(&tree, MAPLE_ALLOC_RANGE);
index ca95db0b6936bd9858f06a4aa7382281c038bf9e..ba32eee7f0206f6bdcdcc21a70d32f55c7f63ac0 100644 (file)
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -2740,10 +2740,10 @@ cannot_expand:
 
        /*
         * mas was called for the prev vma, and that may not be the correct
-        * location for the vma being inserted.
+        * location for the vma being inserted, but is is before that location
+        * and so the call to vma_mas_link()->vma_mas_store()->mas_store_gfp()
+        * will detect the write as a spanning store and reset mas if necessary.
         */
-       if (mas.max < addr)
-               mas_reset(&mas);
        mas_set(&mas, addr);
        mas_walk(&mas);
        vma_mas_link(mm, vma, &mas, prev);