From: Max Kellermann Date: Thu, 10 Oct 2024 07:31:53 +0000 (+0200) Subject: MDS/CDir: return as early as possible from CDir::should_split_fast() X-Git-Tag: testing/wip-pdonnell-testing-20241106.142118-debug~24^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=27feea13ff0fe9690bc099e3692ffbd5db5e51e4;p=ceph-ci.git 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 --- diff --git a/src/mds/CDir.cc b/src/mds/CDir.cc index f000da7928a..0095b5276e9 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