From 10b3c7f5e424f54b3ba82dbf1600d866e64ec0a0 Mon Sep 17 00:00:00 2001 From: Michael Niewöhner Date: Tue, 18 Aug 2020 19:10:17 +0200 Subject: Add zstd support to zfs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Co-authored-by: Brian Behlendorf Co-authored-by: Sebastian Gottschall Co-authored-by: Kjeld Schouten-Lebbing Co-authored-by: Michael Niewöhner Signed-off-by: Allan Jude Signed-off-by: Allan Jude Signed-off-by: Brian Behlendorf Signed-off-by: Sebastian Gottschall Signed-off-by: Kjeld Schouten-Lebbing Signed-off-by: Michael Niewöhner Closes #6247 Closes #9024 Closes #10277 Closes #10278 --- man/man8/zfsprops.8 | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'man/man8') diff --git a/man/man8/zfsprops.8 b/man/man8/zfsprops.8 index 1fcb07c6f..11ec29832 100644 --- a/man/man8/zfsprops.8 +++ b/man/man8/zfsprops.8 @@ -36,6 +36,7 @@ .\" Copyright 2019 Richard Laager. All rights reserved. .\" Copyright 2018 Nexenta Systems, Inc. .\" Copyright 2019 Joyent, Inc. +.\" Copyright (c) 2019, Kjeld Schouten-Lebbing .\" .Dd January 30, 2020 .Dt ZFSPROPS 8 @@ -773,7 +774,8 @@ for more information on these algorithms. Changing this property affects only newly-written data. .It Xo .Sy compression Ns = Ns Sy on Ns | Ns Sy off Ns | Ns Sy gzip Ns | Ns -.Sy gzip- Ns Em N Ns | Ns Sy lz4 Ns | Ns Sy lzjb Ns | Ns Sy zle +.Sy gzip- Ns Em N Ns | Ns Sy lz4 Ns | Ns Sy lzjb Ns | Ns Sy zle Ns | Ns Sy zstd Ns | Ns +.Sy zstd- Ns Em N Ns | Ns Sy zstd-fast Ns | Ns Sy zstd-fast- Ns Em N .Xc Controls the compression algorithm used for this dataset. .Pp @@ -841,6 +843,38 @@ is equivalent to .Pc . .Pp The +.Sy zstd +compression algorithm provides both high compression ratios and good +performance. You can specify the +.Sy zstd +level by using the value +.Sy zstd- Ns Em N , +where +.Em N +is an integer from 1 +.Pq fastest +to 19 +.Pq best compression ratio . +.Sy zstd +is equivalent to +.Sy zstd-3 . +.Pp +Faster speeds at the cost of the compression ratio can be requested by +setting a negative +.Sy zstd +level. This is done using +.Sy zstd-fast- Ns Em N , +where +.Em N +is an integer in [1-9,10,20,30,...,100,500,1000] which maps to a negative +.Sy zstd +level. The lower the level the faster the compression - 1000 provides +the fastest compression and lowest compression ratio. +.Sy zstd-fast +is equivalent to +.Sy zstd-fast-1 . +.Pp +The .Sy zle compression algorithm compresses runs of zeros. .Pp -- cgit v1.2.3