]> git.proxmox.com Git - mirror_zfs.git/commit
Add zstd support to zfs
authorMichael Niewöhner <foss@mniewoehner.de>
Tue, 18 Aug 2020 17:10:17 +0000 (19:10 +0200)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Thu, 20 Aug 2020 17:30:06 +0000 (10:30 -0700)
commit10b3c7f5e424f54b3ba82dbf1600d866e64ec0a0
tree6d4debce2b3e4232411399e7dde1221a95af061a
parentdc544aba15758f7fbf55ef6a95ae8b93e241c533
Add zstd support to zfs

This PR adds two new compression types, based on ZStandard:

- zstd: A basic ZStandard compression algorithm Available compression.
  Levels for zstd are zstd-1 through zstd-19, where the compression
  increases with every level, but speed decreases.

- zstd-fast: A faster version of the ZStandard compression algorithm
  zstd-fast is basically a "negative" level of zstd. The compression
  decreases with every level, but speed increases.

  Available compression levels for zstd-fast:
   - zstd-fast-1 through zstd-fast-10
   - zstd-fast-20 through zstd-fast-100 (in increments of 10)
   - zstd-fast-500 and zstd-fast-1000

For more information check the man page.

Implementation details:

Rather than treat each level of zstd as a different algorithm (as was
done historically with gzip), the block pointer `enum zio_compress`
value is simply zstd for all levels, including zstd-fast, since they all
use the same decompression function.

The compress= property (a 64bit unsigned integer) uses the lower 7 bits
to store the compression algorithm (matching the number of bits used in
a block pointer, as the 8th bit was borrowed for embedded block
pointers).  The upper bits are used to store the compression level.

It is necessary to be able to determine what compression level was used
when later reading a block back, so the concept used in LZ4, where the
first 32bits of the on-disk value are the size of the compressed data
(since the allocation is rounded up to the nearest ashift), was
extended, and we store the version of ZSTD and the level as well as the
compressed size. This value is returned when decompressing a block, so
that if the block needs to be recompressed (L2ARC, nop-write, etc), that
the same parameters will be used to result in the matching checksum.

All of the internal ZFS code ( `arc_buf_hdr_t`, `objset_t`,
`zio_prop_t`, etc.) uses the separated _compress and _complevel
variables.  Only the properties ZAP contains the combined/bit-shifted
value. The combined value is split when the compression_changed_cb()
callback is called, and sets both objset members (os_compress and
os_complevel).

The userspace tools all use the combined/bit-shifted value.

Additional notes:

zdb can now also decode the ZSTD compression header (flag -Z) and
inspect the size, version and compression level saved in that header.
For each record, if it is ZSTD compressed, the parameters of the decoded
compression header get printed.

ZSTD is included with all current tests and new tests are added
as-needed.

Per-dataset feature flags now get activated when the property is set.
If a compression algorithm requires a feature flag, zfs activates the
feature when the property is set, rather than waiting for the first
block to be born.  This is currently only used by zstd but can be
extended as needed.

Portions-Sponsored-By: The FreeBSD Foundation
Co-authored-by: Allan Jude <allanjude@freebsd.org>
Co-authored-by: Brian Behlendorf <behlendorf1@llnl.gov>
Co-authored-by: Sebastian Gottschall <s.gottschall@dd-wrt.com>
Co-authored-by: Kjeld Schouten-Lebbing <kjeld@schouten-lebbing.nl>
Co-authored-by: Michael Niewöhner <foss@mniewoehner.de>
Signed-off-by: Allan Jude <allan@klarasystems.com>
Signed-off-by: Allan Jude <allanjude@freebsd.org>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Sebastian Gottschall <s.gottschall@dd-wrt.com>
Signed-off-by: Kjeld Schouten-Lebbing <kjeld@schouten-lebbing.nl>
Signed-off-by: Michael Niewöhner <foss@mniewoehner.de>
Closes #6247
Closes #9024
Closes #10277
Closes #10278
69 files changed:
AUTHORS
cmd/dbufstat/dbufstat.in
cmd/zdb/zdb.c
configure.ac
include/sys/Makefile.am
include/sys/arc.h
include/sys/arc_impl.h
include/sys/dmu_objset.h
include/sys/dsl_dataset.h
include/sys/spa.h
include/sys/zfs_context.h
include/sys/zfs_ioctl.h
include/sys/zio.h
include/sys/zio_compress.h
include/sys/zio_impl.h
include/sys/zstd/Makefile.am [new file with mode: 0644]
include/sys/zstd/zstd.h [new file with mode: 0644]
include/zfeature_common.h
lib/Makefile.am
lib/libzpool/Makefile.am
lib/libzpool/kernel.c
lib/libzstd/Makefile.am [new file with mode: 0644]
man/man5/zpool-features.5
man/man8/zfsprops.8
module/Kbuild.in
module/Makefile.bsd
module/Makefile.in
module/zcommon/zfeature_common.c
module/zcommon/zfs_prop.c
module/zfs/arc.c
module/zfs/blkptr.c
module/zfs/dbuf.c
module/zfs/dmu.c
module/zfs/dmu_objset.c
module/zfs/dmu_recv.c
module/zfs/dmu_send.c
module/zfs/dsl_dataset.c
module/zfs/spa_misc.c
module/zfs/zfs_ioctl.c
module/zfs/zio.c
module/zfs/zio_compress.c
module/zstd/Makefile.in [new file with mode: 0644]
module/zstd/README.md [new file with mode: 0644]
module/zstd/include/aarch64_compat.h [new file with mode: 0644]
module/zstd/include/limits.h [new file with mode: 0644]
module/zstd/include/stddef.h [new file with mode: 0644]
module/zstd/include/stdint.h [new file with mode: 0644]
module/zstd/include/stdio.h [new file with mode: 0644]
module/zstd/include/stdlib.h [new file with mode: 0644]
module/zstd/include/string.h [new file with mode: 0644]
module/zstd/zfs_zstd.c [new file with mode: 0644]
scripts/Makefile.am
scripts/dkms.mkconf
scripts/zfs.sh
tests/runfiles/common.run
tests/zfs-tests/include/properties.shlib
tests/zfs-tests/tests/functional/cli_root/zdb/Makefile.am
tests/zfs-tests/tests/functional/cli_root/zdb/zdb_args_neg.ksh
tests/zfs-tests/tests/functional/cli_root/zdb/zdb_decompress_zstd.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_receive/Makefile.am
tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_from_zstd.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_receive/zstd_test_data.txt [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zfs_set/Makefile.am
tests/zfs-tests/tests/functional/cli_root/zfs_set/zfs_set_feature_activation.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_get/zpool_get.cfg
tests/zfs-tests/tests/functional/compression/Makefile.am
tests/zfs-tests/tests/functional/compression/l2arc_encrypted.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/compression/l2arc_encrypted_no_compressed_arc.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/history/history_002_pos.ksh