ddt: move entry compression into ddt_zap

I think I can say with some confidence that anyone making a new storage
type in 2023 is doing their own thing with compression, not this.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Rob Norris <rob.norris@klarasystems.com>
Sponsored-by: Klara, Inc.
Sponsored-by: iXsystems, Inc.
Closes #15887
This commit is contained in:
Rob Norris 2023-06-30 12:48:45 +10:00 committed by Brian Behlendorf
parent d3bafe4554
commit 86e91c030c
3 changed files with 50 additions and 53 deletions

View File

@ -58,9 +58,6 @@ enum ddt_class {
#define DDT_TYPE_CURRENT 0 #define DDT_TYPE_CURRENT 0
#define DDT_COMPRESS_BYTEORDER_MASK 0x80
#define DDT_COMPRESS_FUNCTION_MASK 0x7f
/* /*
* On-disk ddt entry: key (name) and physical storage (value). * On-disk ddt entry: key (name) and physical storage (value).
*/ */
@ -92,8 +89,6 @@ typedef struct ddt_key {
#define DDK_GET_CRYPT(ddk) BF64_GET((ddk)->ddk_prop, 39, 1) #define DDK_GET_CRYPT(ddk) BF64_GET((ddk)->ddk_prop, 39, 1)
#define DDK_SET_CRYPT(ddk, x) BF64_SET((ddk)->ddk_prop, 39, 1, x) #define DDK_SET_CRYPT(ddk, x) BF64_SET((ddk)->ddk_prop, 39, 1, x)
#define DDT_KEY_WORDS (sizeof (ddt_key_t) / sizeof (uint64_t))
#define DDE_GET_NDVAS(dde) (DDK_GET_CRYPT(&dde->dde_key) \ #define DDE_GET_NDVAS(dde) (DDK_GET_CRYPT(&dde->dde_key) \
? SPA_DVAS_PER_BP - 1 : SPA_DVAS_PER_BP) ? SPA_DVAS_PER_BP - 1 : SPA_DVAS_PER_BP)
@ -220,9 +215,6 @@ extern void ddt_get_dedup_stats(spa_t *spa, ddt_stat_t *dds_total);
extern uint64_t ddt_get_dedup_dspace(spa_t *spa); extern uint64_t ddt_get_dedup_dspace(spa_t *spa);
extern uint64_t ddt_get_pool_dedup_ratio(spa_t *spa); extern uint64_t ddt_get_pool_dedup_ratio(spa_t *spa);
extern size_t ddt_compress(void *src, uchar_t *dst, size_t s_len, size_t d_len);
extern void ddt_decompress(uchar_t *src, void *dst, size_t s_len, size_t d_len);
extern ddt_t *ddt_select(spa_t *spa, const blkptr_t *bp); extern ddt_t *ddt_select(spa_t *spa, const blkptr_t *bp);
extern void ddt_enter(ddt_t *ddt); extern void ddt_enter(ddt_t *ddt);
extern void ddt_exit(ddt_t *ddt); extern void ddt_exit(ddt_t *ddt);

View File

