圧縮が有効になっている BTRFS は、圧縮しにくいファイルを圧縮しないというヒューリスティックを使用します。「btrfs filesystem defrag -c」を使用して既存のファイルを圧縮する場合もヒューリスティックが使用されますか、それとも圧縮しにくいファイルであってもすべてのファイルが圧縮されますか?
答え1
btrfs filesystem defrag -c
圧縮を強制しているようで、初期の圧縮試行が成功せず、ファイルシステムが でマウントされていない場合にのみ、最終的にファイルを圧縮不可としてフラグ付けしますcompress-force
。
それを証明するため、最初に 1 MB の非圧縮データ、続いて 128 MB の圧縮データ (つまりテキスト ファイル) を持つファイルを作成しました。このファイルは、/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