aboutsummaryrefslogtreecommitdiff
path: root/lib/maple_tree.c
diff options
context:
space:
mode:
authorGravatar Peng Zhang <zhangpeng.00@bytedance.com> 2023-12-15 15:46:32 +0800
committerGravatar Andrew Morton <akpm@linux-foundation.org> 2023-12-20 14:48:14 -0800
commit7e552dcd803f4ff60165271c573ab2e38d15769f (patch)
treee21e4895f508b6f2e9d12722accb4edf6c8a8eb5 /lib/maple_tree.c
parentmm/memory: replace kmap() with kmap_local_page() (diff)
downloadlinux-7e552dcd803f4ff60165271c573ab2e38d15769f.tar.gz
linux-7e552dcd803f4ff60165271c573ab2e38d15769f.tar.bz2
linux-7e552dcd803f4ff60165271c573ab2e38d15769f.zip
maple_tree: avoid checking other gaps after getting the largest gap
The last range stored in maple tree is typically quite large. By checking if it exceeds the sum of the remaining ranges in that node, it is possible to avoid checking all other gaps. Running the maple tree test suite in user mode almost always results in a near 100% hit rate for this optimization. Link: https://lkml.kernel.org/r/20231215074632.82045-1-zhangpeng.00@bytedance.com Signed-off-by: Peng Zhang <zhangpeng.00@bytedance.com> Reviewed-by: Liam R. Howlett <Liam.Howlett@oracle.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Diffstat (limited to 'lib/maple_tree.c')
-rw-r--r--lib/maple_tree.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/lib/maple_tree.c b/lib/maple_tree.c
index c9a970ea20dd..6f241bb38799 100644
--- a/lib/maple_tree.c
+++ b/lib/maple_tree.c
@@ -1518,6 +1518,9 @@ static unsigned long mas_leaf_max_gap(struct ma_state *mas)
gap = ULONG_MAX - pivots[max_piv];
if (gap > max_gap)
max_gap = gap;
+
+ if (max_gap > pivots[max_piv] - mas->min)
+ return max_gap;
}
for (; i <= max_piv; i++) {