From ea836d9e22f5d864ce3fbe6a2ade0b8073b62328 Mon Sep 17 00:00:00 2001 From: "Liam R. Howlett" Date: Fri, 25 Nov 2022 14:30:29 -0500 Subject: [PATCH] maple_tree: Rename mas_pause() to mas_invalidate() Change the name of mas_pause() to better reflect the maple state could be invalid. mas_invalidate() sets the internal node to MAS_INVALID which will continue from the current index and last for the next maple state operation. Signed-off-by: Liam R. Howlett --- Documentation/core-api/maple_tree.rst | 4 ++-- include/linux/maple_tree.h | 10 +++++----- include/linux/mm.h | 2 +- lib/maple_tree.c | 24 ++++++++++++------------ lib/test_maple_tree.c | 8 ++++---- tools/testing/radix-tree/maple.c | 2 +- 6 files changed, 25 insertions(+), 25 deletions(-) diff --git a/Documentation/core-api/maple_tree.rst b/Documentation/core-api/maple_tree.rst index 45defcf15da7..9c5162d85405 100644 --- a/Documentation/core-api/maple_tree.rst +++ b/Documentation/core-api/maple_tree.rst @@ -164,7 +164,7 @@ at that location. You can walk each entry within a range by using mas_for_each(). If you want to walk each element of the tree then ``0`` and ``ULONG_MAX`` may be used as the range. If the lock needs to be periodically dropped, see the locking -section mas_pause(). +section mas_invalidate(). Using a maple state allows mas_next() and mas_prev() to function as if the tree was a linked list. With such a high branching factor the amortized @@ -179,7 +179,7 @@ mas_find_rev() will find the fist entry which exists at or below the last on the first call, and the previous entry from every subsequent calls. If the user needs to yield the lock during an operation, then the maple state -must be paused using mas_pause(). +must be invalidated using mas_invalidate(). There are a few extra interfaces provided when using an allocation tree. If you wish to search for a gap within a range, then mas_empty_area() diff --git a/include/linux/maple_tree.h b/include/linux/maple_tree.h index 3f972602c978..5999aa5f0ac7 100644 --- a/include/linux/maple_tree.h +++ b/include/linux/maple_tree.h @@ -420,7 +420,7 @@ struct ma_wr_state { #define MAS_START ((struct maple_enode *)1UL) #define MAS_ROOT ((struct maple_enode *)5UL) #define MAS_NONE ((struct maple_enode *)9UL) -#define MAS_PAUSE ((struct maple_enode *)17UL) +#define MAS_INVALID ((struct maple_enode *)17UL) #define MA_ERROR(err) \ ((struct maple_enode *)(((unsigned long)err << 2) | 2UL)) @@ -461,7 +461,7 @@ int mas_preallocate(struct ma_state *mas, void *entry, gfp_t gfp); bool mas_is_err(struct ma_state *mas); bool mas_nomem(struct ma_state *mas, gfp_t gfp); -void mas_pause(struct ma_state *mas); +void mas_invalidate(struct ma_state *mas); void maple_tree_init(void); void mas_destroy(struct ma_state *mas); int mas_expected_entries(struct ma_state *mas, unsigned long nr_entries); @@ -488,10 +488,10 @@ static inline bool mas_is_none(struct ma_state *mas) return mas->node == MAS_NONE; } -/* Checks if a mas has been paused */ -static inline bool mas_is_paused(struct ma_state *mas) +/* Checks if a mas has been invalidated */ +static inline bool mas_is_invalid(struct ma_state *mas) { - return mas->node == MAS_PAUSE; + return mas->node == MAS_INVALID; } void mas_dup_tree(struct ma_state *oldmas, struct ma_state *mas); diff --git a/include/linux/mm.h b/include/linux/mm.h index 5483041ef7d8..22788bcf97cc 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -716,7 +716,7 @@ static inline int vma_iter_bulk_store(struct vma_iterator *vmi, static inline void vma_iter_invalidate(struct vma_iterator *vmi) { - mas_pause(&vmi->mas); + mas_invalidate(&vmi->mas); } static inline void vma_iter_set(struct vma_iterator *vmi, unsigned long addr) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 440539ff0d11..36b32258f11e 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -4737,7 +4737,7 @@ static inline void *mas_next_entry(struct ma_state *mas, unsigned long limit) if (mas->index > limit) { mas->index = mas->last = limit; - mas_pause(mas); + mas_invalidate(mas); return NULL; } last = mas->last; @@ -4848,7 +4848,7 @@ static inline void *mas_prev_entry(struct ma_state *mas, unsigned long min) if (mas->index < min) { mas->index = mas->last = min; - mas_pause(mas); + mas_invalidate(mas); return NULL; } retry: @@ -5857,7 +5857,7 @@ EXPORT_SYMBOL_GPL(mas_expected_entries); */ void *mas_next(struct ma_state *mas, unsigned long max) { - if (mas_is_none(mas) || mas_is_paused(mas)) + if (mas_is_none(mas) || mas_is_invalid(mas)) mas->node = MAS_START; if (mas_is_start(mas)) @@ -5921,7 +5921,7 @@ void *mas_prev(struct ma_state *mas, unsigned long min) if (unlikely(mas_is_ptr(mas))) return NULL; - if (mas_is_none(mas) || mas_is_paused(mas)) + if (mas_is_none(mas) || mas_is_invalid(mas)) mas->node = MAS_START; if (mas_is_start(mas)) { @@ -5964,7 +5964,7 @@ void *mt_prev(struct maple_tree *mt, unsigned long index, unsigned long min) EXPORT_SYMBOL_GPL(mt_prev); /** - * mas_pause() - Pause a mas_find/mas_for_each to drop the lock. + * mas_invalidate() - Pause a mas_find/mas_for_each to drop the lock. * @mas: The maple state to pause * * Some users need to pause a walk and drop the lock they're holding in @@ -5972,15 +5972,15 @@ EXPORT_SYMBOL_GPL(mt_prev); * on an entry. Those users should call this function before they drop * the lock. It resets the @mas to be suitable for the next iteration * of the loop after the user has reacquired the lock. If most entries - * found during a walk require you to call mas_pause(), the mt_for_each() + * found during a walk require you to call mas_invalidate(), the mt_for_each() * iterator may be more appropriate. * */ -void mas_pause(struct ma_state *mas) +void mas_invalidate(struct ma_state *mas) { - mas->node = MAS_PAUSE; + mas->node = MAS_INVALID; } -EXPORT_SYMBOL_GPL(mas_pause); +EXPORT_SYMBOL_GPL(mas_invalidate); /** * mas_find() - On the first call, find the entry at or after mas->index up to @@ -5996,7 +5996,7 @@ EXPORT_SYMBOL_GPL(mas_pause); */ void *mas_find(struct ma_state *mas, unsigned long max) { - if (unlikely(mas_is_paused(mas))) { + if (unlikely(mas_is_invalid(mas))) { if (unlikely(mas->last == ULONG_MAX)) { mas->node = MAS_NONE; return NULL; @@ -6040,7 +6040,7 @@ EXPORT_SYMBOL_GPL(mas_find); */ void *mas_find_rev(struct ma_state *mas, unsigned long min) { - if (unlikely(mas_is_paused(mas))) { + if (unlikely(mas_is_invalid(mas))) { if (unlikely(mas->last == ULONG_MAX)) { mas->node = MAS_NONE; return NULL; @@ -6088,7 +6088,7 @@ void *mas_erase(struct ma_state *mas) void *entry; MA_WR_STATE(wr_mas, mas, NULL); - if (mas_is_none(mas) || mas_is_paused(mas)) + if (mas_is_none(mas) || mas_is_invalid(mas)) mas->node = MAS_START; /* Retry unnecessary when holding the write lock. */ diff --git a/lib/test_maple_tree.c b/lib/test_maple_tree.c index c16147f71bc0..820e0238ef28 100644 --- a/lib/test_maple_tree.c +++ b/lib/test_maple_tree.c @@ -421,7 +421,7 @@ static noinline void check_find(struct maple_tree *mt) } mas_unlock(&mas); - /* Test mas_pause */ + /* Test mas_invalidate */ val = 0; mas_set(&mas, val); mas_lock(&mas); @@ -435,7 +435,7 @@ static noinline void check_find(struct maple_tree *mt) if (!val) val = 1; - mas_pause(&mas); + mas_invalidate(&mas); mas_unlock(&mas); mas_lock(&mas); } @@ -514,7 +514,7 @@ static noinline void check_find(struct maple_tree *mt) /* For zero check. */ if (!val) val = 1; - mas_pause(&mas); + mas_invalidate(&mas); mas_unlock(&mas); mas_lock(&mas); } @@ -1892,7 +1892,7 @@ static noinline void next_prev_test(struct maple_tree *mt) mas_set(&mas, 0); i = 0; mas_for_each(&mas, val, 1000) { - mas_pause(&mas); + mas_invalidate(&mas); i++; } diff --git a/tools/testing/radix-tree/maple.c b/tools/testing/radix-tree/maple.c index 2e91973fbaa6..e6ec96350a0f 100644 --- a/tools/testing/radix-tree/maple.c +++ b/tools/testing/radix-tree/maple.c @@ -914,7 +914,7 @@ static inline void *mas_range_load(struct ma_state *mas, void *entry = NULL; unsigned long index = mas->index; - if (mas_is_none(mas) || mas_is_paused(mas)) + if (mas_is_none(mas) || mas_is_invalid(mas)) mas->node = MAS_START; retry: if (mas_tree_walk(mas, range_min, range_max)) -- 2.49.0