
(Esther Arzola的Ferris侦探,KarenRustadTölva的原创设计)
Findlargedir是一种专门编写的工具,可帮助快速识别具有单个平坦结构中超过100K条目的任何文件系统上的“黑洞”目录。当目录有许多条目(目录或文件)时,获得目录列表的速度越慢,影响了试图获取目录列表的所有过程的性能(例如,删除某些文件和/或查找某些特定文件)。读取大型目录indodes的过程在这样做的同时被冷冻,最终会在不间断的睡眠(“ d”状态)中持续更长的时间。根据文件系统的不同,这可能会因100K条目而变得可见,并且开始对1M+条目产生非常明显的性能影响。
即使大多数Linux和un*X文件系统不支持目录Inode收缩(例如非常常见的Ext3/Ext4),因此这些目录大多也无法缩小,即使内容被清理了。这通常发生在被遗忘的Web Sessions目录(PHP Sessions文件夹中,将GC间隔配置为几天),各种缓存文件夹(CMS编译模板和缓存),POSIX文件系统模拟对象存储等。
程序将尝试确定任何此类事件,并根据校准进行报告。每个文件系统中的每个目录Inode中都包装了多少个假设目录条目。在这样做的同时,它将确定目录Inode的增长率与条目数量/Inode的数量,并将使用该比率快速扫描文件系统,避免执行昂贵/慢速目录查找。虽然有许多工具可以扫描文件系统( find , du , ncdu等),但它们都没有使用启发式方法来避免昂贵的查找,因为它们旨在完全准确,而该工具则旨在使用启发式方法和警报,而不会遇到问题的文件夹。
程序将不会遵循符号链接,并且需要R/W权限才能校准目录,以便能够计算目录Inode的大小与条目比率的数量,并估算目录中的许多条目,而无需实际对其进行计数。虽然此方法只是目录中实际条目数量的近似值,但它足够好,可以快速扫描犯罪目录。

-a )会导致过多的I/O和过多的内存使用;仅在适当时使用Usage: findlargedir [OPTIONS] < PATH > ...
Arguments:
< PATH > ... Paths to check for large directories
Options:
-a, --accurate < ACCURATE >
Perform accurate directory entry counting [default: false] [possible values: true, false]
-o, --one-filesystem < ONE_FILESYSTEM >
Do not cross mount points [default: true] [possible values: true, false]
-c, --calibration-count < CALIBRATION_COUNT >
Calibration directory file count [default: 100000]
-A, --alert-threshold < ALERT_THRESHOLD >
Alert threshold count (print the estimate) [default: 10000]
-B, --blacklist-threshold < BLACKLIST_THRESHOLD >
Blacklist threshold count (print the estimate and stop deeper scan) [default: 100000]
-x, --threads < THREADS >
Number of threads to use when calibrating and scanning [default: 24]
-p, --updates < UPDATES >
Seconds between status updates, set to 0 to disable [default: 20]
-i, --size-inode-ratio < SIZE_INODE_RATIO >
Skip calibration and provide directory entry to inode size ratio (typically ~ 21-32) [default: 0]
-t, --calibration-path < CALIBRATION_PATH >
Custom calibration directory path
-s, --skip-path < SKIP_PATH >
Directories to exclude from scanning
-h, --help
Print help information
-V, --version
Print version information当使用准确的模式( -a参数)时,请注意大型目录查找将完全停止该过程的长时间。这种模式的作用基本上是在可能有罪的目录上计算精确数量的条目的次级完全准确的通过。
为了避免登录到挂载的文件系统(如find -xdev选项中),默认情况下,参数单文件系统模式( -o参数)被切换,但是如有必要,可以将其禁用。
可以通过手动提供-i参数的目录Inode大小到条目比率的目录大小与条目的数量,可以完全跳过校准阶段。只有当您已经知道比率(例如从以前的运行中)时,这才有意义。
设置-p参数到0将阻止程序偶尔提供状态更新。
硬件:8核Xeon E5-1630与4驱动SATA RAID-10
基准设置:
$ cat bench1.sh
#! /bin/dash
exec /usr/bin/find / -xdev -type d -size +200000c
$ cat bench2.sh
#! /bin/dash
exec /usr/local/sbin/findlargedir /用超细测量的实际结果:
$ hyperfine --prepare ' echo 3 | tee /proc/sys/vm/drop_caches '
./bench1.sh ./bench2.sh
Benchmark 1: ./bench1.sh
Time (mean ± σ): 357.040 s ± 7.176 s [User: 2.324 s, System: 13.881 s]
Range (min … max): 349.639 s … 367.636 s 10 runs
Benchmark 2: ./bench2.sh
Time (mean ± σ): 199.751 s ± 4.431 s [User: 75.163 s, System: 141.271 s]
Range (min … max): 190.136 s … 203.432 s 10 runs
Summary
' ./bench2.sh ' ran
1.79 ± 0.05 times faster than ' ./bench1.sh ' 硬件:48核Xeon Silver 4214,7-Drive SM883 SATA HW RAID-5阵列,2TB内容(十几个具有小文件的容器)
相同的基准设置。结果:
$ hyperfine --prepare ' echo 3 | tee /proc/sys/vm/drop_caches '
./bench1.sh ./bench2.sh
Benchmark 1: ./bench1.sh
Time (mean ± σ): 392.433 s ± 1.952 s [User: 16.056 s, System: 81.994 s]
Range (min … max): 390.284 s … 395.732 s 10 runs
Benchmark 2: ./bench2.sh
Time (mean ± σ): 34.650 s ± 0.469 s [User: 79.441 s, System: 528.939 s]
Range (min … max): 34.049 s … 35.388 s 10 runs
Summary
' ./bench2.sh ' ran
11.33 ± 0.16 times faster than ' ./bench1.sh '