compress: standardise names of compression functions

This is mostly to make searching easier.

Sponsored-by: Klara, Inc.
Sponsored-by: Wasabi Technology, Inc.
Signed-off-by: Rob Norris <rob.norris@klarasystems.com>
This commit is contained in:
Rob Norris 2024-06-29 11:16:50 +10:00 committed by Tony Hutter
parent dd0c08f9c6
commit 522816498c
9 changed files with 122 additions and 106 deletions

View File

@ -153,22 +153,22 @@ extern void lz4_fini(void);
/*
* Compression routines.
*/
extern size_t lzjb_compress(void *src, void *dst, size_t s_len, size_t d_len,
int level);
extern int lzjb_decompress(void *src, void *dst, size_t s_len, size_t d_len,
int level);
extern size_t gzip_compress(void *src, void *dst, size_t s_len, size_t d_len,
int level);
extern int gzip_decompress(void *src, void *dst, size_t s_len, size_t d_len,
int level);
extern size_t zle_compress(void *src, void *dst, size_t s_len, size_t d_len,
int level);
extern int zle_decompress(void *src, void *dst, size_t s_len, size_t d_len,
int level);
extern size_t lz4_compress_zfs(void *src, void *dst, size_t s_len, size_t d_len,
int level);
extern int lz4_decompress_zfs(void *src, void *dst, size_t s_len, size_t d_len,
int level);
extern size_t zfs_lzjb_compress(void *src, void *dst, size_t s_len,
size_t d_len, int level);
extern int zfs_lzjb_decompress(void *src, void *dst, size_t s_len,
size_t d_len, int level);
extern size_t zfs_gzip_compress(void *src, void *dst, size_t s_len,
size_t d_len, int level);
extern int zfs_gzip_decompress(void *src, void *dst, size_t s_len,
size_t d_len, int level);
extern size_t zfs_zle_compress(void *src, void *dst, size_t s_len,
size_t d_len, int level);
extern int zfs_zle_decompress(void *src, void *dst, size_t s_len,
size_t d_len, int level);
extern size_t zfs_lz4_compress(void *src, void *dst, size_t s_len,
size_t d_len, int level);
extern int zfs_lz4_decompress(void *src, void *dst, size_t s_len,
size_t d_len, int level);
/*
* Compress and decompress data if necessary.

View File

@ -92,8 +92,6 @@ void zstd_fini(void);
size_t zfs_zstd_compress(void *s_start, void *d_start, size_t s_len,
size_t d_len, int level);
size_t zfs_zstd_compress_wrap(void *s_start, void *d_start, size_t s_len,
size_t d_len, int level);
int zfs_zstd_get_level(void *s_start, size_t s_len, uint8_t *level);
int zfs_zstd_decompress_level(void *s_start, void *d_start, size_t s_len,
size_t d_len, uint8_t *level);

View File

@ -2426,7 +2426,7 @@ get_receive_resume_token_impl(dsl_dataset_t *ds)
compressed = kmem_alloc(packed_size, KM_SLEEP);
/* Call compress function directly to avoid hole detection. */
compressed_size = gzip_compress(packed, compressed,
compressed_size = zfs_gzip_compress(packed, compressed,
packed_size, packed_size, 6);
zio_cksum_t cksum;

View File

@ -48,7 +48,8 @@ typedef uLongf zlen_t;
#endif
size_t
gzip_compress(void *s_start, void *d_start, size_t s_len, size_t d_len, int n)
zfs_gzip_compress(void *s_start, void *d_start, size_t s_len,
size_t d_len, int n)
{
int ret;
zlen_t dstlen = d_len;
@ -83,7 +84,8 @@ gzip_compress(void *s_start, void *d_start, size_t s_len, size_t d_len, int n)
}
int
gzip_decompress(void *s_start, void *d_start, size_t s_len, size_t d_len, int n)
zfs_gzip_decompress(void *s_start, void *d_start, size_t s_len,
size_t d_len, int n)
{
(void) n;
zlen_t dstlen = d_len;

View File

@ -53,7 +53,7 @@ int LZ4_uncompress_unknownOutputSize(const char *source, char *dest,
static kmem_cache_t *lz4_cache;
size_t
lz4_compress_zfs(void *s_start, void *d_start, size_t s_len,
zfs_lz4_compress(void *s_start, void *d_start, size_t s_len,
size_t d_len, int n)
{
(void) n;
@ -81,7 +81,7 @@ lz4_compress_zfs(void *s_start, void *d_start, size_t s_len,
}
int
lz4_decompress_zfs(void *s_start, void *d_start, size_t s_len,
zfs_lz4_decompress(void *s_start, void *d_start, size_t s_len,
size_t d_len, int n)
{
(void) n;

View File

@ -46,7 +46,8 @@
#define LEMPEL_SIZE 1024
size_t
lzjb_compress(void *s_start, void *d_start, size_t s_len, size_t d_len, int n)
zfs_lzjb_compress(void *s_start, void *d_start, size_t s_len,
size_t d_len, int n)
{
(void) n;
uchar_t *src = s_start;
@ -101,7 +102,8 @@ lzjb_compress(void *s_start, void *d_start, size_t s_len, size_t d_len, int n)
}
int
lzjb_decompress(void *s_start, void *d_start, size_t s_len, size_t d_len, int n)
zfs_lzjb_decompress(void *s_start, void *d_start,
size_t s_len, size_t d_len, int n)
{
(void) s_len, (void) n;
uchar_t *src = s_start;

View File

@ -54,24 +54,36 @@ static unsigned long zio_decompress_fail_fraction = 0;
* PART OF THE ON-DISK FORMAT.
*/
zio_compress_info_t zio_compress_table[ZIO_COMPRESS_FUNCTIONS] = {
{"inherit", 0, NULL, NULL, NULL},
{"on", 0, NULL, NULL, NULL},
{"uncompressed", 0, NULL, NULL, NULL},
{"lzjb", 0, lzjb_compress, lzjb_decompress, NULL},
{"empty", 0, NULL, NULL, NULL},
{"gzip-1", 1, gzip_compress, gzip_decompress, NULL},
{"gzip-2", 2, gzip_compress, gzip_decompress, NULL},
{"gzip-3", 3, gzip_compress, gzip_decompress, NULL},
{"gzip-4", 4, gzip_compress, gzip_decompress, NULL},
{"gzip-5", 5, gzip_compress, gzip_decompress, NULL},
{"gzip-6", 6, gzip_compress, gzip_decompress, NULL},
{"gzip-7", 7, gzip_compress, gzip_decompress, NULL},
{"gzip-8", 8, gzip_compress, gzip_decompress, NULL},
{"gzip-9", 9, gzip_compress, gzip_decompress, NULL},
{"zle", 64, zle_compress, zle_decompress, NULL},
{"lz4", 0, lz4_compress_zfs, lz4_decompress_zfs, NULL},
{"zstd", ZIO_ZSTD_LEVEL_DEFAULT, zfs_zstd_compress_wrap,
zfs_zstd_decompress, zfs_zstd_decompress_level},
{"inherit", 0, NULL, NULL, NULL},
{"on", 0, NULL, NULL, NULL},
{"uncompressed", 0, NULL, NULL, NULL},
{"lzjb", 0,
zfs_lzjb_compress, zfs_lzjb_decompress, NULL},
{"empty", 0, NULL, NULL, NULL},
{"gzip-1", 1,
zfs_gzip_compress, zfs_gzip_decompress, NULL},
{"gzip-2", 2,
zfs_gzip_compress, zfs_gzip_decompress, NULL},
{"gzip-3", 3,
zfs_gzip_compress, zfs_gzip_decompress, NULL},
{"gzip-4", 4,
zfs_gzip_compress, zfs_gzip_decompress, NULL},
{"gzip-5", 5,
zfs_gzip_compress, zfs_gzip_decompress, NULL},
{"gzip-6", 6,
zfs_gzip_compress, zfs_gzip_decompress, NULL},
{"gzip-7", 7,
zfs_gzip_compress, zfs_gzip_decompress, NULL},
{"gzip-8", 8,
zfs_gzip_compress, zfs_gzip_decompress, NULL},
{"gzip-9", 9,
zfs_gzip_compress, zfs_gzip_decompress, NULL},
{"zle", 64,
zfs_zle_compress, zfs_zle_decompress, NULL},
{"lz4", 0,
zfs_lz4_compress, zfs_lz4_decompress, NULL},
{"zstd", ZIO_ZSTD_LEVEL_DEFAULT,
zfs_zstd_compress, zfs_zstd_decompress, zfs_zstd_decompress_level},
};
uint8_t

View File

@ -35,7 +35,8 @@
#include <sys/zio_compress.h>
size_t
zle_compress(void *s_start, void *d_start, size_t s_len, size_t d_len, int n)
zfs_zle_compress(void *s_start, void *d_start, size_t s_len,
size_t d_len, int n)
{
uchar_t *src = s_start;
uchar_t *dst = d_start;
@ -65,7 +66,8 @@ zle_compress(void *s_start, void *d_start, size_t s_len, size_t d_len, int n)
}
int
zle_decompress(void *s_start, void *d_start, size_t s_len, size_t d_len, int n)
zfs_zle_decompress(void *s_start, void *d_start, size_t s_len,
size_t d_len, int n)
{
uchar_t *src = s_start;
uchar_t *dst = d_start;

View File

@ -429,68 +429,9 @@ zstd_enum_to_level(enum zio_zstd_levels level, int16_t *zstd_level)
return (1);
}
size_t
zfs_zstd_compress_wrap(void *s_start, void *d_start, size_t s_len, size_t d_len,
int level)
{
int16_t zstd_level;
if (zstd_enum_to_level(level, &zstd_level)) {
ZSTDSTAT_BUMP(zstd_stat_com_inval);
return (s_len);
}
/*
* A zstd early abort heuristic.
*
* - Zeroth, if this is <= zstd-3, or < zstd_abort_size (currently
* 128k), don't try any of this, just go.
* (because experimentally that was a reasonable cutoff for a perf win
* with tiny ratio change)
* - First, we try LZ4 compression, and if it doesn't early abort, we
* jump directly to whatever compression level we intended to try.
* - Second, we try zstd-1 - if that errors out (usually, but not
* exclusively, if it would overflow), we give up early.
*
* If it works, instead we go on and compress anyway.
*
* Why two passes? LZ4 alone gets you a lot of the way, but on highly
* compressible data, it was losing up to 8.5% of the compressed
* savings versus no early abort, and all the zstd-fast levels are
* worse indications on their own than LZ4, and don't improve the LZ4
* pass noticably if stacked like this.
*/
size_t actual_abort_size = zstd_abort_size;
if (zstd_earlyabort_pass > 0 && zstd_level >= zstd_cutoff_level &&
s_len >= actual_abort_size) {
int pass_len = 1;
pass_len = lz4_compress_zfs(s_start, d_start, s_len, d_len, 0);
if (pass_len < d_len) {
ZSTDSTAT_BUMP(zstd_stat_lz4pass_allowed);
goto keep_trying;
}
ZSTDSTAT_BUMP(zstd_stat_lz4pass_rejected);
pass_len = zfs_zstd_compress(s_start, d_start, s_len, d_len,
ZIO_ZSTD_LEVEL_1);
if (pass_len == s_len || pass_len <= 0 || pass_len > d_len) {
ZSTDSTAT_BUMP(zstd_stat_zstdpass_rejected);
return (s_len);
}
ZSTDSTAT_BUMP(zstd_stat_zstdpass_allowed);
} else {
ZSTDSTAT_BUMP(zstd_stat_passignored);
if (s_len < actual_abort_size) {
ZSTDSTAT_BUMP(zstd_stat_passignored_size);
}
}
keep_trying:
return (zfs_zstd_compress(s_start, d_start, s_len, d_len, level));
}
/* Compress block using zstd */
size_t
zfs_zstd_compress(void *s_start, void *d_start, size_t s_len, size_t d_len,
static size_t
zfs_zstd_compress_impl(void *s_start, void *d_start, size_t s_len, size_t d_len,
int level)
{
size_t c_len;
@ -594,6 +535,65 @@ zfs_zstd_compress(void *s_start, void *d_start, size_t s_len, size_t d_len,
return (c_len + sizeof (*hdr));
}
size_t
zfs_zstd_compress(void *s_start, void *d_start, size_t s_len, size_t d_len,
int level)
{
int16_t zstd_level;
if (zstd_enum_to_level(level, &zstd_level)) {
ZSTDSTAT_BUMP(zstd_stat_com_inval);
return (s_len);
}
/*
* A zstd early abort heuristic.
*
* - Zeroth, if this is <= zstd-3, or < zstd_abort_size (currently
* 128k), don't try any of this, just go.
* (because experimentally that was a reasonable cutoff for a perf win
* with tiny ratio change)
* - First, we try LZ4 compression, and if it doesn't early abort, we
* jump directly to whatever compression level we intended to try.
* - Second, we try zstd-1 - if that errors out (usually, but not
* exclusively, if it would overflow), we give up early.
*
* If it works, instead we go on and compress anyway.
*
* Why two passes? LZ4 alone gets you a lot of the way, but on highly
* compressible data, it was losing up to 8.5% of the compressed
* savings versus no early abort, and all the zstd-fast levels are
* worse indications on their own than LZ4, and don't improve the LZ4
* pass noticably if stacked like this.
*/
size_t actual_abort_size = zstd_abort_size;
if (zstd_earlyabort_pass > 0 && zstd_level >= zstd_cutoff_level &&
s_len >= actual_abort_size) {
int pass_len = 1;
pass_len = zfs_lz4_compress(s_start, d_start, s_len, d_len, 0);
if (pass_len < d_len) {
ZSTDSTAT_BUMP(zstd_stat_lz4pass_allowed);
goto keep_trying;
}
ZSTDSTAT_BUMP(zstd_stat_lz4pass_rejected);
pass_len = zfs_zstd_compress_impl(s_start, d_start, s_len,
d_len, ZIO_ZSTD_LEVEL_1);
if (pass_len == s_len || pass_len <= 0 || pass_len > d_len) {
ZSTDSTAT_BUMP(zstd_stat_zstdpass_rejected);
return (s_len);
}
ZSTDSTAT_BUMP(zstd_stat_zstdpass_allowed);
} else {
ZSTDSTAT_BUMP(zstd_stat_passignored);
if (s_len < actual_abort_size) {
ZSTDSTAT_BUMP(zstd_stat_passignored_size);
}
}
keep_trying:
return (zfs_zstd_compress_impl(s_start, d_start, s_len, d_len, level));
}
/* Decompress block using zstd and return its stored level */
int
zfs_zstd_decompress_level(void *s_start, void *d_start, size_t s_len,