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: introduce ma_leaf_max_gap()

This is the same as mas_leaf_max_gap(), but the information necessary is
known without a maple state in future code. Adding this function now
simplifies the review for a subsequent patch.

Link: https://lkml.kernel.org/r/20260130205935.2559335-16-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
de7f3ed3 6953038c

+28 -20
+28 -20
lib/maple_tree.c
··· 1315 1315 wr_mas->r_max = mas_safe_pivot(mas, wr_mas->pivots, mas->offset, 1316 1316 wr_mas->type); 1317 1317 } 1318 - 1319 - /* 1320 - * mas_leaf_max_gap() - Returns the largest gap in a leaf node 1321 - * @mas: the maple state 1322 - * 1323 - * Return: The maximum gap in the leaf. 1324 - */ 1325 - static unsigned long mas_leaf_max_gap(struct ma_state *mas) 1318 + static inline unsigned long ma_leaf_max_gap(struct maple_node *mn, 1319 + enum maple_type mt, unsigned long min, unsigned long max, 1320 + unsigned long *pivots, void __rcu **slots) 1326 1321 { 1327 - enum maple_type mt; 1328 1322 unsigned long pstart, gap, max_gap; 1329 - struct maple_node *mn; 1330 - unsigned long *pivots; 1331 - void __rcu **slots; 1332 1323 unsigned char i; 1333 1324 unsigned char max_piv; 1334 1325 1335 - mt = mte_node_type(mas->node); 1336 - mn = mas_mn(mas); 1337 - slots = ma_slots(mn, mt); 1338 1326 max_gap = 0; 1339 1327 if (unlikely(ma_is_dense(mt))) { 1340 1328 gap = 0; ··· 1344 1356 * Check the first implied pivot optimizes the loop below and slot 1 may 1345 1357 * be skipped if there is a gap in slot 0. 1346 1358 */ 1347 - pivots = ma_pivots(mn, mt); 1348 1359 if (likely(!slots[0])) { 1349 - max_gap = pivots[0] - mas->min + 1; 1360 + max_gap = pivots[0] - min + 1; 1350 1361 i = 2; 1351 1362 } else { 1352 1363 i = 1; 1353 1364 } 1354 1365 1355 1366 /* reduce max_piv as the special case is checked before the loop */ 1356 - max_piv = ma_data_end(mn, mt, pivots, mas->max) - 1; 1367 + max_piv = ma_data_end(mn, mt, pivots, max) - 1; 1357 1368 /* 1358 1369 * Check end implied pivot which can only be a gap on the right most 1359 1370 * node. 1360 1371 */ 1361 - if (unlikely(mas->max == ULONG_MAX) && !slots[max_piv + 1]) { 1372 + if (unlikely(max == ULONG_MAX) && !slots[max_piv + 1]) { 1362 1373 gap = ULONG_MAX - pivots[max_piv]; 1363 1374 if (gap > max_gap) 1364 1375 max_gap = gap; 1365 1376 1366 - if (max_gap > pivots[max_piv] - mas->min) 1377 + if (max_gap > pivots[max_piv] - min) 1367 1378 return max_gap; 1368 1379 } 1369 1380 ··· 1380 1393 i++; 1381 1394 } 1382 1395 return max_gap; 1396 + } 1397 + 1398 + /* 1399 + * mas_leaf_max_gap() - Returns the largest gap in a leaf node 1400 + * @mas: the maple state 1401 + * 1402 + * Return: The maximum gap in the leaf. 1403 + */ 1404 + static inline unsigned long mas_leaf_max_gap(struct ma_state *mas) 1405 + { 1406 + enum maple_type mt; 1407 + struct maple_node *mn; 1408 + unsigned long *pivots; 1409 + void __rcu **slots; 1410 + 1411 + mn = mas_mn(mas); 1412 + mt = mte_node_type(mas->node); 1413 + slots = ma_slots(mn, mt); 1414 + pivots = ma_pivots(mn, mt); 1415 + 1416 + return ma_leaf_max_gap(mn, mt, mas->min, mas->max, pivots, slots); 1383 1417 } 1384 1418 1385 1419 /*