
(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 '