aboutsummaryrefslogtreecommitdiffstats
path: root/module/zfs/ddt_stats.c
diff options
context:
space:
mode:
authorRob Norris <[email protected]>2023-06-20 11:09:48 +1000
committerBrian Behlendorf <[email protected]>2024-08-16 12:02:39 -0700
commitf4aeb23f521cb4c5d94b103c926a3cc7b7be8abc (patch)
treea8f717cb7d080826c2cabef9f7d0d1c1f1add055 /module/zfs/ddt_stats.c
parent0ba5f503c5d644d28429c366fd1cdbd1c6c9b2b9 (diff)
ddt: add "flat phys" feature
Traditional dedup keeps a separate ddt_phys_t "type" for each possible count of DVAs (that is, copies=) parameter. Each of these are tracked independently of each other, and have their own set of DVAs. This leads to an (admittedly rare) situation where you can create as many as six copies of the data, by changing the copies= parameter between copying. This is both a waste of storage on disk, but also a waste of space in the stored DDT entries, since there never needs to be more than three DVAs to handle all possible values of copies=. This commit adds a new FDT feature, DDT_FLAG_FLAT. When active, only the first ddt_phys_t is used. Each time a block is written with the dedup bit set, this single phys is checked to see if it has enough DVAs to fulfill the request. If it does, the block is filled with the saved DVAs as normal. If not, an adjusted write is issued to create as many extra copies as are needed to fulfill the request, which are then saved into the entry too. Because a single phys is no longer an all-or-nothing, but can be transitioning from fewer to more DVAs, the write path now has to keep a copy of the previous "known good" DVA set so we can revert to it in case an error occurs. zio_ddt_write() has been restructured and heavily commented to make it much easier to see what's happening. Backwards compatibility is maintained simply by allocating four ddt_phys_t when the DDT_FLAG_FLAT flag is not set, and updating the phys selection macros to check the flag. In the old arrangement, each number of copies gets a whole phys, so it will always have either zero or all necessary DVAs filled, with no in-between, so the old behaviour naturally falls out of the new code. Reviewed-by: Alexander Motin <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Rob Norris <[email protected]> Co-authored-by: Don Brady <[email protected]> Sponsored-by: Klara, Inc. Sponsored-by: iXsystems, Inc. Closes #15893
Diffstat (limited to 'module/zfs/ddt_stats.c')
-rw-r--r--module/zfs/ddt_stats.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/module/zfs/ddt_stats.c b/module/zfs/ddt_stats.c
index 5449eca3a..6da77bbca 100644
--- a/module/zfs/ddt_stats.c
+++ b/module/zfs/ddt_stats.c
@@ -43,18 +43,22 @@ ddt_stat_generate(ddt_t *ddt, ddt_entry_t *dde, ddt_stat_t *dds)
memset(dds, 0, sizeof (*dds));
for (int p = 0; p < DDT_NPHYS(ddt); p++) {
- ddt_phys_t *ddp = &dde->dde_phys[p];
+ const ddt_univ_phys_t *ddp = dde->dde_phys;
+ ddt_phys_variant_t v = DDT_PHYS_VARIANT(ddt, p);
- uint64_t dsize = 0;
- uint64_t refcnt = ddp->ddp_refcnt;
-
- if (ddp->ddp_phys_birth == 0)
+ if (ddt_phys_birth(ddp, v) == 0)
continue;
- int ndvas = DDK_GET_CRYPT(&dde->dde_key) ?
- SPA_DVAS_PER_BP - 1 : SPA_DVAS_PER_BP;
+ int ndvas = ddt_phys_dva_count(ddp, v,
+ DDK_GET_CRYPT(&dde->dde_key));
+ const dva_t *dvas = (ddt->ddt_flags & DDT_FLAG_FLAT) ?
+ ddp->ddp_flat.ddp_dva : ddp->ddp_trad[p].ddp_dva;
+
+ uint64_t dsize = 0;
for (int d = 0; d < ndvas; d++)
- dsize += dva_get_dsize_sync(spa, &ddp->ddp_dva[d]);
+ dsize += dva_get_dsize_sync(spa, &dvas[d]);
+
+ uint64_t refcnt = ddt_phys_refcnt(ddp, v);
dds->dds_blocks += 1;
dds->dds_lsize += lsize;