Skip to content

Commit

Permalink
ddt: include birth time in flat entries
Browse files Browse the repository at this point in the history
This is support for the upcoming "dedup prune" feature. By making the
change here, we avoid the need to take another on-disk format change
when that lands.

Sponsored-by: Klara, Inc.
Sponsored-by: iXsystems, Inc.
Co-authored-by: Don Brady <[email protected]>
Signed-off-by: Rob Norris <[email protected]>
  • Loading branch information
robn and don-brady committed Jun 14, 2024
1 parent a22b12f commit 05f309f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
4 changes: 4 additions & 0 deletions include/sys/ddt.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ typedef struct {

typedef struct {
ddt_phys_t ddpf_phys[1];
uint64_t ddpf_class_birth;
} ddt_phys_flat_t;

typedef struct {
Expand All @@ -162,6 +163,9 @@ typedef struct {
#define DDT_PHYS_FOR_COPIES(ddt, p) _DDT_PHYS_SWITCH(ddt, 0, p)
#define DDT_PHYS_IS_DITTO(ddt, p) _DDT_PHYS_SWITCH(ddt, 0, (p == 0))

#define DDT_PHYS_FLAT_CLASS_BIRTH(phys) \
(((ddt_phys_flat_t *)(phys))->ddpf_class_birth)

/*
* A "live" entry, holding changes to an entry made this txg, and other data to
* support loading, updating and repairing the entry.
Expand Down
19 changes: 11 additions & 8 deletions include/sys/ddt_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,17 @@ extern "C" {
#define DDT_DIR_FLAGS "flags"

/* Fill a lightweight entry from a live entry. */
#define DDT_ENTRY_TO_LIGHTWEIGHT(ddt, dde, ddlwe) do { \
memset((ddlwe), 0, sizeof (*ddlwe)); \
(ddlwe)->ddlwe_key = (dde)->dde_key; \
(ddlwe)->ddlwe_type = (dde)->dde_type; \
(ddlwe)->ddlwe_class = (dde)->dde_class; \
(ddlwe)->ddlwe_nphys = DDT_NPHYS(ddt); \
for (int p = 0; p < (ddlwe)->ddlwe_nphys; p++) \
(ddlwe)->ddlwe_phys[p] = (dde)->dde_phys[p]; \
#define DDT_ENTRY_TO_LIGHTWEIGHT(ddt, dde, ddlwe) do { \
memset((ddlwe), 0, sizeof (*ddlwe)); \
(ddlwe)->ddlwe_key = (dde)->dde_key; \
(ddlwe)->ddlwe_type = (dde)->dde_type; \
(ddlwe)->ddlwe_class = (dde)->dde_class; \
(ddlwe)->ddlwe_nphys = DDT_NPHYS(ddt); \
for (int p = 0; p < (ddlwe)->ddlwe_nphys; p++) \
(ddlwe)->ddlwe_phys[p] = (dde)->dde_phys[p]; \
if (ddt->ddt_flags & DDT_FLAG_FLAT) \
DDT_PHYS_FLAT_CLASS_BIRTH(&((ddlwe)->ddlwe_phys[0])) = \
DDT_PHYS_FLAT_CLASS_BIRTH(&((dde)->dde_phys[0])); \
} while (0)

/*
Expand Down
3 changes: 3 additions & 0 deletions module/zfs/ddt.c
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,9 @@ ddt_lookup(ddt_t *ddt, const blkptr_t *bp, boolean_t add)

/* Time to make a new entry. */
dde = ddt_alloc(ddt, &search);
if (ddt->ddt_flags & DDT_FLAG_FLAT)
DDT_PHYS_FLAT_CLASS_BIRTH(&dde->dde_phys[0]) =
gethrestime_sec();
avl_insert(&ddt->ddt_tree, dde, where);

/*
Expand Down

0 comments on commit 05f309f

Please sign in to comment.