Skip to content

Commit

Permalink
compress: add "slack" compression option
Browse files Browse the repository at this point in the history
The "slack" option simply searches from the end of the block backwards
to the last non-zero byte, and sets that position as the "compressed"
size.

Signed-off-by: Rob Norris <[email protected]>
Sponsored-by: Klara, Inc.
Sponsored-by: Wasabi Technology, Inc.
  • Loading branch information
robn committed Jul 3, 2024
1 parent fd51786 commit 3dc96e0
Show file tree
Hide file tree
Showing 18 changed files with 171 additions and 13 deletions.
3 changes: 2 additions & 1 deletion cmd/dbufstat.in
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,8 @@ def get_compstring(c):
"ZIO_COMPRESS_GZIP_6", "ZIO_COMPRESS_GZIP_7",
"ZIO_COMPRESS_GZIP_8", "ZIO_COMPRESS_GZIP_9",
"ZIO_COMPRESS_ZLE", "ZIO_COMPRESS_LZ4",
"ZIO_COMPRESS_ZSTD", "ZIO_COMPRESS_FUNCTION"]
"ZIO_COMPRESS_ZSTD", "ZIO_COMPRESS_SLACK",
"ZIO_COMPRESS_FUNCTION"]

# If "-rr" option is used, don't convert to string representation
if raw > 1:
Expand Down
9 changes: 7 additions & 2 deletions cmd/zstream/zstream_decompress.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,16 @@ zstream_do_decompress(int argc, char *argv[])
type = ZIO_COMPRESS_LZJB;
else if (0 == strcmp("gzip", argv[i]))
type = ZIO_COMPRESS_GZIP_1;
else if (0 == strcmp("slack", argv[i]))
type = ZIO_COMPRESS_SLACK;
else if (0 == strcmp("zle", argv[i]))
type = ZIO_COMPRESS_ZLE;
else if (0 == strcmp("zstd", argv[i]))
type = ZIO_COMPRESS_ZSTD;
else {
fprintf(stderr, "Invalid compression type %s.\n"
"Supported types are off, lz4, lzjb, gzip, "
"zle, and zstd\n",
"Supported types are off, lz4, lzjb, "
"gzip, slack, zle, and zstd\n",
argv[i]);
exit(2);
}
Expand Down Expand Up @@ -278,6 +280,9 @@ zstream_do_decompress(int argc, char *argv[])
case ZIO_COMPRESS_ZSTD:
xfunc = zfs_zstd_decompress;
break;
case ZIO_COMPRESS_SLACK:
xfunc = slack_decompress;
break;
default:
assert(B_FALSE);
}
Expand Down
5 changes: 5 additions & 0 deletions include/sys/zio_compress.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ enum zio_compress {
ZIO_COMPRESS_ZLE,
ZIO_COMPRESS_LZ4,
ZIO_COMPRESS_ZSTD,
ZIO_COMPRESS_SLACK,
ZIO_COMPRESS_FUNCTIONS
};

Expand Down Expand Up @@ -179,6 +180,10 @@ 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 slack_compress(void *src, void *dst, size_t s_len, size_t d_len,
int level);
extern int slack_decompress(void *src, void *dst, size_t s_len, size_t d_len,
int level);

