From 9b0868b9ac21a45426b18fe03a9d384b2f65de89 Mon Sep 17 00:00:00 2001 From: "Liam R. Howlett" Date: Tue, 8 Sep 2020 11:51:36 -0400 Subject: [PATCH] maple_tree: Renames to remove _get and comments on some functions Signed-off-by: Liam R. Howlett --- lib/maple_tree.c | 109 ++++++++++++++++++++++++++++++++---------- lib/test_maple_tree.c | 34 ++++++------- 2 files changed, 101 insertions(+), 42 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index df99b9a47b4c..335e48e45a44 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -289,20 +289,20 @@ static inline enum maple_type mas_parent_enum(struct ma_state *mas, /* * mte_set_parent() - Set the parent node and encode the slot. - * @node: The encoded maple node. - * @parent: The encoded maple node that is the parent of @node. - * @slot: The slot that @node resides in @parent. + * @enode: The encoded maple node. + * @parent: The encoded maple node that is the parent of @enode. + * @slot: The slot that @enode resides in @parent. * - * Type is encoded in the node->parent + * Type is encoded in the enode->parent * bit 0: 1 = root, 0 otherwise * bit 1: Reserved. * bit 2: 0 = range 32, 1 = [a]range 64 | lowest bit of range_16's slot. * - * Slot number is encoded in the node->parent + * Slot number is encoded in the enode->parent * range_32, slot number is encoded in bits 3-6 * [a]range_64, slot number is encoded in bits 3-6 */ -static inline void mte_set_parent(struct maple_enode *node, +static inline void mte_set_parent(struct maple_enode *enode, const struct maple_enode *parent, unsigned char slot) { @@ -324,13 +324,19 @@ static inline void mte_set_parent(struct maple_enode *node, val &= ~bitmask; // Remove any old slot number. val |= (slot << slot_shift); // Set the slot. val |= type; - mte_to_node(node)->parent = ma_parent_ptr(val); + mte_to_node(enode)->parent = ma_parent_ptr(val); } -static inline unsigned int mte_parent_slot(const struct maple_enode *node) +/* + * mte_parent_slot() - get the parent slot of @enode. + * @enode: The encoded maple node. + * + * Returns: The slot in the parent node where @enode resides. + */ +static inline unsigned int mte_parent_slot(const struct maple_enode *enode) { unsigned long bitmask = 0x7C; - unsigned long val = (unsigned long) mte_to_node(node)->parent; + unsigned long val = (unsigned long) mte_to_node(enode)->parent; unsigned long slot_shift = mte_parent_shift(val); if (val & 1) @@ -339,14 +345,23 @@ static inline unsigned int mte_parent_slot(const struct maple_enode *node) return (val & bitmask) >> slot_shift; } - -static inline struct maple_node *mte_parent(const struct maple_enode *node) +/* + * mte_parent() - Get the parent of @node. + * @node: The encoded maple node. + * + * Returns: The parent maple node. + */ +static inline struct maple_node *mte_parent(const struct maple_enode *enode) { unsigned long bitmask = 0x7F; - return (void *)((unsigned long)(mte_to_node(node)->parent) & ~bitmask); + return (void *)((unsigned long)(mte_to_node(enode)->parent) & ~bitmask); } +/* + * mte_dead_node() - check if the @enode is dead. + * Returns: true if dead, false otherwise. + */ static inline bool mte_dead_node(const struct maple_enode *enode) { struct maple_node *parent, *node = mte_to_node(enode); @@ -355,11 +370,31 @@ static inline bool mte_dead_node(const struct maple_enode *enode) return (parent == node); } -static inline struct maple_node *mas_get_alloc(const struct ma_state *ms) +/* + * mas_get_alloc() - Get the first allocated node. + * @mas: The maple state. + * + * The first allocated node may be used for accounting of many other nodes. + * Please see mas_alloc_cnt() and mas_next_alloc() for complete use. + * + * Returns: The first allocated node. + * + */ +static inline struct maple_node *mas_get_alloc(const struct ma_state *mas) { - return (struct maple_node *)((unsigned long)ms->alloc & ~0x7F); + return (struct maple_node *)((unsigned long)mas->alloc & ~0x7F); } +/* + * ma_get_node_alloc_cnt() - Get the number of allocations stored in this node. + * @node: The maple node + * + * Used to calculate the total allocated nodes in a maple state. See + * mas_alloc_cnt(). + * + * Returns: The count of the allocated nodes stored in this nodes slots. + * + */ static inline int ma_get_node_alloc_cnt(const struct maple_node *node) { int ret = 1; @@ -380,7 +415,16 @@ static inline int ma_get_node_alloc_cnt(const struct maple_node *node) return ret; } -static inline int mas_get_alloc_cnt(const struct ma_state *mas) +/* + * mas_alloc_cnt() - Get the number of nodes allocated in a maple state. + * @mas: The maple state + * + * Walks through the allocated nodes and returns the number allocated. + * + * Returns: The total number of nodes allocated + * + */ +static inline int mas_alloc_cnt(const struct ma_state *mas) { struct maple_node *node = mas_get_alloc(mas); @@ -390,20 +434,35 @@ static inline int mas_get_alloc_cnt(const struct ma_state *mas) return ma_get_node_alloc_cnt(node); } +/* + * mas_set_alloc_req() - Set the requested number of allocations. + * @mas - the maple state + * @count - the number of allocations. + */ static inline void mas_set_alloc_req(struct ma_state *mas, int count) { mas->alloc = (struct maple_node *)((unsigned long)mas->alloc & ~0x7F); mas->alloc = (struct maple_node *)((unsigned long)mas->alloc | count); } -static inline int mas_get_alloc_req(const struct ma_state *mas) +/* + * mas_alloc_req() - get the requested number of allocations. + * Returns: The allocation request count. + */ +static inline int mas_alloc_req(const struct ma_state *mas) { return (int)(((unsigned long)mas->alloc & 0x7F)); } +/* + * mas_offset() - get the offset into a given node (slot/pivot number) + * @mas: The maple state + * + * Returns: The offset into the @mas node of interest. + */ static inline int mas_offset(const struct ma_state *mas) { - return mas_get_alloc_req(mas); + return mas_alloc_req(mas); } static inline void mas_set_offset(struct ma_state *mas, int slot) @@ -761,7 +820,7 @@ static inline struct maple_node *mas_next_alloc(struct ma_state *ms) if (!ms->alloc) return NULL; - cnt = mas_get_alloc_cnt(ms); + cnt = mas_alloc_cnt(ms); mn = mas_get_alloc(ms); if (cnt == 1) { ms->alloc = NULL; @@ -787,7 +846,7 @@ static inline void mas_push_node(struct ma_state *mas, struct maple_enode *used) int cnt; memset(reuse, 0, sizeof(*reuse)); - cnt = mas_get_alloc_cnt(mas); + cnt = mas_alloc_cnt(mas); if (cnt == 0) { mas->alloc = reuse; } else if (cnt <= MAPLE_NODE_SLOTS) { @@ -800,16 +859,16 @@ static inline void mas_push_node(struct ma_state *mas, struct maple_enode *used) smn = node->slot[(cnt/MAPLE_NODE_SLOTS) - 1]; smn->slot[cnt % MAPLE_NODE_SLOTS] = reuse; } - cnt = mas_get_alloc_cnt(mas); + cnt = mas_alloc_cnt(mas); - BUG_ON(!mas_get_alloc_cnt(mas)); + BUG_ON(!mas_alloc_cnt(mas)); } static inline void mas_node_node(struct ma_state *ms, gfp_t gfp) { struct maple_node *mn, *smn; - int req = mas_get_alloc_req(ms); - int allocated = mas_get_alloc_cnt(ms); + int req = mas_alloc_req(ms); + int allocated = mas_alloc_cnt(ms); int slot; if (!req) @@ -893,7 +952,7 @@ bool mas_nomem(struct ma_state *mas, gfp_t gfp) static inline struct maple_node *mas_node_cnt(struct ma_state *mas, int count) { - int allocated = mas_get_alloc_cnt(mas); + int allocated = mas_alloc_cnt(mas); BUG_ON(count > 127); if (allocated < count) { @@ -4309,7 +4368,7 @@ static inline void mas_dup_children(struct ma_state *mas, int *node_cnt) struct maple_node *child; struct maple_enode *oldchild, *echild; unsigned char slot, end = mt_slot_count(mas->node); - int allocated = mas_get_alloc_cnt(mas); + int allocated = mas_alloc_cnt(mas); if (allocated < end) { mas->span_enode = mas->node; diff --git a/lib/test_maple_tree.c b/lib/test_maple_tree.c index 55bc8e567f12..87b42c4c29f9 100644 --- a/lib/test_maple_tree.c +++ b/lib/test_maple_tree.c @@ -202,12 +202,12 @@ static noinline void check_new_node(struct maple_tree *mt) // request 3 nodes to be allocated. mas_node_cnt(&mas, 3); // Allocation request of 3. - MT_BUG_ON(mt, mas_get_alloc_req(&mas) != 3); + MT_BUG_ON(mt, mas_alloc_req(&mas) != 3); // Allocate failed. MT_BUG_ON(mt, mas.node != MA_ERROR(-ENOMEM)); MT_BUG_ON(mt, !mas_nomem(&mas, GFP_KERNEL)); - MT_BUG_ON(mt, mas_get_alloc_cnt(&mas) != 3); + MT_BUG_ON(mt, mas_alloc_cnt(&mas) != 3); mn = mas_get_alloc(&mas); MT_BUG_ON(mt, mn == NULL); MT_BUG_ON(mt, mn->slot[0] == NULL); @@ -221,7 +221,7 @@ static noinline void check_new_node(struct maple_tree *mt) // Set allocation request to 1. mas_set_alloc_req(&mas, 1); // Check Allocation request of 1. - MT_BUG_ON(mt, mas_get_alloc_req(&mas) != 1); + MT_BUG_ON(mt, mas_alloc_req(&mas) != 1); mas_set_err(&mas, -ENOMEM); // Validate allocation request. MT_BUG_ON(mt, !mas_nomem(&mas, GFP_KERNEL)); @@ -231,7 +231,7 @@ static noinline void check_new_node(struct maple_tree *mt) MT_BUG_ON(mt, mn == NULL); MT_BUG_ON(mt, mn->slot[0] != NULL); MT_BUG_ON(mt, mn->slot[1] != NULL); - MT_BUG_ON(mt, mas_get_alloc_cnt(&mas) != 0); + MT_BUG_ON(mt, mas_alloc_cnt(&mas) != 0); ma_free_rcu(mn); mas.node = MAS_START; @@ -241,16 +241,16 @@ static noinline void check_new_node(struct maple_tree *mt) // Drop the lock and allocate 3 nodes. mas_nomem(&mas, GFP_KERNEL); // Ensure 3 are allocated. - MT_BUG_ON(mt, mas_get_alloc_cnt(&mas) != 3); + MT_BUG_ON(mt, mas_alloc_cnt(&mas) != 3); // Allocation request of 0. - MT_BUG_ON(mt, mas_get_alloc_req(&mas) != 0); + MT_BUG_ON(mt, mas_alloc_req(&mas) != 0); mn = mas.alloc; MT_BUG_ON(mt, mn == NULL); MT_BUG_ON(mt, mn->slot[0] == NULL); MT_BUG_ON(mt, mn->slot[1] == NULL); // Ensure we counted 3. - MT_BUG_ON(mt, mas_get_alloc_cnt(&mas) != 3); + MT_BUG_ON(mt, mas_alloc_cnt(&mas) != 3); // Free. mas_nomem(&mas, GFP_KERNEL); @@ -274,43 +274,43 @@ static noinline void check_new_node(struct maple_tree *mt) j++; } } - MT_BUG_ON(mt, mas_get_alloc_cnt(&mas) != 127); + MT_BUG_ON(mt, mas_alloc_cnt(&mas) != 127); mas_nomem(&mas, GFP_KERNEL); // Free. - MT_BUG_ON(mt, mas_get_alloc_cnt(&mas) != 0); + MT_BUG_ON(mt, mas_alloc_cnt(&mas) != 0); for (i = 1; i < 128; i++) { mas_node_cnt(&mas, i); // Request mas_nomem(&mas, GFP_KERNEL); // Fill request - MT_BUG_ON(mt, mas_get_alloc_cnt(&mas) != i); // check request filled + MT_BUG_ON(mt, mas_alloc_cnt(&mas) != i); // check request filled for (j = i; j > 0; j--) { //Free the requests mn = mas_next_alloc(&mas); // get the next node. MT_BUG_ON(mt, mn == NULL); ma_free_rcu(mn); } - MT_BUG_ON(mt, mas_get_alloc_cnt(&mas) != 0); + MT_BUG_ON(mt, mas_alloc_cnt(&mas) != 0); } for (i = 1; i < 128; i++) { MA_STATE(mas2, mt, 0, 0); mas_node_cnt(&mas, i); // Request mas_nomem(&mas, GFP_KERNEL); // Fill request - MT_BUG_ON(mt, mas_get_alloc_cnt(&mas) != i); // check request filled + MT_BUG_ON(mt, mas_alloc_cnt(&mas) != i); // check request filled for (j = 1; j <= i; j++) { // Move the allocations to mas2 mn = mas_next_alloc(&mas); // get the next node. MT_BUG_ON(mt, mn == NULL); mas_push_node(&mas2, (struct maple_enode *)mn); - MT_BUG_ON(mt, mas_get_alloc_cnt(&mas2) != j); + MT_BUG_ON(mt, mas_alloc_cnt(&mas2) != j); } - MT_BUG_ON(mt, mas_get_alloc_cnt(&mas) != 0); - MT_BUG_ON(mt, mas_get_alloc_cnt(&mas2) != i); + MT_BUG_ON(mt, mas_alloc_cnt(&mas) != 0); + MT_BUG_ON(mt, mas_alloc_cnt(&mas2) != i); for (j = i; j > 0; j--) { //Free the requests - MT_BUG_ON(mt, mas_get_alloc_cnt(&mas2) != j); + MT_BUG_ON(mt, mas_alloc_cnt(&mas2) != j); mn = mas_next_alloc(&mas2); // get the next node. MT_BUG_ON(mt, mn == NULL); ma_free_rcu(mn); } - MT_BUG_ON(mt, mas_get_alloc_cnt(&mas2) != 0); + MT_BUG_ON(mt, mas_alloc_cnt(&mas2) != 0); } mtree_unlock(mt); -- 2.50.1