Compbench is a C tool that benchmarks Btrfs compression algorithms (zstd, lzo) by measuring read and write throughput, compression ratio, CPU usage, and disk I/O — all through direct kernel interfaces with zero text parsing of external tool output.
- Direct kernel interfaces — compression ratio via
statvfs(), CPU via/proc/stat, disk I/O via/sys/block/*/stat, timing viaclock_gettime(CLOCK_MONOTONIC_RAW), data copy viacopy_file_range() - Exhaustive testing — configurable zstd level range (-15..15), lzo, zlib, and no compression
- Cold-cache reads — the page cache is dropped before the read test, so
RdMiB/sreflects real disk throughput, not memory - Force mode comparison — run standard
compressand/orcompress-forcemount options, with a side-by-side percentage comparison table - HDD zone testing — benchmark first/last N% of disk to evaluate spatial performance variations, with interpolated results
- Repeatable — average results over multiple runs, with throughput standard deviation reported in the CSV
- Disk-level I/O stats — actual bytes written to physical media, separate from apparent throughput
- CSV export — machine-readable output with full metadata (archive, dataset, host, kernel, date)
sudo apt install gcc make btrfs-progs xz-utils gdisk curltar and util-linux are typically installed by default.
make
sudo make installThis installs the compbench binary and its man page (compbench(1)).
The binary is dynamically linked against libm and libc only.
Warning: This tool formats the target device, erasing all existing data.
sudo compbench /dev/sdX https://example.com/archive.tar.xzUsage: compbench [OPTIONS] DEVICE ARCHIVE
DEVICE is the block device to test (e.g. /dev/sdX).
ARCHIVE is a local path or URL to a .tar.xz archive.
Options:
-n, --repeat N Repeat each test N times (default: 1)
--zstd MIN-MAX zstd level range (default: 1-15)
-f, --force MODE Force mode: none|zstd|lzo|all|both (default: none)
--hdd PERCENT Test on first/last N% of disk (1-50)
-o, --output FILE Export results to CSV
--no-integrity-check
Skip archive integrity verification
-v, --verbose Verbose output
-h, --help Show help
-V, --version Show version
| Mode | Effect |
|---|---|
none |
Standard compress= for all tests |
zstd |
compress-force= for zstd, standard for lzo |
lzo |
compress-force= for lzo, standard for zstd |
all |
compress-force= for all algorithms |
both |
Run each test twice (standard + force) and show comparison |
sudo compbench /dev/sdX https://example.com/archive.tar.xz -n 3 --zstd 1-10 -f both --hdd 10 -vThis will:
- Test zstd levels 10 down to 1, plus lzo and no compression
- Repeat the sequence 3 times with averaged results
- Run both standard and force modes with a comparison table
- Test on the first and last 10% of the disk
- Run in verbose mode
All metrics use kernel interfaces directly:
| Column | Description | Source |
|---|---|---|
| WrMiB/s | Synced write throughput (copy + sync) | clock_gettime |
| RdMiB/s | Read throughput after cache clear (page cache dropped + remount + full tree read) | clock_gettime |
| WrDisk* | Actual bytes written to physical media | /sys/block/*/stat |
| RdDisk* | Actual bytes read from physical media | /sys/block/*/stat |
| Ratio | Space consumed vs uncompressed | statvfs |
| WrCPU% | System CPU usage during write | /proc/stat |
| RdCPU% | System CPU usage during read | /proc/stat |
| Sec/Red | Seconds per 1% space reduction | Derived |
Download the .deb from GitHub Releases and install:
sudo dpkg -i compbench_*.deb
sudo apt-get install -fdpkg-buildpackage -us -ucThe test suite uses loop devices (no real disks needed):
sudo bash test.shContributions, bug reports, and suggestions are welcome! Please open an issue or submit a pull request on GitHub.
GNU General Public License v3.0