From: Liam R. Howlett Date: Fri, 9 Oct 2020 19:00:28 +0000 (-0400) Subject: mas_entry_cnt() rename and cleanup X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=cee441d88ec92b9735cb62050b08569a0820fa79;p=users%2Fjedix%2Flinux-maple.git mas_entry_cnt() rename and cleanup Signed-off-by: Liam R. Howlett --- diff --git a/include/linux/maple_tree.h b/include/linux/maple_tree.h index 0810c7427cb4..eecf046cab05 100644 --- a/include/linux/maple_tree.h +++ b/include/linux/maple_tree.h @@ -395,7 +395,7 @@ static inline void mt_set_in_rcu(struct maple_tree *mt) mtree_unlock(mt); } -int mas_entry_cnt(struct ma_state *mas, unsigned long nr_leaves); +int mas_entry_count(struct ma_state *mas, unsigned long nr_leaves); void *mt_find(struct maple_tree *mt, unsigned long *index, unsigned long max); void *_mt_find(struct maple_tree *mt, unsigned long *index, unsigned long max, diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 9a20236d346d..25fe27927fa3 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -18,6 +18,8 @@ #include #define MA_ROOT_PARENT 1 +#define MAPLE_NODE_MAX MAPLE_NODE_MASK + #define ma_parent_ptr(x) ((struct maple_pnode *)(x)) #define ma_mnode_ptr(x) ((struct maple_node *)(x)) #define ma_enode_ptr(x) ((struct maple_enode *)(x)) @@ -993,15 +995,16 @@ static inline struct maple_node *mas_node_cnt(struct ma_state *mas, int count) return mas->alloc; } -int mas_entry_cnt(struct ma_state *mas, unsigned long nr_entries) { +int mas_entry_count(struct ma_state *mas, unsigned long nr_entries) { int nonleaf_cap = MAPLE_ARANGE64_SLOTS - 1; - int nr_leaves; + int nr_nodes; if (!mt_is_alloc(mas->tree)) nonleaf_cap = MAPLE_RANGE64_SLOTS - 1; - nr_leaves = DIV_ROUND_UP(nr_entries, MAPLE_RANGE64_SLOTS); - mas_node_cnt(mas, nr_leaves + DIV_ROUND_UP(nr_leaves, nonleaf_cap)); + nr_nodes = DIV_ROUND_UP(nr_entries, MAPLE_RANGE64_SLOTS); // leaves + nr_nodes += DIV_ROUND_UP(nr_nodes, nonleaf_cap); + mas_node_cnt(mas, min(nr_nodes, (int)MAPLE_NODE_MAX)); if (!mas_is_err(mas)) return 0; return xa_err(mas->node);