From: Liam R. Howlett Date: Wed, 24 Nov 2021 16:41:17 +0000 (-0500) Subject: maple_tree: Remove _mas_safe_pivot() X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=cfe809bc2c527cc35574a4962179d27660356b51;p=users%2Fjedix%2Flinux-maple.git maple_tree: Remove _mas_safe_pivot() Signed-off-by: Liam R. Howlett --- diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 740ccbbb2a49..f349edc04ebf 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -621,7 +621,7 @@ static inline unsigned long mte_pivot(const struct maple_enode *mn, } /* - * _mas_safe_pivot() - get the pivot at @piv or mas->max. + * mas_safe_pivot() - get the pivot at @piv or mas->max. * @mas: The maple state * @pivots: The pointer to the maple node pivots * @piv: The pivot to fetch @@ -631,8 +631,8 @@ static inline unsigned long mte_pivot(const struct maple_enode *mn, * otherwise. */ static inline unsigned long -_mas_safe_pivot(const struct ma_state *mas, unsigned long *pivots, - unsigned char piv, enum maple_type type) +mas_safe_pivot(const struct ma_state *mas, unsigned long *pivots, + unsigned char piv, enum maple_type type) { if (piv >= mt_pivots[type]) return mas->max; @@ -640,22 +640,6 @@ _mas_safe_pivot(const struct ma_state *mas, unsigned long *pivots, return pivots[piv]; } -/* - * mas_safe_pivot() - Return pivot, implied or otherwise. - * @mas: The maple state - * @piv: the pivot location - * - * Return: The pivot (including mas->max for the final piv) - */ -static inline unsigned long -mas_safe_pivot(const struct ma_state *mas, unsigned char piv) -{ - enum maple_type type = mte_node_type(mas->node); - unsigned long *pivots = ma_pivots(mas_mn(mas), type); - - return _mas_safe_pivot(mas, pivots, piv, type); -} - /* * mas_safe_min() - Return the minimum for a given offset. * @mas: The maple state @@ -689,7 +673,7 @@ static inline unsigned long mas_logical_pivot(struct ma_state *mas, unsigned long *pivots, unsigned char offset, enum maple_type type) { - unsigned long lpiv = _mas_safe_pivot(mas, pivots, offset, type); + unsigned long lpiv = mas_safe_pivot(mas, pivots, offset, type); if (likely(lpiv)) return lpiv; @@ -983,7 +967,7 @@ static inline void mas_descend(struct ma_state *mas) if (mas->offset) mas->min = pivots[mas->offset - 1] + 1; - mas->max = _mas_safe_pivot(mas, pivots, mas->offset, type); + mas->max = mas_safe_pivot(mas, pivots, mas->offset, type); mas->node = mas_slot(mas, slots, mas->offset); } @@ -1856,7 +1840,7 @@ static inline void mas_mab_cp(struct ma_state *mas, unsigned char mas_start, } if (likely(i <= mas_end)) - b_node->pivot[j] = _mas_safe_pivot(mas, pivots, i, mt); + b_node->pivot[j] = mas_safe_pivot(mas, pivots, i, mt); complete: b_node->b_end = ++j; @@ -3090,12 +3074,12 @@ done: } /* - * _mas_split_final_node() - Split the final node in a subtree operation. + * mas_split_final_node() - Split the final node in a subtree operation. * @mast: the maple subtree state * @mas: The maple state * @height: The height of the tree in case it's a new root. */ -static inline bool _mas_split_final_node(struct maple_subtree_state *mast, +static inline bool mas_split_final_node(struct maple_subtree_state *mast, struct ma_state *mas, int height) { struct maple_enode *ancestor; @@ -3122,25 +3106,6 @@ static inline bool _mas_split_final_node(struct maple_subtree_state *mast, return true; } -/* - * mas_split_final_node() - Check if a subtree state can be contained within a - * single node and do so if possible. - * @mast: The maple subtree state - * @mas: The maple state - * @height: The height in case of a new root. - * - * Return: True if this was the final node and it has been handled, false - * otherwise. - */ -static inline bool mas_split_final_node(struct maple_subtree_state *mast, - struct ma_state *mas, int height) -{ - if (mt_slots[mast->bn->type] <= mast->bn->b_end) - return false; - - return _mas_split_final_node(mast, mas, height); -} - /* * mast_fill_bnode() - Copy data into the big node in the subtree state * @mast: The maple subtree state @@ -3290,7 +3255,7 @@ static inline bool mas_push_data(struct ma_state *mas, int height, mast_split_data(mast, mas, split); mast_fill_bnode(mast, mas, 2); - _mas_split_final_node(mast, mas, height + 1); + mas_split_final_node(mast, mas, height + 1); return true; } @@ -3328,8 +3293,10 @@ static int mas_split(struct ma_state *mas, struct maple_big_node *b_node) mast.bn = b_node; while (height++ <= mas->depth) { - if (mas_split_final_node(&mast, mas, height)) + if (mt_slots[b_node->type] > b_node->b_end) { + mas_split_final_node(&mast, mas, height); break; + } l_mas = r_mas = *mas; l_mas.node = mas_new_ma_node(mas, b_node); @@ -3645,7 +3612,8 @@ static inline void mas_extend_spanning_null(struct ma_wr_state *l_wr_mas, } else if ((r_mas->last == r_wr_mas->r_max) && (r_mas->last < r_mas->max) && !mas_slot_locked(r_mas, r_wr_mas->slots, r_mas->offset + 1)) { - r_mas->last = mas_safe_pivot(r_mas, r_mas->offset + 1); + r_mas->last = mas_safe_pivot(r_mas, r_wr_mas->pivots, + r_wr_mas->type, r_mas->offset + 1); r_mas->offset++; } } @@ -3894,7 +3862,8 @@ static inline bool mas_wr_node_store(struct ma_wr_state *wr_mas) new_end++; } else { - if (_mas_safe_pivot(mas, wr_mas->pivots, wr_mas->offset_end, wr_mas->type) == mas->last) + if (mas_safe_pivot(mas, wr_mas->pivots, wr_mas->offset_end, + wr_mas->type) == mas->last) wr_mas->offset_end++; new_end -= wr_mas->offset_end - offset - 1; @@ -4010,7 +3979,7 @@ static inline bool mas_node_store(struct ma_state *mas, void *entry, new_end++; } else { - if (_mas_safe_pivot(mas, pivots, offset_end, mt) == mas->last) + if (mas_safe_pivot(mas, pivots, offset_end, mt) == mas->last) offset_end++; new_end -= offset_end - offset - 1; @@ -4560,7 +4529,7 @@ static inline int mas_next_node(struct ma_state *mas, struct maple_node *node, mt = mte_node_type(mas->node); slots = ma_slots(node, mt); pivots = ma_pivots(node, mt); - pivot = _mas_safe_pivot(mas, pivots, ++offset, mt); + pivot = mas_safe_pivot(mas, pivots, ++offset, mt); while (unlikely(level > 1)) { /* Descend, if necessary */ enode = mas_slot(mas, slots, offset); @@ -4650,7 +4619,7 @@ static inline void *mas_next_nentry(struct ma_state *mas, return NULL; } - pivot = _mas_safe_pivot(mas, pivots, mas->offset, type); + pivot = mas_safe_pivot(mas, pivots, mas->offset, type); entry = mas_slot(mas, slots, mas->offset); if (ma_dead_node(node)) return NULL; @@ -4925,7 +4894,7 @@ static bool _mas_rev_awalk(struct ma_state *mas, unsigned long size) while (mas->last < min) min = mas_safe_min(mas, pivots, --offset); - max = _mas_safe_pivot(mas, pivots, offset, type); + max = mas_safe_pivot(mas, pivots, offset, type); index = mas->index; while (index <= max) { gap = 0; @@ -5005,7 +4974,7 @@ static inline bool _mas_awalk(struct ma_state *mas, unsigned long size) count = mt_slots[type]; min = mas_safe_min(mas, pivots, offset); for (; offset < count; offset++) { - pivot = _mas_safe_pivot(mas, pivots, offset, type); + pivot = mas_safe_pivot(mas, pivots, offset, type); if (offset && !pivot) break; @@ -5187,7 +5156,7 @@ static inline void mas_fill_gap(struct ma_state *mas, void *entry, mas_ascend(mas); ptype = mte_node_type(mas->node); pivots = ma_pivots(mas_mn(mas), ptype); - mas->max = _mas_safe_pivot(mas, pivots, pslot, ptype); + mas->max = mas_safe_pivot(mas, pivots, pslot, ptype); mas->min = mas_safe_min(mas, pivots, pslot); mas->node = mn; mas->offset = slot; @@ -6828,7 +6797,10 @@ void mas_validate_limits(struct ma_state *mas) return; for (i = 0; i < mt_slot_count(mas->node); i++) { - unsigned long piv = mas_safe_pivot(mas, i); + enum maple_type type = mte_node_type(mas->node); + unsigned long *pivots = ma_pivots(mas_mn(mas), type); + unsigned long piv = mas_safe_pivot(mas, pivots, type, i); + if (!piv) break;