Skip to content

Commit

Permalink
ddt: only create tables for dedup-capable checksums
Browse files Browse the repository at this point in the history
Most values in zio_checksum can never be used for dedup, partly because
the dedup= property only offers a limited list, but also some values (eg
ZIO_CHECKSUM_OFF) aren't real and will never be seen.

A true flag would be better than a hardcoded list, but thats more
cleanup elsewhere than I want to do right now.

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 openzfs#15887
  • Loading branch information
robn authored and behlendorf committed Feb 15, 2024
1 parent 406562c commit d961954
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
8 changes: 7 additions & 1 deletion cmd/zdb/zdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1965,6 +1965,8 @@ dump_all_ddts(spa_t *spa)

for (enum zio_checksum c = 0; c < ZIO_CHECKSUM_FUNCTIONS; c++) {
ddt_t *ddt = spa->spa_ddt[c];
if (!ddt)
continue;
for (ddt_type_t type = 0; type < DDT_TYPES; type++) {
for (ddt_class_t class = 0; class < DDT_CLASSES;
class++) {
Expand Down Expand Up @@ -6062,6 +6064,8 @@ zdb_ddt_leak_init(spa_t *spa, zdb_cb_t *zcb)
return;

ASSERT(ddt_phys_total_refcnt(&dde) > 1);
ddt_t *ddt = spa->spa_ddt[ddb.ddb_checksum];
VERIFY(ddt);

for (p = 0; p < DDT_PHYS_TYPES; p++, ddp++) {
if (ddp->ddp_phys_birth == 0)
Expand All @@ -6076,7 +6080,7 @@ zdb_ddt_leak_init(spa_t *spa, zdb_cb_t *zcb)
zcb->zcb_dedup_blocks++;
}
}
ddt_t *ddt = spa->spa_ddt[ddb.ddb_checksum];

ddt_enter(ddt);
VERIFY(ddt_lookup(ddt, &blk, B_TRUE) != NULL);
ddt_exit(ddt);
Expand Down Expand Up @@ -7949,6 +7953,8 @@ dump_mos_leaks(spa_t *spa)
for (uint64_t cksum = 0;
cksum < ZIO_CHECKSUM_FUNCTIONS; cksum++) {
ddt_t *ddt = spa->spa_ddt[cksum];
if (!ddt)
continue;
mos_obj_refd(ddt->ddt_object[type][class]);
}
}
Expand Down
21 changes: 19 additions & 2 deletions module/zfs/ddt.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@
#include <sys/dsl_scan.h>
#include <sys/abd.h>

/*
* These are the only checksums valid for dedup. They must match the list
* from dedup_table in zfs_prop.c
*/
#define DDT_CHECKSUM_VALID(c) \
(c == ZIO_CHECKSUM_SHA256 || c == ZIO_CHECKSUM_SHA512 || \
c == ZIO_CHECKSUM_SKEIN || c == ZIO_CHECKSUM_EDONR || \
c == ZIO_CHECKSUM_BLAKE3)

static kmem_cache_t *ddt_cache;
static kmem_cache_t *ddt_entry_cache;

Expand Down Expand Up @@ -400,6 +409,7 @@ ddt_phys_total_refcnt(const ddt_entry_t *dde)
ddt_t *
ddt_select(spa_t *spa, const blkptr_t *bp)
{
ASSERT(DDT_CHECKSUM_VALID(BP_GET_CHECKSUM(bp)));
return (spa->spa_ddt[BP_GET_CHECKSUM(bp)]);
}

Expand Down Expand Up @@ -629,8 +639,10 @@ ddt_create(spa_t *spa)
{
spa->spa_dedup_checksum = ZIO_DEDUPCHECKSUM;

for (enum zio_checksum c = 0; c < ZIO_CHECKSUM_FUNCTIONS; c++)
spa->spa_ddt[c] = ddt_table_alloc(spa, c);
for (enum zio_checksum c = 0; c < ZIO_CHECKSUM_FUNCTIONS; c++) {
if (DDT_CHECKSUM_VALID(c))
spa->spa_ddt[c] = ddt_table_alloc(spa, c);
}
}

int
Expand All @@ -648,6 +660,9 @@ ddt_load(spa_t *spa)
return (error == ENOENT ? 0 : error);

for (enum zio_checksum c = 0; c < ZIO_CHECKSUM_FUNCTIONS; c++) {
if (!DDT_CHECKSUM_VALID(c))
continue;

ddt_t *ddt = spa->spa_ddt[c];
for (ddt_type_t type = 0; type < DDT_TYPES; type++) {
for (ddt_class_t class = 0; class < DDT_CLASSES;
Expand Down Expand Up @@ -967,6 +982,8 @@ ddt_walk(spa_t *spa, ddt_bookmark_t *ddb, ddt_entry_t *dde)
do {
do {
ddt_t *ddt = spa->spa_ddt[ddb->ddb_checksum];
if (ddt == NULL)
continue;
int error = ENOENT;
if (ddt_object_exists(ddt, ddb->ddb_type,
ddb->ddb_class)) {
Expand Down

0 comments on commit d961954

Please sign in to comment.