]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
MDS/CDir: return as early as possible from CDir::should_split_fast() 60236/head
authorMax Kellermann <max.kellermann@ionos.com>
Thu, 10 Oct 2024 07:31:53 +0000 (09:31 +0200)
committerMax Kellermann <max.kellermann@ionos.com>
Fri, 18 Oct 2024 07:49:40 +0000 (09:49 +0200)
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 <max.kellermann@ionos.com>
src/mds/CDir.cc

index f000da7928a726071c4b0f2ea4517001b8695991..0095b5276e9c8e1453aae9a42ea0abc07ff6b19b 100644 (file)
@@ -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