zdb: rework DDT block count and leak check to just count the blocks

The upcoming dedup features break the long held assumption that all
blocks on disk with a 'D' dedup bit will always be present in the DDT,
or will have the same set of DVA allocations on disk as in the DDT.

If the DDT is no longer a complete picture of all the dedup blocks that
will be and should be on disk, then it does us no good to walk and prime
it up front, since it won't necessarily match up with every block we'll
see anyway.

Instead, we rework things here to be more like the BRT checks. When we
see a dedup'd block, we look it up in the DDT, consume a refcount, and
for the second-or-later instances, count them as duplicates.

The DDT and BRT are moved ahead of the space accounting. This will
become important for the "flat" feature, which may need to count a
modified version of the block.

Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Co-authored-by: Allan Jude <allan@klarasystems.com>
Co-authored-by: Don Brady <don.brady@klarasystems.com>
Signed-off-by: Rob Norris <rob.norris@klarasystems.com>
Sponsored-by: Klara, Inc.
Sponsored-by: iXsystems, Inc.
Closes #15892
This commit is contained in:
Rob Norris
2024-06-18 14:11:11 +10:00
committed by Brian Behlendorf
parent 2b131d7345
commit d63f5d7e50
4 changed files with 200 additions and 129 deletions
+2 -6
View File
@@ -715,7 +715,7 @@ ddt_prefetch_all(spa_t *spa)
static int ddt_configure(ddt_t *ddt, boolean_t new);
ddt_entry_t *
ddt_lookup(ddt_t *ddt, const blkptr_t *bp, boolean_t add)
ddt_lookup(ddt_t *ddt, const blkptr_t *bp)
{
spa_t *spa = ddt->ddt_spa;
ddt_key_t search;
@@ -767,10 +767,6 @@ ddt_lookup(ddt_t *ddt, const blkptr_t *bp, boolean_t add)
return (dde);
}
/* Not found. */
if (!add)
return (NULL);
/* Time to make a new entry. */
dde = ddt_alloc(&search);
avl_insert(&ddt->ddt_tree, dde, where);
@@ -1502,7 +1498,7 @@ ddt_addref(spa_t *spa, const blkptr_t *bp)
ddt = ddt_select(spa, bp);
ddt_enter(ddt);
dde = ddt_lookup(ddt, bp, B_TRUE);
dde = ddt_lookup(ddt, bp);
/* Can be NULL if the entry for this block was pruned. */
if (dde == NULL) {
+2 -2
View File
@@ -3518,7 +3518,7 @@ zio_ddt_write(zio_t *zio)
ASSERT(!(zio->io_bp_override && (zio->io_flags & ZIO_FLAG_RAW)));
ddt_enter(ddt);
dde = ddt_lookup(ddt, bp, B_TRUE);
dde = ddt_lookup(ddt, bp);
if (dde == NULL) {
/* DDT size is over its quota so no new entries */
zp->zp_dedup = B_FALSE;
@@ -3598,7 +3598,7 @@ zio_ddt_free(zio_t *zio)
ASSERT(zio->io_child_type == ZIO_CHILD_LOGICAL);
ddt_enter(ddt);
freedde = dde = ddt_lookup(ddt, bp, B_TRUE);
freedde = dde = ddt_lookup(ddt, bp);
if (dde) {
ddp = ddt_phys_select(dde, bp);
if (ddp)