/*
* Compress and decompress data if necessary.
Expand Down
1 change: 1 addition & 0 deletions include/zfeature_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ typedef enum spa_feature {
SPA_FEATURE_AVZ_V2,
SPA_FEATURE_REDACTION_LIST_SPILL,
SPA_FEATURE_RAIDZ_EXPANSION,
SPA_FEATURE_SLACK_COMPRESS,
SPA_FEATURES
} spa_feature_t;

Expand Down
11 changes: 6 additions & 5 deletions lib/libzfs/libzfs.abi
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@
<elf-symbol name='fletcher_4_superscalar_ops' size='128' type='object-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
<elf-symbol name='libzfs_config_ops' size='16' type='object-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
<elf-symbol name='sa_protocol_names' size='16' type='object-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
<elf-symbol name='spa_feature_table' size='2296' type='object-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
<elf-symbol name='spa_feature_table' size='2352' type='object-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
<elf-symbol name='zfeature_checks_disable' size='4' type='object-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
<elf-symbol name='zfs_deleg_perm_tab' size='512' type='object-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
<elf-symbol name='zfs_history_event_names' size='328' type='object-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
Expand Down Expand Up @@ -5963,7 +5963,8 @@
<enumerator name='SPA_FEATURE_AVZ_V2' value='38'/>
<enumerator name='SPA_FEATURE_REDACTION_LIST_SPILL' value='39'/>
<enumerator name='SPA_FEATURE_RAIDZ_EXPANSION' value='40'/>
<enumerator name='SPA_FEATURES' value='41'/>
<enumerator name='SPA_FEATURE_SLACK_COMPRESS' value='41'/>
<enumerator name='SPA_FEATURES' value='42'/>
</enum-decl>
<typedef-decl name='spa_feature_t' type-id='33ecb627' id='d6618c78'/>
<qualified-type-def type-id='22cce67b' const='yes' id='d2816df0'/>
Expand Down Expand Up @@ -9025,8 +9026,8 @@
</function-decl>
</abi-instr>
<abi-instr address-size='64' path='module/zcommon/zfeature_common.c' language='LANG_C99'>
<array-type-def dimensions='1' type-id='83f29ca2' size-in-bits='18368' id='b93e4d14'>
<subrange length='41' type-id='7359adad' id='cb834f44'/>
<array-type-def dimensions='1' type-id='83f29ca2' size-in-bits='18816' id='b937914f'>
<subrange length='42' type-id='7359adad' id='cb7c937f'/>
</array-type-def>
<enum-decl name='zfeature_flags' id='6db816a4'>
<underlying-type type-id='9cac1fee'/>
Expand Down Expand Up @@ -9103,7 +9104,7 @@
<pointer-type-def type-id='611586a1' size-in-bits='64' id='2e243169'/>
<qualified-type-def type-id='eaa32e2f' const='yes' id='83be723c'/>
<pointer-type-def type-id='83be723c' size-in-bits='64' id='7acd98a2'/>
<var-decl name='spa_feature_table' type-id='b93e4d14' mangled-name='spa_feature_table' visibility='default' elf-symbol-id='spa_feature_table'/>
<var-decl name='spa_feature_table' type-id='b937914f' mangled-name='spa_feature_table' visibility='default' elf-symbol-id='spa_feature_table'/>
<var-decl name='zfeature_checks_disable' type-id='c19b74c3' mangled-name='zfeature_checks_disable' visibility='default' elf-symbol-id='zfeature_checks_disable'/>
<function-decl name='opendir' visibility='default' binding='global' size-in-bits='64'>
<parameter type-id='80f4b756'/>
Expand Down
1 change: 1 addition & 0 deletions lib/libzpool/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ nodist_libzpool_la_SOURCES = \
module/zfs/rrwlock.c \
module/zfs/sa.c \
module/zfs/sha2_zfs.c \
module/zfs/slack.c \
module/zfs/skein_zfs.c \
module/zfs/spa.c \
module/zfs/spa_checkpoint.c \
Expand Down
10 changes: 8 additions & 2 deletions man/man7/zfsprops.7
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@
.\" Copyright 2019 Joyent, Inc.
.\" Copyright (c) 2019, Kjeld Schouten-Lebbing
.\" Copyright (c) 2022 Hewlett Packard Enterprise Development LP.
.\" Copyright (c) 2024, Klara, Inc.
.\"
.Dd August 8, 2023
.Dd July 3, 2024
.Dt ZFSPROPS 7
.Os
.
Expand Down Expand Up @@ -796,7 +797,7 @@ 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 Ar N Ns | Ns Sy lz4 Ns | Ns Sy lzjb Ns | Ns Sy zle Ns | Ns Sy zstd Ns | Ns
.Sy zstd- Ns Ar N Ns | Ns Sy zstd-fast Ns | Ns Sy zstd-fast- Ns Ar N
.Sy zstd- Ns Ar N Ns | Ns Sy zstd-fast Ns | Ns Sy zstd-fast- Ns | Ns Sy slack Ns Ar N
.Xc
Controls the compression algorithm used for this dataset.
.Pp
Expand Down Expand Up @@ -906,6 +907,11 @@ The
.Sy zle
compression algorithm compresses runs of zeros.
.Pp
The
.Sy slack
compression algorithm removes runs of zeroes from the end of blocks.
It is useful when using very large block sizes with incompressible data.
.Pp
This property can also be referred to by its shortened column name
.Sy compress .
Changing this property affects only newly-written data.
Expand Down
39 changes: 37 additions & 2 deletions man/man7/zpool-features.7
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
.\" CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your
.\" own identifying information:
.\" Portions Copyright [yyyy] [name of copyright owner]
.\" Copyright (c) 2019, Klara Inc.
.\" Copyright (c) 2019, 2024, Klara, Inc.
.\" Copyright (c) 2019, Allan Jude
.\" Copyright (c) 2021, Colm Buckley <[email protected]>
.\"
.Dd June 23, 2022
.Dd July 3, 2024
.Dt ZPOOL-FEATURES 7
.Os
.
Expand Down Expand Up @@ -858,6 +858,41 @@ preventing hash collision attacks on systems with dedup.
.Pp
.checksum-spiel skein
.
.feature com.klarasystems slack_compress no extensible_dataset
.Sy slack
is a compression option that simply removes the trailing run of zero bytes at
the end of each block.
It is designed for when very large block sizes are used with to store largely
incompressible data.
Normally in this scenario
.Sy compress Ns = Ns Sy none
would be used,
but with large block sizes that can often leave a multi-megabyte run of zeroes
at the end of a block, adding memory and checksumming overhead.
.Pp
When the
.Sy slack_compress
feature is set to
.Sy enabled ,
the administrator can turn on
.Sy slack
compression of any dataset using
.Nm zfs Cm set Sy compress Ns = Ns Sy slack Ar dset
.Po see Xr zfs-set 8 Pc .
This feature becomes
.Sy active
once a
.Sy compress
property has been set to
.Sy slack ,
and will return to being
.Sy enabled
once all filesystems that have ever had their
.Sy compress
property set to
.Sy slack
are destroyed.
.
.feature com.delphix spacemap_histogram yes
This features allows ZFS to maintain more information about how free space
is organized within the pool.
Expand Down
1 change: 1 addition & 0 deletions man/man8/zstream.8
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ Valid compression types include
.Sy gzip ,
.Sy lz4 ,
.Sy lzjb ,
.Sy slack ,
.Sy zstd ,
and
.Sy zle .
Expand Down
1 change: 1 addition & 0 deletions module/Kbuild.in
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ ZFS_OBJS := \
sa.o \
sha2_zfs.o \
skein_zfs.o \
slack.o \
spa.o \
spa_checkpoint.o \
spa_config.o \
Expand Down
1 change: 1 addition & 0 deletions module/Makefile.bsd
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ SRCS+= abd.c \
sa.c \
sha2_zfs.c \
skein_zfs.c \
slack.c \
spa.c \
space_map.c \
space_reftree.c \
Expand Down
14 changes: 14 additions & 0 deletions module/zcommon/zfeature_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,20 @@ zpool_feature_init(void)
"Support for raidz expansion",
ZFEATURE_FLAG_MOS, ZFEATURE_TYPE_BOOLEAN, NULL, sfeatures);

{
{
static const spa_feature_t slack_deps[] = {
SPA_FEATURE_EXTENSIBLE_DATASET,
SPA_FEATURE_NONE
};
zfeature_register(SPA_FEATURE_SLACK_COMPRESS,
"com.klarasystems:slack_compress", "slack_compress",
"slack compression support",
ZFEATURE_FLAG_PER_DATASET, ZFEATURE_TYPE_BOOLEAN,
slack_deps, sfeatures);
}
}

zfs_mod_list_supported_free(sfeatures);
}

Expand Down
1 change: 1 addition & 0 deletions module/zcommon/zfs_prop.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ zfs_prop_init(void)
{ "gzip-9", ZIO_COMPRESS_GZIP_9 },
{ "zle", ZIO_COMPRESS_ZLE },
{ "lz4", ZIO_COMPRESS_LZ4 },
{ "slack", ZIO_COMPRESS_SLACK },
{ "zstd", ZIO_COMPRESS_ZSTD },
{ "zstd-fast",
ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_FAST_DEFAULT) },
Expand Down
67 changes: 67 additions & 0 deletions module/zfs/slack.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* 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
* or http://www.opensolaris.org/os/licensing.
* 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
*/

