From: Liam R. Howlett Date: Tue, 6 Feb 2024 20:55:12 +0000 (-0500) Subject: maple_tree: change allocated requests to a variable X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=be2930e6abf232b012ec0df2d2ece09aac5a2832;p=users%2Fjedix%2Flinux-maple.git maple_tree: change allocated requests to a variable Instead of pre-allocating and pushing/popping maple nodes off a list maintained in the maple state, just set the requested number to a variable and pass it along to the per-cpu array Signed-off-by: Liam R. Howlett --- diff --git a/include/linux/maple_tree.h b/include/linux/maple_tree.h index 060120d121f4..31d4b3e38229 100644 --- a/include/linux/maple_tree.h +++ b/include/linux/maple_tree.h @@ -439,7 +439,7 @@ struct ma_state { struct maple_enode *node; /* The node containing this entry */ unsigned long min; /* The minimum index of this node - implied pivot min */ unsigned long max; /* The maximum index of this node - implied pivot max */ - struct maple_alloc *alloc; /* Allocated nodes for this operation */ + unsigned long requested; /* Requested nodes for this operation */ enum maple_status status; /* The status of the state (active, start, none, etc) */ unsigned char depth; /* depth of tree descent during write */ unsigned char offset; @@ -486,7 +486,7 @@ struct ma_wr_state { .status = ma_start, \ .min = 0, \ .max = ULONG_MAX, \ - .alloc = NULL, \ + .requested = 0, \ .mas_flags = 0, \ .store_type = wr_invalid, \ } diff --git a/lib/maple_tree.c b/lib/maple_tree.c index af9c708dfd4b..824ed2c30455 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -578,67 +578,6 @@ static __always_inline bool mte_dead_node(const struct maple_enode *enode) return (parent == node); } -/* - * mas_allocated() - Get the number of nodes allocated in a maple state. - * @mas: The maple state - * - * The ma_state alloc member is overloaded to hold a pointer to the first - * allocated node or to the number of requested nodes to allocate. If bit 0 is - * set, then the alloc contains the number of requested nodes. If there is an - * allocated node, then the total allocated nodes is in that node. - * - * Return: The total number of nodes allocated - */ -static inline unsigned long mas_allocated(const struct ma_state *mas) -{ - if (!mas->alloc || ((unsigned long)mas->alloc & 0x1)) - return 0; - - return mas->alloc->total; -} - -/* - * mas_set_alloc_req() - Set the requested number of allocations. - * @mas: the maple state - * @count: the number of allocations. - * - * The requested number of allocations is either in the first allocated node, - * located in @mas->alloc->request_count, or directly in @mas->alloc if there is - * no allocated node. Set the request either in the node or do the necessary - * encoding to store in @mas->alloc directly. - */ -static inline void mas_set_alloc_req(struct ma_state *mas, unsigned long count) -{ - if (!mas->alloc || ((unsigned long)mas->alloc & 0x1)) { - if (!count) - mas->alloc = NULL; - else - mas->alloc = (struct maple_alloc *)(((count) << 1U) | 1U); - return; - } - - mas->alloc->request_count = count; -} - -/* - * mas_alloc_req() - get the requested number of allocations. - * @mas: The maple state - * - * The alloc count is either stored directly in @mas, or in - * @mas->alloc->request_count if there is at least one node allocated. Decode - * the request count if it's stored directly in @mas->alloc. - * - * Return: The allocation request count. - */ -static inline unsigned int mas_alloc_req(const struct ma_state *mas) -{ - if ((unsigned long)mas->alloc & 0x1) - return (unsigned long)(mas->alloc) >> 1; - else if (mas->alloc) - return mas->alloc->request_count; - return 0; -} - /* * ma_pivots() - Get a pointer to the maple node pivots. * @node - the maple node @@ -1164,7 +1103,7 @@ static void mas_node_count_gfp(struct ma_state *mas, int count, gfp_t gfp) return; mas_set_err(mas, ret); - mas_set_alloc_req(mas, count); + mas->requested = count; } /* @@ -4195,10 +4134,6 @@ static inline void mas_wr_preallocate(struct ma_wr_state *wr_mas, void *entry, g return; mas_node_count_gfp(mas, request, gfp); - if (likely(!mas_is_err(mas))) - return; - - mas_set_alloc_req(mas, 0); } /** @@ -5294,6 +5229,7 @@ static inline void mas_wr_store_prealloc(struct ma_wr_state *wr_mas, void *entry mas_node_count(mas, request); } + /* Interface */ /** @@ -5445,14 +5381,10 @@ EXPORT_SYMBOL_GPL(mas_preallocate); * @mas: The maple state * * Upon completion, check the left-most node and rebalance against the node to - * the right if necessary. Frees any allocated nodes associated with this maple - * state. + * the right if necessary. */ void mas_destroy(struct ma_state *mas) { - struct maple_alloc *node; - unsigned long total; - /* * When using mas_for_each() to insert an expected number of elements, * it is possible that the number inserted is less than the expected @@ -5471,22 +5403,6 @@ void mas_destroy(struct ma_state *mas) mas->mas_flags &= ~MA_STATE_REBALANCE; } mas->mas_flags &= ~(MA_STATE_BULK|MA_STATE_PREALLOC); - - total = mas_allocated(mas); - while (total) { - node = mas->alloc; - mas->alloc = node->slot[0]; - if (node->node_count > 1) { - size_t count = node->node_count - 1; - - mt_free_bulk(count, (void __rcu **)&node->slot[1]); - total -= count; - } - mt_free_one(ma_mnode_ptr(node)); - total--; - } - - mas->alloc = NULL; } EXPORT_SYMBOL_GPL(mas_destroy); @@ -6152,13 +6068,13 @@ bool mas_nomem(struct ma_state *mas, gfp_t gfp) if (gfpflags_allow_blocking(gfp) && !mt_external_lock(mas->tree)) { mtree_unlock(mas->tree); - mas_node_count_gfp(mas, mas_alloc_req(mas), gfp); + mas_node_count_gfp(mas, mas->requested, gfp); mtree_lock(mas->tree); } else { - mas_node_count_gfp(mas, mas_alloc_req(mas), gfp); + mas_node_count_gfp(mas, mas->requested, gfp); } - mas_set_alloc_req(mas, 0); + mas->requested = 0; if (mas_is_err(mas)) return false; @@ -7508,8 +7424,8 @@ void mas_dump(const struct ma_state *mas) pr_err("[%u/%u] index=%lx last=%lx\n", mas->offset, mas->end, mas->index, mas->last); - pr_err(" min=%lx max=%lx alloc=%p, depth=%u, flags=%x\n", - mas->min, mas->max, mas->alloc, mas->depth, mas->mas_flags); + pr_err(" min=%lx max=%lx alloc=%lu, depth=%u, flags=%x\n", + mas->min, mas->max, mas->requested, mas->depth, mas->mas_flags); if (mas->index > mas->last) pr_err("Check index & last\n"); }