2008-11-20 23:01:55 +03:00
|
|
|
/*
|
|
|
|
* CDDL HEADER START
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the terms of the
|
|
|
|
* Common Development and Distribution License (the "License").
|
|
|
|
* You may not use this file except in compliance with the License.
|
|
|
|
*
|
|
|
|
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
|
2022-07-12 00:16:13 +03:00
|
|
|
* or https://opensource.org/licenses/CDDL-1.0.
|
2008-11-20 23:01:55 +03:00
|
|
|
* See the License for the specific language governing permissions
|
|
|
|
* and limitations under the License.
|
|
|
|
*
|
|
|
|
* When distributing Covered Code, include this CDDL HEADER in each
|
|
|
|
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
|
|
|
|
* If applicable, add the following below this CDDL HEADER, with the
|
|
|
|
* fields enclosed by brackets "[]" replaced with your own identifying
|
|
|
|
* information: Portions Copyright [yyyy] [name of copyright owner]
|
|
|
|
*
|
|
|
|
* CDDL HEADER END
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2010-05-29 00:45:14 +04:00
|
|
|
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
|
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
2020-08-18 20:10:17 +03:00
|
|
|
* Copyright (c) 2019, Allan Jude
|
2024-06-30 05:10:00 +03:00
|
|
|
* Copyright (c) 2019, 2024, Klara, Inc.
|
2008-11-20 23:01:55 +03:00
|
|
|
* Use is subject to license terms.
|
2016-07-22 18:52:49 +03:00
|
|
|
* Copyright (c) 2015, 2016 by Delphix. All rights reserved.
|
2008-11-20 23:01:55 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _SYS_ZIO_COMPRESS_H
|
|
|
|
#define _SYS_ZIO_COMPRESS_H
|
|
|
|
|
2016-07-22 18:52:49 +03:00
|
|
|
#include <sys/abd.h>
|
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2016-07-11 20:45:52 +03:00
|
|
|
enum zio_compress {
|
|
|
|
ZIO_COMPRESS_INHERIT = 0,
|
|
|
|
ZIO_COMPRESS_ON,
|
|
|
|
ZIO_COMPRESS_OFF,
|
|
|
|
ZIO_COMPRESS_LZJB,
|
|
|
|
ZIO_COMPRESS_EMPTY,
|
|
|
|
ZIO_COMPRESS_GZIP_1,
|
|
|
|
ZIO_COMPRESS_GZIP_2,
|
|
|
|
ZIO_COMPRESS_GZIP_3,
|
|
|
|
ZIO_COMPRESS_GZIP_4,
|
|
|
|
ZIO_COMPRESS_GZIP_5,
|
|
|
|
ZIO_COMPRESS_GZIP_6,
|
|
|
|
ZIO_COMPRESS_GZIP_7,
|
|
|
|
ZIO_COMPRESS_GZIP_8,
|
|
|
|
ZIO_COMPRESS_GZIP_9,
|
|
|
|
ZIO_COMPRESS_ZLE,
|
|
|
|
ZIO_COMPRESS_LZ4,
|
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
2020-08-18 20:10:17 +03:00
|
|
|
ZIO_COMPRESS_ZSTD,
|
2016-07-11 20:45:52 +03:00
|
|
|
ZIO_COMPRESS_FUNCTIONS
|
|
|
|
};
|
|
|
|
|
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
2020-08-18 20:10:17 +03:00
|
|
|
/* Compression algorithms that have levels */
|
|
|
|
#define ZIO_COMPRESS_HASLEVEL(compress) ((compress == ZIO_COMPRESS_ZSTD || \
|
|
|
|
(compress >= ZIO_COMPRESS_GZIP_1 && \
|
|
|
|
compress <= ZIO_COMPRESS_GZIP_9)))
|
|
|
|
|
|
|
|
#define ZIO_COMPLEVEL_INHERIT 0
|
|
|
|
#define ZIO_COMPLEVEL_DEFAULT 255
|
|
|
|
|
|
|
|
enum zio_zstd_levels {
|
|
|
|
ZIO_ZSTD_LEVEL_INHERIT = 0,
|
|
|
|
ZIO_ZSTD_LEVEL_1,
|
|
|
|
#define ZIO_ZSTD_LEVEL_MIN ZIO_ZSTD_LEVEL_1
|
|
|
|
ZIO_ZSTD_LEVEL_2,
|
|
|
|
ZIO_ZSTD_LEVEL_3,
|
|
|
|
#define ZIO_ZSTD_LEVEL_DEFAULT ZIO_ZSTD_LEVEL_3
|
|
|
|
ZIO_ZSTD_LEVEL_4,
|
|
|
|
ZIO_ZSTD_LEVEL_5,
|
|
|
|
ZIO_ZSTD_LEVEL_6,
|
|
|
|
ZIO_ZSTD_LEVEL_7,
|
|
|
|
ZIO_ZSTD_LEVEL_8,
|
|
|
|
ZIO_ZSTD_LEVEL_9,
|
|
|
|
ZIO_ZSTD_LEVEL_10,
|
|
|
|
ZIO_ZSTD_LEVEL_11,
|
|
|
|
ZIO_ZSTD_LEVEL_12,
|
|
|
|
ZIO_ZSTD_LEVEL_13,
|
|
|
|
ZIO_ZSTD_LEVEL_14,
|
|
|
|
ZIO_ZSTD_LEVEL_15,
|
|
|
|
ZIO_ZSTD_LEVEL_16,
|
|
|
|
ZIO_ZSTD_LEVEL_17,
|
|
|
|
ZIO_ZSTD_LEVEL_18,
|
|
|
|
ZIO_ZSTD_LEVEL_19,
|
|
|
|
#define ZIO_ZSTD_LEVEL_MAX ZIO_ZSTD_LEVEL_19
|
|
|
|
ZIO_ZSTD_LEVEL_RESERVE = 101, /* Leave room for new positive levels */
|
|
|
|
ZIO_ZSTD_LEVEL_FAST, /* Fast levels are negative */
|
|
|
|
ZIO_ZSTD_LEVEL_FAST_1,
|
|
|
|
#define ZIO_ZSTD_LEVEL_FAST_DEFAULT ZIO_ZSTD_LEVEL_FAST_1
|
|
|
|
ZIO_ZSTD_LEVEL_FAST_2,
|
|
|
|
ZIO_ZSTD_LEVEL_FAST_3,
|
|
|
|
ZIO_ZSTD_LEVEL_FAST_4,
|
|
|
|
ZIO_ZSTD_LEVEL_FAST_5,
|
|
|
|
ZIO_ZSTD_LEVEL_FAST_6,
|
|
|
|
ZIO_ZSTD_LEVEL_FAST_7,
|
|
|
|
ZIO_ZSTD_LEVEL_FAST_8,
|
|
|
|
ZIO_ZSTD_LEVEL_FAST_9,
|
|
|
|
ZIO_ZSTD_LEVEL_FAST_10,
|
|
|
|
ZIO_ZSTD_LEVEL_FAST_20,
|
|
|
|
ZIO_ZSTD_LEVEL_FAST_30,
|
|
|
|
ZIO_ZSTD_LEVEL_FAST_40,
|
|
|
|
ZIO_ZSTD_LEVEL_FAST_50,
|
|
|
|
ZIO_ZSTD_LEVEL_FAST_60,
|
|
|
|
ZIO_ZSTD_LEVEL_FAST_70,
|
|
|
|
ZIO_ZSTD_LEVEL_FAST_80,
|
|
|
|
ZIO_ZSTD_LEVEL_FAST_90,
|
|
|
|
ZIO_ZSTD_LEVEL_FAST_100,
|
|
|
|
ZIO_ZSTD_LEVEL_FAST_500,
|
|
|
|
ZIO_ZSTD_LEVEL_FAST_1000,
|
|
|
|
#define ZIO_ZSTD_LEVEL_FAST_MAX ZIO_ZSTD_LEVEL_FAST_1000
|
|
|
|
ZIO_ZSTD_LEVEL_AUTO = 251, /* Reserved for future use */
|
|
|
|
ZIO_ZSTD_LEVEL_LEVELS
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Forward Declaration to avoid visibility problems */
|
|
|
|
struct zio_prop;
|
|
|
|
|
2013-06-11 21:12:34 +04:00
|
|
|
/* Common signature for all zio compress functions. */
|
2024-06-30 05:10:00 +03:00
|
|
|
typedef size_t zio_compress_func_t(abd_t *src, abd_t *dst,
|
2008-11-20 23:01:55 +03:00
|
|
|
size_t s_len, size_t d_len, int);
|
2013-06-11 21:12:34 +04:00
|
|
|
/* Common signature for all zio decompress functions. */
|
2024-06-30 05:10:00 +03:00
|
|
|
typedef int zio_decompress_func_t(abd_t *src, abd_t *dst,
|
2008-11-20 23:01:55 +03:00
|
|
|
size_t s_len, size_t d_len, int);
|
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
2020-08-18 20:10:17 +03:00
|
|
|
/* Common signature for all zio decompress and get level functions. */
|
2024-06-30 05:10:00 +03:00
|
|
|
typedef int zio_decompresslevel_func_t(abd_t *src, abd_t *dst,
|
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
2020-08-18 20:10:17 +03:00
|
|
|
size_t s_len, size_t d_len, uint8_t *level);
|
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
/*
|
|
|
|
* Information about each compression function.
|
|
|
|
*/
|
2013-02-15 08:37:43 +04:00
|
|
|
typedef const struct zio_compress_info {
|
2022-04-19 21:38:30 +03:00
|
|
|
const char *ci_name;
|
2016-07-22 18:52:49 +03:00
|
|
|
int ci_level;
|
|
|
|
zio_compress_func_t *ci_compress;
|
|
|
|
zio_decompress_func_t *ci_decompress;
|
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
2020-08-18 20:10:17 +03:00
|
|
|
zio_decompresslevel_func_t *ci_decompress_level;
|
2008-11-20 23:01:55 +03:00
|
|
|
} zio_compress_info_t;
|
|
|
|
|
2022-10-01 01:34:39 +03:00
|
|
|
extern zio_compress_info_t zio_compress_table[ZIO_COMPRESS_FUNCTIONS];
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2013-01-23 13:54:30 +04:00
|
|
|
/*
|
|
|
|
* lz4 compression init & free
|
|
|
|
*/
|
|
|
|
extern void lz4_init(void);
|
|
|
|
extern void lz4_fini(void);
|
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
/*
|
|
|
|
* Compression routines.
|
|
|
|
*/
|
2024-06-30 05:10:00 +03:00
|
|
|
extern size_t zfs_lzjb_compress(abd_t *src, abd_t *dst, size_t s_len,
|
2024-06-29 04:16:50 +03:00
|
|
|
size_t d_len, int level);
|
2024-06-30 05:10:00 +03:00
|
|
|
extern int zfs_lzjb_decompress(abd_t *src, abd_t *dst, size_t s_len,
|
2024-06-29 04:16:50 +03:00
|
|
|
size_t d_len, int level);
|
2024-06-30 05:10:00 +03:00
|
|
|
extern size_t zfs_gzip_compress(abd_t *src, abd_t *dst, size_t s_len,
|
2024-06-29 04:16:50 +03:00
|
|
|
size_t d_len, int level);
|
2024-06-30 05:10:00 +03:00
|
|
|
extern int zfs_gzip_decompress(abd_t *src, abd_t *dst, size_t s_len,
|
2024-06-29 04:16:50 +03:00
|
|
|
size_t d_len, int level);
|
2024-06-30 05:10:00 +03:00
|
|
|
extern size_t zfs_zle_compress(abd_t *src, abd_t *dst, size_t s_len,
|
2024-06-29 04:16:50 +03:00
|
|
|
size_t d_len, int level);
|
2024-06-30 05:10:00 +03:00
|
|
|
extern int zfs_zle_decompress(abd_t *src, abd_t *dst, size_t s_len,
|
2024-06-29 04:16:50 +03:00
|
|
|
size_t d_len, int level);
|
2024-06-30 05:10:00 +03:00
|
|
|
extern size_t zfs_lz4_compress(abd_t *src, abd_t *dst, size_t s_len,
|
2024-06-29 04:16:50 +03:00
|
|
|
size_t d_len, int level);
|
2024-06-30 05:10:00 +03:00
|
|
|
extern int zfs_lz4_decompress(abd_t *src, abd_t *dst, size_t s_len,
|
2024-06-29 04:16:50 +03:00
|
|
|
size_t d_len, int level);
|
2019-06-13 23:14:35 +03:00
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
/*
|
|
|
|
* Compress and decompress data if necessary.
|
|
|
|
*/
|
2023-02-28 01:41:02 +03:00
|
|
|
extern size_t zio_compress_data(enum zio_compress c, abd_t *src, void **dst,
|
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
2020-08-18 20:10:17 +03:00
|
|
|
size_t s_len, uint8_t level);
|
2016-07-22 18:52:49 +03:00
|
|
|
extern int zio_decompress_data(enum zio_compress c, abd_t *src, void *dst,
|
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
2020-08-18 20:10:17 +03:00
|
|
|
size_t s_len, size_t d_len, uint8_t *level);
|
|
|
|
extern int zio_compress_to_feature(enum zio_compress comp);
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2024-06-30 05:10:00 +03:00
|
|
|
#define ZFS_COMPRESS_WRAP_DECL(name) \
|
|
|
|
size_t \
|
|
|
|
name(abd_t *src, abd_t *dst, size_t s_len, size_t d_len, int n) \
|
|
|
|
{ \
|
|
|
|
void *s_buf = abd_borrow_buf_copy(src, s_len); \
|
|
|
|
void *d_buf = abd_borrow_buf(dst, d_len); \
|
|
|
|
size_t c_len = name##_buf(s_buf, d_buf, s_len, d_len, n); \
|
|
|
|
abd_return_buf(src, s_buf, s_len); \
|
|
|
|
abd_return_buf_copy(dst, d_buf, d_len); \
|
|
|
|
return (c_len); \
|
|
|
|
}
|
|
|
|
#define ZFS_DECOMPRESS_WRAP_DECL(name) \
|
|
|
|
int \
|
|
|
|
name(abd_t *src, abd_t *dst, size_t s_len, size_t d_len, int n) \
|
|
|
|
{ \
|
|
|
|
void *s_buf = abd_borrow_buf_copy(src, s_len); \
|
|
|
|
void *d_buf = abd_borrow_buf(dst, d_len); \
|
|
|
|
int err = name##_buf(s_buf, d_buf, s_len, d_len, n); \
|
|
|
|
abd_return_buf(src, s_buf, s_len); \
|
|
|
|
abd_return_buf_copy(dst, d_buf, d_len); \
|
|
|
|
return (err); \
|
|
|
|
}
|
|
|
|
#define ZFS_DECOMPRESS_LEVEL_WRAP_DECL(name) \
|
|
|
|
int \
|
|
|
|
name(abd_t *src, abd_t *dst, size_t s_len, size_t d_len, uint8_t *n) \
|
|
|
|
{ \
|
|
|
|
void *s_buf = abd_borrow_buf_copy(src, s_len); \
|
|
|
|
void *d_buf = abd_borrow_buf(dst, d_len); \
|
|
|
|
int err = name##_buf(s_buf, d_buf, s_len, d_len, n); \
|
|
|
|
abd_return_buf(src, s_buf, s_len); \
|
|
|
|
abd_return_buf_copy(dst, d_buf, d_len); \
|
|
|
|
return (err); \
|
|
|
|
}
|
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* _SYS_ZIO_COMPRESS_H */
|