@ -35,7 +35,6 @@
#include <sys/arc.h> #include <sys/arc.h>
#include <sys/dsl_pool.h> #include <sys/dsl_pool.h>
#include <sys/zio_checksum.h> #include <sys/zio_checksum.h>
#include <sys/zio_compress.h>
#include <sys/dsl_scan.h> #include <sys/dsl_scan.h>
#include <sys/abd.h> #include <sys/abd.h>
@ -554,47 +553,6 @@ ddt_get_pool_dedup_ratio(spa_t *spa)
return (dds_total.dds_ref_dsize * 100 / dds_total.dds_dsize); return (dds_total.dds_ref_dsize * 100 / dds_total.dds_dsize);
} }
size_t
ddt_compress(void *src, uchar_t *dst, size_t s_len, size_t d_len)
{
uchar_t *version = dst++;
int cpfunc = ZIO_COMPRESS_ZLE;
zio_compress_info_t *ci = &zio_compress_table[cpfunc];
size_t c_len;
ASSERT3U(d_len, >=, s_len + 1); /* no compression plus version byte */
c_len = ci->ci_compress(src, dst, s_len, d_len - 1, ci->ci_level);
if (c_len == s_len) {
cpfunc = ZIO_COMPRESS_OFF;
memcpy(dst, src, s_len);
}
*version = cpfunc;
if (ZFS_HOST_BYTEORDER)
*version |= DDT_COMPRESS_BYTEORDER_MASK;
return (c_len + 1);
}
void
ddt_decompress(uchar_t *src, void *dst, size_t s_len, size_t d_len)
{
uchar_t version = *src++;
int cpfunc = version & DDT_COMPRESS_FUNCTION_MASK;
zio_compress_info_t *ci = &zio_compress_table[cpfunc];
if (ci->ci_decompress != NULL)
(void) ci->ci_decompress(src, dst, s_len, d_len, ci->ci_level);
else
memcpy(dst, src, d_len);
if (((version & DDT_COMPRESS_BYTEORDER_MASK) != 0) !=
(ZFS_HOST_BYTEORDER != 0))
byteswap_uint64_array(dst, d_len);
}
ddt_t * ddt_t *
ddt_select(spa_t *spa, const blkptr_t *bp) ddt_select(spa_t *spa, const blkptr_t *bp)
{ {

View File

@ -30,10 +30,57 @@
#include <sys/ddt.h> #include <sys/ddt.h>
#include <sys/zap.h> #include <sys/zap.h>
#include <sys/dmu_tx.h> #include <sys/dmu_tx.h>
#include <sys/zio_compress.h>
static unsigned int ddt_zap_default_bs = 15; static unsigned int ddt_zap_default_bs = 15;
static unsigned int ddt_zap_default_ibs = 15; static unsigned int ddt_zap_default_ibs = 15;
#define DDT_ZAP_COMPRESS_BYTEORDER_MASK 0x80
#define DDT_ZAP_COMPRESS_FUNCTION_MASK 0x7f
#define DDT_KEY_WORDS (sizeof (ddt_key_t) / sizeof (uint64_t))
static size_t
ddt_zap_compress(void *src, uchar_t *dst, size_t s_len, size_t d_len)
{
uchar_t *version = dst++;
int cpfunc = ZIO_COMPRESS_ZLE;
zio_compress_info_t *ci = &zio_compress_table[cpfunc];
size_t c_len;
ASSERT3U(d_len, >=, s_len + 1); /* no compression plus version byte */
c_len = ci->ci_compress(src, dst, s_len, d_len - 1, ci->ci_level);
if (c_len == s_len) {
cpfunc = ZIO_COMPRESS_OFF;
memcpy(dst, src, s_len);
}
*version = cpfunc;
if (ZFS_HOST_BYTEORDER)
*version |= DDT_ZAP_COMPRESS_BYTEORDER_MASK;
return (c_len + 1);
}
static void
ddt_zap_decompress(uchar_t *src, void *dst, size_t s_len, size_t d_len)
{
uchar_t version = *src++;
int cpfunc = version & DDT_ZAP_COMPRESS_FUNCTION_MASK;
zio_compress_info_t *ci = &zio_compress_table[cpfunc];
if (ci->ci_decompress != NULL)
(void) ci->ci_decompress(src, dst, s_len, d_len, ci->ci_level);
else
memcpy(dst, src, d_len);
if (((version & DDT_ZAP_COMPRESS_BYTEORDER_MASK) != 0) !=
(ZFS_HOST_BYTEORDER != 0))
byteswap_uint64_array(dst, d_len);
}
static int static int
ddt_zap_create(objset_t *os, uint64_t *objectp, dmu_tx_t *tx, boolean_t prehash) ddt_zap_create(objset_t *os, uint64_t *objectp, dmu_tx_t *tx, boolean_t prehash)
{ {
@ -77,7 +124,7 @@ ddt_zap_lookup(objset_t *os, uint64_t object, ddt_entry_t *dde)
if (error) if (error)
goto out; goto out;
ddt_decompress(cbuf, dde->dde_phys, csize, sizeof (dde->dde_phys)); ddt_zap_decompress(cbuf, dde->dde_phys, csize, sizeof (dde->dde_phys));
out: out:
kmem_free(cbuf, sizeof (dde->dde_phys) + 1); kmem_free(cbuf, sizeof (dde->dde_phys) + 1);
@ -97,7 +144,7 @@ ddt_zap_update(objset_t *os, uint64_t object, ddt_entry_t *dde, dmu_tx_t *tx)
uchar_t cbuf[sizeof (dde->dde_phys) + 1]; uchar_t cbuf[sizeof (dde->dde_phys) + 1];
uint64_t csize; uint64_t csize;
csize = ddt_compress(dde->dde_phys, cbuf, csize = ddt_zap_compress(dde->dde_phys, cbuf,
sizeof (dde->dde_phys), sizeof (cbuf)); sizeof (dde->dde_phys), sizeof (cbuf));
return (zap_update_uint64(os, object, (uint64_t *)&dde->dde_key, return (zap_update_uint64(os, object, (uint64_t *)&dde->dde_key,
@ -138,7 +185,7 @@ ddt_zap_walk(objset_t *os, uint64_t object, ddt_entry_t *dde, uint64_t *walk)
DDT_KEY_WORDS, 1, csize, cbuf); DDT_KEY_WORDS, 1, csize, cbuf);
ASSERT0(error); ASSERT0(error);
if (error == 0) { if (error == 0) {
ddt_decompress(cbuf, dde->dde_phys, csize, ddt_zap_decompress(cbuf, dde->dde_phys, csize,
sizeof (dde->dde_phys)); sizeof (dde->dde_phys));
dde->dde_key = *(ddt_key_t *)za.za_name; dde->dde_key = *(ddt_key_t *)za.za_name;
} }