/*
* Copyright (c) 2024, Klara, Inc.
*/

#include <sys/zio_compress.h>
#include <sys/types.h>

/*
* Slack compression simply searches for the last non-zero byte in the buffer,
* and sets the position as the size of the "compressed" data.
*/

size_t
slack_compress(void *src, void *dst, size_t s_len, size_t d_len, int level)
{
(void) level;

ASSERT3U(s_len, >, 0);
ASSERT0(P2PHASE(s_len, sizeof (uint64_t)));

uint64_t *buf = (uint64_t *)src;

int p = (s_len / sizeof (uint64_t)) - 1;
for (; p >= 0; p--)
if (buf[p] != 0)
break;

if (p < 0)
return (s_len);

size_t c_len = (p + 1) * sizeof (uint64_t);
if (c_len > d_len)
return (s_len);

memcpy(dst, src, c_len);
return (c_len);
}

int
slack_decompress(void *src, void *dst, size_t s_len, size_t d_len, int level)
{
(void) level;
ASSERT3U(d_len, >=, s_len);
memcpy(dst, src, s_len);
return (0);
}
14 changes: 14 additions & 0 deletions module/zfs/zfs_ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -4670,6 +4670,20 @@ zfs_check_settable(const char *dsname, nvpair_t *pair, cred_t *cr)
}
spa_close(spa, FTAG);
}

