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: inline mas_spanning_rebalance_loop() into mas_wr_spanning_rebalance()

Just copy the code and replace count with height. This is done to avoid
affecting other code paths into mas_spanning_rebalance_loop() for the next
change.

No functional change intended.

Link: https://lkml.kernel.org/r/20260130205935.2559335-14-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
f141d566 b14ffd2c

+107 -1
+107 -1
lib/maple_tree.c
··· 2862 2862 static noinline void mas_wr_spanning_rebalance(struct ma_state *mas, 2863 2863 struct ma_wr_state *l_wr_mas, struct ma_wr_state *r_wr_mas) 2864 2864 { 2865 + 2866 + unsigned char split, mid_split; 2867 + unsigned char slot = 0; 2868 + unsigned char new_height = 0; /* used if node is a new root */ 2869 + struct maple_enode *left = NULL, *middle = NULL, *right = NULL; 2870 + struct maple_enode *old_enode; 2871 + 2865 2872 struct maple_subtree_state mast; 2866 2873 struct maple_big_node b_node; 2867 2874 struct maple_copy cp; ··· 2924 2917 mast_spanning_rebalance(&mast); 2925 2918 2926 2919 height = mas_mt_height(mas) + 1; 2927 - mas_spanning_rebalance_loop(mas, &mast, height); 2920 + 2921 + /* 2922 + * Each level of the tree is examined and balanced, pushing data to the left or 2923 + * right, or rebalancing against left or right nodes is employed to avoid 2924 + * rippling up the tree to limit the amount of churn. Once a new sub-section of 2925 + * the tree is created, there may be a mix of new and old nodes. The old nodes 2926 + * will have the incorrect parent pointers and currently be in two trees: the 2927 + * original tree and the partially new tree. To remedy the parent pointers in 2928 + * the old tree, the new data is swapped into the active tree and a walk down 2929 + * the tree is performed and the parent pointers are updated. 2930 + * See mas_topiary_replace() for more information. 2931 + */ 2932 + while (height--) { 2933 + mast.bn->b_end--; 2934 + mast.bn->type = mte_node_type(mast.orig_l->node); 2935 + split = mas_mab_to_node(mas, mast.bn, &left, &right, &middle, 2936 + &mid_split); 2937 + mast_set_split_parents(&mast, left, middle, right, split, 2938 + mid_split); 2939 + mast_cp_to_nodes(&mast, left, middle, right, split, mid_split); 2940 + new_height++; 2941 + 2942 + /* 2943 + * Copy data from next level in the tree to mast.bn from next 2944 + * iteration 2945 + */ 2946 + memset(mast.bn, 0, sizeof(struct maple_big_node)); 2947 + mast.bn->type = mte_node_type(left); 2948 + 2949 + /* Root already stored in l->node. */ 2950 + if (mas_is_root_limits(mast.l)) 2951 + goto new_root; 2952 + 2953 + mast_ascend(&mast); 2954 + mast_combine_cp_left(&mast); 2955 + mast.l->offset = mast.bn->b_end; 2956 + mab_set_b_end(mast.bn, mast.l, left); 2957 + mab_set_b_end(mast.bn, mast.m, middle); 2958 + mab_set_b_end(mast.bn, mast.r, right); 2959 + 2960 + /* Copy anything necessary out of the right node. */ 2961 + mast_combine_cp_right(&mast); 2962 + mast.orig_l->last = mast.orig_l->max; 2963 + 2964 + if (mast_sufficient(&mast)) { 2965 + if (mast_overflow(&mast)) 2966 + continue; 2967 + 2968 + if (mast.orig_l->node == mast.orig_r->node) { 2969 + /* 2970 + * The data in b_node should be stored in one 2971 + * node and in the tree 2972 + */ 2973 + slot = mast.l->offset; 2974 + break; 2975 + } 2976 + 2977 + continue; 2978 + } 2979 + 2980 + /* May be a new root stored in mast.bn */ 2981 + if (mas_is_root_limits(mast.orig_l)) 2982 + break; 2983 + 2984 + mast_spanning_rebalance(&mast); 2985 + 2986 + /* rebalancing from other nodes may require another loop. */ 2987 + if (!height) 2988 + height++; 2989 + } 2990 + 2991 + mast.l->node = mt_mk_node(ma_mnode_ptr(mas_pop_node(mas)), 2992 + mte_node_type(mast.orig_l->node)); 2993 + 2994 + mab_mas_cp(mast.bn, 0, mt_slots[mast.bn->type] - 1, mast.l, true); 2995 + new_height++; 2996 + mas_set_parent(mas, left, mast.l->node, slot); 2997 + if (middle) 2998 + mas_set_parent(mas, middle, mast.l->node, ++slot); 2999 + 3000 + if (right) 3001 + mas_set_parent(mas, right, mast.l->node, ++slot); 3002 + 3003 + if (mas_is_root_limits(mast.l)) { 3004 + new_root: 3005 + mas_mn(mast.l)->parent = ma_parent_ptr(mas_tree_parent(mas)); 3006 + while (!mte_is_root(mast.orig_l->node)) 3007 + mast_ascend(&mast); 3008 + } else { 3009 + mas_mn(mast.l)->parent = mas_mn(mast.orig_l)->parent; 3010 + } 3011 + 3012 + old_enode = mast.orig_l->node; 3013 + mas->depth = mast.l->depth; 3014 + mas->node = mast.l->node; 3015 + mas->min = mast.l->min; 3016 + mas->max = mast.l->max; 3017 + mas->offset = mast.l->offset; 3018 + mas_wmb_replace(mas, old_enode, new_height); 3019 + mtree_range_walk(mas); 2928 3020 } 2929 3021 /* 2930 3022 * mas_rebalance() - Rebalance a given node.