]> git.proxmox.com Git - mirror_zfs.git/commitdiff
ddt: only create tables for dedup-capable checksums
authorRob Norris <rob.norris@klarasystems.com>
Thu, 1 Feb 2024 00:05:18 +0000 (11:05 +1100)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Thu, 15 Feb 2024 19:45:55 +0000 (11:45 -0800)
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 #15887

cmd/zdb/zdb.c
module/zfs/ddt.c

index 7f17de03d3cedf4679242ab6814f45f6c9a3dd86..4880c8048726882080935df9a12374b7239b4783 100644 (file)
@@ -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++) {
@@ -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)
@@ -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);
@@ -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]);
                        }
                }
index 3e278d702da57e31bdbcf054203f45128855656b..f22c79c50aa540fe3b1a6a971fc38e3c77cea2c2 100644 (file)
 #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;
 
@@ -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)]);
 }
 
@@ -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
@@ -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;
@@ -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)) {