]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
maple_tree: Add mas_free to push unused nodes
authorLiam R. Howlett <Liam.Howlett@Oracle.com>
Tue, 13 Oct 2020 16:14:27 +0000 (12:14 -0400)
committerLiam R. Howlett <Liam.Howlett@Oracle.com>
Fri, 30 Oct 2020 19:13:11 +0000 (15:13 -0400)
Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
include/linux/maple_tree.h
lib/maple_tree.c

index 09b64012a85d1e0c3f42ea79cbacd7c1106830a6..6ff6dd6b1d95adb174d029034159c2891be75c52 100644 (file)
@@ -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.
index 5fbaa9914d1669fb739102f52171c9a83117d24c..6512fbb890f217b10ddf1be7ac08df2ff3d8af9f 100644 (file)
@@ -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);