Transparent filesystem compression
Filesystem-managed compression of eligible file data that preserves the original logical bytes exposed to applications.
In Btrfs, compression works on file extents, and data are split into 128 KiB chunks before compression so that random rewrites avoid a large penalty, at the cost of more extents and metadata. Changing compression policy affects new writes, leaving existing data untouched, and an algorithm chosen for a defragmentation run applies to that run only. Zstandard levels range from -15 to 15 and zlib levels from 1 to 9, with level 3 as the default for both. Attempting compression is not a guarantee that each block is stored compressed: even compress-force may retain an uncompressed representation. [1]
In OpenZFS, blocks are allocated in whole sectors of 2^ashift bytes, so a block that saves less than one sector is stored uncompressed, and a 12.5% default threshold applies in addition. With a 16 KiB record size and 4 KiB sectors, compression must save at least 25% to reduce space on disk. Zero-filled blocks are stored as holes instead of being compressed. [3]
Relations
- related
- Reflink, Filesystem defragmentation, Copy-on-write (storage), File extent, Lossless compression, Compression ratio
Advantages
- Applications keep reading and writing the original bytes, and one filesystem can hold uncompressed files next to files compressed with different algorithms. [1]
Limitations
- Files touched by fallocate are excluded from Btrfs compression even with compress-force, because preallocated space must guarantee that later writes do not fail. [1]
- If the first compressed portion of a Btrfs file is not smaller than the original, the file is marked NOCOMPRESS and is not compressed again unless forced. [1]
- Higher levels use more CPU time and memory and may not shrink the data significantly further. [1]
Citations
- Btrfs-progs v6.16: Compression chapter, algorithms, levels, exceptions and incompressible data
- OpenZFS zfs-2.3.4: zfsprops(7), compression property, sector rounding and threshold.
Further reading
Sources & caveats
- btrfs-compression is the btrfs-progs v6.16 compression chapter, re-read for chunk size, levels, exceptions and incompressible data.
- zfsprops is the OpenZFS zfs-2.3.4 zfsprops(7) manual page, read for the compression property, sector rounding and the default threshold.
- No compression ratio or throughput measurement is claimed.