Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

maple_tree: move mas_spanning_rebalance loop to function

Move the loop over the tree levels to its own function.

No intended functional changes.

Link: https://lkml.kernel.org/r/20260130205935.2559335-3-Liam.Howlett@oracle.com
Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
Cc: Alice Ryhl <aliceryhl@google.com>
Cc: Andrew Ballance <andrewjballance@gmail.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Christian Kujau <lists@nerdbynature.de>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: SeongJae Park <sj@kernel.org>
Cc: Sidhartha Kumar <sidhartha.kumar@oracle.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Liam R. Howlett and committed by
Andrew Morton
3e302560 68848324

+58 -50
+58 -50
lib/maple_tree.c
··· 2595 2595 return NULL; 2596 2596 } 2597 2597 2598 - /* 2599 - * mas_spanning_rebalance() - Rebalance across two nodes which may not be peers. 2600 - * @mas: The starting maple state 2601 - * @mast: The maple_subtree_state, keeps track of 4 maple states. 2602 - * @count: The estimated count of iterations needed. 2603 - * 2604 - * Follow the tree upwards from @l_mas and @r_mas for @count, or until the root 2605 - * is hit. First @b_node is split into two entries which are inserted into the 2606 - * next iteration of the loop. @b_node is returned populated with the final 2607 - * iteration. @mas is used to obtain allocations. orig_l_mas keeps track of the 2608 - * nodes that will remain active by using orig_l_mas->index and orig_l_mas->last 2609 - * to account of what has been copied into the new sub-tree. The update of 2610 - * orig_l_mas->last is used in mas_consume to find the slots that will need to 2611 - * be either freed or destroyed. orig_l_mas->depth keeps track of the height of 2612 - * the new sub-tree in case the sub-tree becomes the full tree. 2613 - */ 2614 - static void mas_spanning_rebalance(struct ma_state *mas, 2598 + static void mas_spanning_rebalance_loop(struct ma_state *mas, 2615 2599 struct maple_subtree_state *mast, unsigned char count) 2616 2600 { 2601 + 2617 2602 unsigned char split, mid_split; 2618 2603 unsigned char slot = 0; 2619 2604 unsigned char new_height = 0; /* used if node is a new root */ 2620 2605 struct maple_enode *left = NULL, *middle = NULL, *right = NULL; 2621 2606 struct maple_enode *old_enode; 2622 - 2623 - MA_STATE(l_mas, mas->tree, mas->index, mas->index); 2624 - MA_STATE(r_mas, mas->tree, mas->index, mas->last); 2625 - MA_STATE(m_mas, mas->tree, mas->index, mas->index); 2626 - 2627 - /* 2628 - * The tree needs to be rebalanced and leaves need to be kept at the same level. 2629 - * Rebalancing is done by use of the ``struct maple_topiary``. 2630 - */ 2631 - mast->l = &l_mas; 2632 - mast->m = &m_mas; 2633 - mast->r = &r_mas; 2634 - l_mas.status = r_mas.status = m_mas.status = ma_none; 2635 - 2636 - /* Check if this is not root and has sufficient data. */ 2637 - if (((mast->orig_l->min != 0) || (mast->orig_r->max != ULONG_MAX)) && 2638 - unlikely(mast->bn->b_end <= mt_min_slots[mast->bn->type])) 2639 - mast_spanning_rebalance(mast); 2640 2607 2641 2608 /* 2642 2609 * Each level of the tree is examined and balanced, pushing data to the left or ··· 2639 2672 2640 2673 mast_ascend(mast); 2641 2674 mast_combine_cp_left(mast); 2642 - l_mas.offset = mast->bn->b_end; 2643 - mab_set_b_end(mast->bn, &l_mas, left); 2644 - mab_set_b_end(mast->bn, &m_mas, middle); 2645 - mab_set_b_end(mast->bn, &r_mas, right); 2675 + mast->l->offset = mast->bn->b_end; 2676 + mab_set_b_end(mast->bn, mast->l, left); 2677 + mab_set_b_end(mast->bn, mast->m, middle); 2678 + mab_set_b_end(mast->bn, mast->r, right); 2646 2679 2647 2680 /* Copy anything necessary out of the right node. */ 2648 2681 mast_combine_cp_right(mast); ··· 2675 2708 count++; 2676 2709 } 2677 2710 2678 - l_mas.node = mt_mk_node(ma_mnode_ptr(mas_pop_node(mas)), 2711 + mast->l->node = mt_mk_node(ma_mnode_ptr(mas_pop_node(mas)), 2679 2712 mte_node_type(mast->orig_l->node)); 2680 2713 2681 - mab_mas_cp(mast->bn, 0, mt_slots[mast->bn->type] - 1, &l_mas, true); 2714 + mab_mas_cp(mast->bn, 0, mt_slots[mast->bn->type] - 1, mast->l, true); 2682 2715 new_height++; 2683 - mas_set_parent(mas, left, l_mas.node, slot); 2716 + mas_set_parent(mas, left, mast->l->node, slot); 2684 2717 if (middle) 2685 - mas_set_parent(mas, middle, l_mas.node, ++slot); 2718 + mas_set_parent(mas, middle, mast->l->node, ++slot); 2686 2719 2687 2720 if (right) 2688 - mas_set_parent(mas, right, l_mas.node, ++slot); 2721 + mas_set_parent(mas, right, mast->l->node, ++slot); 2689 2722 2690 2723 if (mas_is_root_limits(mast->l)) { 2691 2724 new_root: ··· 2693 2726 while (!mte_is_root(mast->orig_l->node)) 2694 2727 mast_ascend(mast); 2695 2728 } else { 2696 - mas_mn(&l_mas)->parent = mas_mn(mast->orig_l)->parent; 2729 + mas_mn(mast->l)->parent = mas_mn(mast->orig_l)->parent; 2697 2730 } 2698 2731 2699 2732 old_enode = mast->orig_l->node; 2700 - mas->depth = l_mas.depth; 2701 - mas->node = l_mas.node; 2702 - mas->min = l_mas.min; 2703 - mas->max = l_mas.max; 2704 - mas->offset = l_mas.offset; 2733 + mas->depth = mast->l->depth; 2734 + mas->node = mast->l->node; 2735 + mas->min = mast->l->min; 2736 + mas->max = mast->l->max; 2737 + mas->offset = mast->l->offset; 2705 2738 mas_wmb_replace(mas, old_enode, new_height); 2706 2739 mtree_range_walk(mas); 2707 2740 return; 2741 + } 2742 + 2743 + /* 2744 + * mas_spanning_rebalance() - Rebalance across two nodes which may not be peers. 2745 + * @mas: The starting maple state 2746 + * @mast: The maple_subtree_state, keeps track of 4 maple states. 2747 + * @count: The estimated count of iterations needed. 2748 + * 2749 + * Follow the tree upwards from @l_mas and @r_mas for @count, or until the root 2750 + * is hit. First @b_node is split into two entries which are inserted into the 2751 + * next iteration of the loop. @b_node is returned populated with the final 2752 + * iteration. @mas is used to obtain allocations. orig_l_mas keeps track of the 2753 + * nodes that will remain active by using orig_l_mas->index and orig_l_mas->last 2754 + * to account of what has been copied into the new sub-tree. The update of 2755 + * orig_l_mas->last is used in mas_consume to find the slots that will need to 2756 + * be either freed or destroyed. orig_l_mas->depth keeps track of the height of 2757 + * the new sub-tree in case the sub-tree becomes the full tree. 2758 + */ 2759 + static void mas_spanning_rebalance(struct ma_state *mas, 2760 + struct maple_subtree_state *mast, unsigned char count) 2761 + { 2762 + 2763 + MA_STATE(l_mas, mas->tree, mas->index, mas->index); 2764 + MA_STATE(r_mas, mas->tree, mas->index, mas->last); 2765 + MA_STATE(m_mas, mas->tree, mas->index, mas->index); 2766 + 2767 + /* 2768 + * The tree needs to be rebalanced and leaves need to be kept at the same level. 2769 + * Rebalancing is done by use of the ``struct maple_topiary``. 2770 + */ 2771 + mast->l = &l_mas; 2772 + mast->m = &m_mas; 2773 + mast->r = &r_mas; 2774 + l_mas.status = r_mas.status = m_mas.status = ma_none; 2775 + 2776 + /* Check if this is not root and has sufficient data. */ 2777 + if (((mast->orig_l->min != 0) || (mast->orig_r->max != ULONG_MAX)) && 2778 + unlikely(mast->bn->b_end <= mt_min_slots[mast->bn->type])) 2779 + mast_spanning_rebalance(mast); 2780 + 2781 + mas_spanning_rebalance_loop(mas, mast, count); 2708 2782 } 2709 2783 2710 2784 /*