From 27feea13ff0fe9690bc099e3692ffbd5db5e51e4 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 10 Oct 2024 09:31:53 +0200 Subject: [PATCH] MDS/CDir: return as early as possible from CDir::should_split_fast() All we want to know is whether we're above the `fast_limit`; if we're above that, we don't need to know how many exactly. By returning early instead of iterating over all entries, a lot of CPU time can be saved. In a microbenchmark where `fio` was used to create thousands of files, the CPU usage of `CDir::should_split_fast()` went from 6% to less than 1% in the `perf report`. Signed-off-by: Max Kellermann --- src/mds/CDir.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/mds/CDir.cc b/src/mds/CDir.cc index f000da7928a7..0095b5276e9c 100644 --- a/src/mds/CDir.cc +++ b/src/mds/CDir.cc @@ -3811,10 +3811,13 @@ bool CDir::should_split_fast() const const CDentry *dn = p.second; if (!dn->get_projected_linkage()->is_null()) { effective_size++; + + if (effective_size > fast_limit) [[unlikely]] + return true; } } - return effective_size > fast_limit; + return false; } bool CDir::should_merge() const -- 2.47.3