与 Ext4 (Linux) 相比,为什么 lstat 在 APFS (OSX) 上的性能较差

Why is performance of lstat poor on APFS (OSX) compared to Ext4 (Linux)

在大型存储库上分析 Git 时,我发现 git 状态在 mac 上比 linux 慢得多(10 倍)。 git status 在存储库中的每个文件上运行 lstat,这是缓慢的来源。

与 linux 相比,此系统调用在 mac 上慢得多是否有特殊原因?

首先检查您的 Git 版本,因为最近的 Git 版本(如 , and even the upcoming 2.27 with submodules)有所改进。

甚至git status improved with Git 2.24

The feature.manyFiles setting is suitable for repos with many files in the working directory.
By setting index.version=4 and core.untrackedCache=true, commands such as 'git status' should improve.


在“Global Kernel Locks in APFS" by Gregory Szorc:

中对 APFS 中 lstats 与 Ext4 的差异进行了一项分析

It is apparent that macOS 10.14 Mojave has received performance work relative to macOS 10.13!
Despite those improvements, APFS is still spending a lot of CPU time in the kernel. And the kernel CPU time is still comparatively very high compared to Linux/EXT4, even for single process operation.

While the source code for APFS is not available for me to confirm, the profiling results showing excessive time spent in lck_mtx_lock_grab_mutex() combined with the fact that execution time decreases when the parallel process count decreases leads me to the conclusion that APFS obtains a global kernel lock during read-only operations such as readdir().

In other words, APFS slows down when attempting to perform parallel read-only I/O.