(评论)
(comments)

原始链接: https://news.ycombinator.com/item?id=40932492

DUT 是一个用 C 语言编写的快速磁盘使用计算器,它的性能优于标准的“du”命令,并且在系统缓存优化时也优于其他命令。 该项目旨在超越 PDU 和 Dust 等流行工具。 DUT 提供具有链接大小的目录大小层次结构。 它的链接跟踪从 ncdu 中汲取了灵感,尽管它的显示格式被认为不太用户友好。 欢迎寻求改进建议的用户。 要安装,只需下载、编译 DUT 并将其放置在系统路径中的某个位置,例如 /usr/local/bin。 Git 历史记录了各种开发方法。 核心组件由数据结构组成:等待处理的目录队列和用于存储文件和目录统计信息的二进制堆。 由于性能不佳,最初尝试使用 C++ 队列和互斥体,然后再制定自定义解决方案。 增强功能包括使用 fstatat(2)、statx(2)、getdents(2) 以及最小化线程间交互。 尽管之前没有关于 fstatat 和 statx 相对于传统 stat 函数的优越性的文档,但这些见解可能会使潜在的开发人员受益。

相关文章

原文
"dut" is a disk usage calculator that I wrote a couple months ago in C. It is multi-threaded, making it one of the fastest such programs. It beats normal "du" in all cases, and beats all other similar programs when Linux's caches are warm (so, not on the first run). I wrote "dut" as a challenge to beat similar programs that I used a lot, namely pdu[1] and dust[2].

"dut" displays a tree of the biggest things under your current directory, and it also shows the size of hard-links under each directory as well. The hard-link tallying was inspired by ncdu[3], but I don't like how unintuitive the readout is. Anyone have ideas for a better format?

There's installation instructions in the README. dut is a single source file, so you only need to download it and copy-paste the compiler command, and then copy somewhere on your path like /usr/local/bin.

I went through a few different approaches writing it, and you can see most of them in the git history. At the core of the program is a datastructure that holds the directories that still need to be traversed, and binary heaps to hold statted files and directories. I had started off using C++ std::queues with mutexes, but the performance was awful, so I took it as a learning opportunity and wrote all the datastructures from scratch. That was the hardest part of the program to get right.

These are the other techniques I used to improve performance:

* Using fstatat(2) with the parent directory's fd instead of lstat(2) with an absolute path. (10-15% performance increase)

* Using statx(2) instead of fstatat. (perf showed fstatat running statx code in the kernel). (10% performance increase)

* Using getdents(2) to get directory contents instead of opendir/readdir/closedir. (also around 10%)

* Limiting inter-thread communication. I originally had fs-traversal results accumulated in a shared binary heap, but giving each thread a binary-heap and then merging them all at the end was faster.

I couldn't find any information online about fstatat and statx being significantly faster than plain old stat, so maybe this info will help someone in the future.

[1]: https://github.com/KSXGitHub/parallel-disk-usage

[2]: https://github.com/bootandy/dust

[3]: https://dev.yorhel.nl/doc/ncdu2, see "Shared Links"

联系我们 contact @ memedata.com