mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-22 02:27:36 +03:00
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:
+61
-61
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user