Skip to content

Commit 27feea1

Browse files
committed
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 <[email protected]>
1 parent c5faa93 commit 27feea1

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/mds/CDir.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3811,10 +3811,13 @@ bool CDir::should_split_fast() const
38113811
const CDentry *dn = p.second;
38123812
if (!dn->get_projected_linkage()->is_null()) {
38133813
effective_size++;
3814+
3815+
if (effective_size > fast_limit) [[unlikely]]
3816+
return true;
38143817
}
38153818
}
38163819

3817-
return effective_size > fast_limit;
3820+
return false;
38183821
}
38193822

38203823
bool CDir::should_merge() const

0 commit comments

Comments
 (0)