Linux Kernel Patch

There are two pieces, the zstd_compress and zstd_decompress kernel modules, and the BtrFS patch. The patches are based off of the linux kernel master branch (version 4.10).

Zstd Kernel modules

  • The header is in include/linux/zstd.h.
  • It is split up into zstd_compress and zstd_decompress, which can be loaded independently.
  • Source files are in lib/zstd/.
  • lib/Kconfig and lib/Makefile need to be modified by applying lib/Kconfig.diff and lib/Makefile.diff respectively.
  • test/UserlandTest.cpp contains tests for the patch in userland by mocking the kernel headers. It can be run with the following commands:
    cd test
    make googletest
    make UserlandTest
    ./UserlandTest
    

BtrFS

  • The patch is located in btrfs.diff.
  • Additionally fs/btrfs/zstd.c is provided as a source for convenience.
  • The patch seems to be working, it doesn't crash the kernel, and compresses at speeds and ratios athat are expected. It can still use some more testing for fringe features, like printing options.

Benchmarks

Benchmarks run on a Ubuntu 14.04 with 2 cores and 4 GiB of RAM. The VM is running on a Macbook Pro with a 3.1 GHz Intel Core i7 processor, 16 GB of ram, and a SSD.

The compression benchmark is copying 10 copies of the unzipped silesia corpus into a BtrFS filesystem mounted with -o compress-force={none, lzo, zlib, zstd}. The decompression benchmark is timing how long it takes to tar all 10 copies into /dev/null. The compression ratio is measured by comparing the output of df and du. See btrfs-benchmark.sh for details.

AlgorithmCompression ratioCompression speedDecompression speed
None0.99504 MB/s686 MB/s
lzo1.66398 MB/s442 MB/s
zlib2.5865 MB/s241 MB/s
zstd 12.57260 MB/s383 MB/s
zstd 32.71174 MB/s408 MB/s
zstd 62.8770 MB/s398 MB/s
zstd 92.9243 MB/s406 MB/s
zstd 122.9321 MB/s408 MB/s
zstd 153.0111 MB/s354 MB/s