if (compval == ZIO_COMPRESS_SLACK) {
spa_t *spa;

if ((err = spa_open(dsname, &spa, FTAG)) != 0)
return (err);

if (!spa_feature_is_enabled(spa,
SPA_FEATURE_SLACK_COMPRESS)) {
spa_close(spa, FTAG);
return (SET_ERROR(ENOTSUP));
}
spa_close(spa, FTAG);
}
}
break;

Expand Down
3 changes: 3 additions & 0 deletions module/zfs/zio_compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ zio_compress_info_t zio_compress_table[ZIO_COMPRESS_FUNCTIONS] = {
{"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},
{"slack", 0, slack_compress, slack_decompress, NULL },
};

uint8_t
Expand Down Expand Up @@ -218,6 +219,8 @@ zio_compress_to_feature(enum zio_compress comp)
switch (comp) {
case ZIO_COMPRESS_ZSTD:
return (SPA_FEATURE_ZSTD_COMPRESS);
case ZIO_COMPRESS_SLACK:
return (SPA_FEATURE_SLACK_COMPRESS);
default:
break;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/zfs-tests/include/properties.shlib
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

. $STF_SUITE/include/libtest.shlib

typeset -a compress_prop_vals=('off' 'lzjb' 'lz4' 'gzip' 'zle' 'zstd')
typeset -a compress_prop_vals=('off' 'lzjb' 'lz4' 'gzip' 'zle' 'zstd' 'slack')
typeset -a checksum_prop_vals=('on' 'off' 'fletcher2' 'fletcher4' 'sha256'
'noparity' 'sha512' 'skein' 'blake3')
if ! is_freebsd; then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,6 @@ if is_linux || is_freebsd; then
"feature@block_cloning"
"feature@vdev_zaps_v2"
"feature@raidz_expansion"
"feature@slack_compress"
)
fi

0 comments on commit 3dc96e0

Please sign in to comment.