readdir_r 弃用的性能影响?

Performance implications of readdir_r deprecation?

当我在新工作站上重新编译我的 FUSE 文件系统时,我注意到有关 readdir_r 的弃用警告。由于 readdir 不是 MT 安全的并且需要自己的同步我有点困惑。

我不确定什么不是 MT 安全的 - 是 readdir 单独还是读取特定目录的整个过程直到结束?似乎标准试图通过指出 readdir 如果在不同目录上调用它是 MT 安全的来证明这一决定的合理性,但如果您的 "program" 是多用户覆盖 FUSE 文件系统,这显然不是安全的假设。那么我应该将整个目录读取过程放在临界区还是只放在单个 readdir 调用中?

老实说,从性能的角度来看,这两种情况对我来说都很糟糕——我的担忧是否有效,或者 Linux 内核中是否存在其他一些瓶颈,使得无论如何都不可能在单个目录上执行并行读取更多比一个 process/thread?

In the current POSIX.1 specification (POSIX.1-2008), readdir(3) is not required to be thread-safe. However, in modern implementations (including the glibc implementation), concurrent calls to readdir(3) that specify different directory streams are thread-safe.

手册页说它是线程安全的(假设您使用的是 glibc,我认为这是对 Linux 的合理假设)——假设您使用的是不同的目录 streams - 不是不同的目录。

目录流是 readdir 的 DIR * 参数。