「btrfs filesystem defrag -c」(壓縮選項)是否強制壓縮?

「btrfs filesystem defrag -c」(壓縮選項)是否強制壓縮?

啟用壓縮的 BTRFS 使用啟發式方法來不壓縮無法很好壓縮的檔案。使用“btrfs filesystem defrag -c”壓縮現有文件是否也使用啟發式,或者是否壓縮所有文件,即使它們不能很好地壓縮?

答案1

btrfs filesystem defrag -c似乎強制壓縮,只有在初始壓縮嘗試沒有成果並且檔案系統未安裝compress-force.

為了證明這一點,我創建了一個文件,其中包含前 1M 不可壓縮數據,隨後是 128K 可壓縮數據(即:文字檔案)。該檔案使用各種選項儲存/tmp並複製到 btrfs 掛載點:

# compress=lzo: no actual compression
root@debian12:~# mount /dev/zvol/tank/vol1 /mnt/ -o compress=lzo
root@debian12:~# cp /tmp/random.img /mnt/
root@debian12:~# sync
root@debian12:~# compsize /mnt/random.img
Processed 1 file, 1 regular extents (1 refs), 0 inline.
Type       Perc     Disk Usage   Uncompressed Referenced
TOTAL      100%      1.1M         1.1M         1.1M
none       100%      1.1M         1.1M         1.1M

# compress=lzo + defrag: compressed, but 'm' (incompressible) flag set
root@debian12:~# btrfs filesystem defrag -c -r /mnt/
root@debian12:~# sync
root@debian12:~# compsize /mnt/random.img
Processed 1 file, 3 regular extents (3 refs), 0 inline.
Type       Perc     Disk Usage   Uncompressed Referenced
TOTAL       90%      1.0M         1.1M         1.1M
none       100%      1.0M         1.0M         1.0M
zlib        15%       20K         128K         128K
root@debian12:~# lsattr /mnt/random.img
---------------------m /mnt/random.img

# compress-force=lzo: some limited compression 
root@debian12:~# mount /dev/zvol/tank/vol1 /mnt/ -o compress-force=lzo
root@debian12:~# cp /tmp/random.img /mnt/
root@debian12:~# sync
root@debian12:~# compsize /mnt/random.img
Processed 1 file, 3 regular extents (3 refs), 0 inline.
Type       Perc     Disk Usage   Uncompressed Referenced
TOTAL       96%      1.0M         1.1M         1.1M
none       100%      1.0M         1.0M         1.0M
lzo         68%       88K         128K         128K

# compress-force=lzo + defrag: better compression and no 'm' flag
root@debian12:~# compsize /mnt/random.img
Processed 1 file, 3 regular extents (3 refs), 0 inline.
Type       Perc     Disk Usage   Uncompressed Referenced
TOTAL       90%      1.0M         1.1M         1.1M
none       100%      1.0M         1.0M         1.0M
zlib        15%       20K         128K         128K
root@debian12:~# lsattr /mnt/random.img
---------------------- /mnt/random.img

相關內容