From: Liam R. Howlett Date: Tue, 13 Oct 2020 16:14:27 +0000 (-0400) Subject: maple_tree: Add mas_free to push unused nodes X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=ebae3442a33190294fbda5fce6f50a85caca5684;p=users%2Fjedix%2Flinux-maple.git maple_tree: Add mas_free to push unused nodes Signed-off-by: Liam R. Howlett --- diff --git a/include/linux/maple_tree.h b/include/linux/maple_tree.h index 09b64012a85d..6ff6dd6b1d95 100644 --- a/include/linux/maple_tree.h +++ b/include/linux/maple_tree.h @@ -367,7 +367,7 @@ static inline bool mt_in_rcu(struct maple_tree *mt) #ifdef CONFIG_MAPLE_RCU_DISABLED return false; #endif - return !!(mt->ma_flags & MAPLE_USE_RCU); + return mt->ma_flags & MAPLE_USE_RCU; } /** * mt_clear_in_rcu() - Switch the tree to non-RCU mode. diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 5fbaa9914d16..6512fbb890f2 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -726,7 +726,9 @@ void mte_destroy_walk(struct maple_enode *, struct maple_tree *); * @recursive - specifies if this sub-tree is to be freed or just the single * node. */ -static inline void mat_free(struct ma_topiary *mat, bool recursive) +static inline void mas_free(struct ma_state *mas, struct maple_enode *used); +static inline void mas_mat_free(struct ma_state *mas, struct ma_topiary *mat, + bool recursive) { struct maple_enode *next; @@ -735,7 +737,7 @@ static inline void mat_free(struct ma_topiary *mat, bool recursive) if (recursive) mte_destroy_walk(mat->head, mat->mtree); else - mte_free(mat->head); + mas_free(mas, mat->head); mat->head = next; } } @@ -897,6 +899,15 @@ static inline void mas_push_node(struct ma_state *mas, struct maple_enode *used) BUG_ON(!mas_alloc_cnt(mas)); } +static inline void mas_free(struct ma_state *mas, struct maple_enode *used) +{ + if (mt_in_rcu(mas->tree)) + mte_free(used); + else { + mas_push_node(mas, used); + } +} + static inline void mas_node_node(struct ma_state *ms, gfp_t gfp) { struct maple_node *mn, *smn; @@ -1359,7 +1370,7 @@ static inline void mas_replace(struct ma_state *mas, bool advanced) } if (!advanced) - mte_free(prev); + mas_free(mas, prev); } /* @@ -2131,10 +2142,10 @@ static inline void mas_wmb_replace(struct ma_state *mas, if (!mte_is_leaf(mas->node)) mas_descend_adopt(mas); - mat_free(free, false); + mas_mat_free(mas, free, false); if (destroy) - mat_free(destroy, true); + mas_mat_free(mas, destroy, true); if (mte_is_leaf(mas->node)) return; @@ -3106,6 +3117,9 @@ static inline void *_mas_store(struct ma_state *mas, void *entry, bool overwrite int ret = 0; + if (mas_is_err(mas)) + return NULL; + if (mas_start(mas) || mas_is_none(mas) || mas->node == MAS_ROOT) { ret = ma_root_ptr(mas, entry, content, overwrite); if (mas_is_err(mas)) @@ -4444,7 +4458,6 @@ free_leaf: kmem_cache_free(maple_node_cache, node); } -void mt_dump(const struct maple_tree *mt); void mte_destroy_walk(struct maple_enode *enode, struct maple_tree *mt) { struct maple_node *node = mte_to_node(enode);