From: Liam R. Howlett <Liam.Howlett@oracle.com>
Date: Tue, 6 May 2025 15:48:41 +0000 (-0400)
Subject: move mas_wr_rebalance_calc()
X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=df758a7f681582d1a15b801f6247ec8603eee1fc;p=users%2Fjedix%2Flinux-maple.git

move mas_wr_rebalance_calc()

Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
---

diff --git a/lib/maple_tree.c b/lib/maple_tree.c
index 8aa08127aa64..c0d3f3254ccf 100644
--- a/lib/maple_tree.c
+++ b/lib/maple_tree.c
@@ -3502,38 +3502,6 @@ static __always_inline unsigned char mas_wr_new_end(struct ma_wr_state *wr_mas)
 	return new_end;
 }
 
-/*
- * mas_wr_rebalance_calc() - Try to calculate a rebalance that will work
- * @data_size: The total data to be written
- * @mt: The maple node types splitting the data
- *
- * Returns: 0 on failure, the split location otherwise.
- */
-static inline
-unsigned char mas_wr_rebalance_calc(unsigned char data_size,
-		enum maple_type mt)
-{
-	unsigned char space, split;
-	unsigned char node_size, node_min;
-
-	node_min = mt_min_slots[mt];
-	node_size = mt_slots[mt];
-
-	space = node_size * 2 - 2;
-	/* Greedy rebalance */
-	if (space <= data_size)
-		return 0;
-
-	split = node_size - 2;
-	if (data_size - split >= node_size)
-		return 0;
-
-	if (data_size - split <= node_min)
-		split = (data_size + 2) / 2;
-
-	return split;
-}
-
 static inline
 void mas_wr_ascend_init(struct ma_state *mas, struct ma_node_info *ni)
 {
@@ -3791,6 +3759,37 @@ static void mt_wr_split_data(struct ma_node_info *src,
 	} while (src->offset <= src->end);
 }
 
+/*
+ * mas_wr_rebalance_calc() - Try to calculate a rebalance that will work
+ * @data_size: The total data to be written
+ * @mt: The maple node types splitting the data
+ *
+ * Returns: 0 on failure, the split location otherwise.
+ */
+static inline
+unsigned char mas_wr_rebalance_calc(unsigned char data_size,
+		enum maple_type mt)
+{
+	unsigned char space, split;
+	unsigned char node_size, node_min;
+
+	node_min = mt_min_slots[mt];
+	node_size = mt_slots[mt];
+
+	space = node_size * 2 - 2;
+	/* Greedy rebalance */
+	if (space <= data_size)
+		return 0;
+
+	split = node_size - 2;
+	if (data_size - split >= node_size)
+		return 0;
+
+	if (data_size - split <= node_min)
+		split = (data_size + 2) / 2;
+
+	return split;
+}
 
 static inline
 bool can_rebalance_right(struct ma_state *tmp_mas, struct ma_node_info *parent,