From f974a0fd68a52c942f8172f2fe4564004f4f6d01 Mon Sep 17 00:00:00 2001 From: "Liam R. Howlett" Date: Wed, 25 Nov 2020 19:49:08 -0500 Subject: [PATCH] mmap: mmap_region() Remove mas_reset() as it will happen if needed Signed-off-by: Liam R. Howlett --- lib/maple_tree.c | 12 ++++++------ lib/test_maple_tree.c | 25 +++++++++++++++++++++++++ mm/mmap.c | 6 +++--- 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 8fbd063d7863..596b6eb7429d 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -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; diff --git a/lib/test_maple_tree.c b/lib/test_maple_tree.c index 33fb7ee3d766..9d264d3cd462 100644 --- a/lib/test_maple_tree.c +++ b/lib/test_maple_tree.c @@ -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); diff --git a/mm/mmap.c b/mm/mmap.c index ca95db0b6936..ba32eee7f020 100644 --- 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); -- 2.50.1