Skip to content

Commit

Permalink
ddt: typedef ddt_type and ddt_class
Browse files Browse the repository at this point in the history
Mostly for consistency, so the reader is less likely to wonder why these
things look different.

Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Rob Norris <[email protected]>
Sponsored-by: Klara, Inc.
Sponsored-by: iXsystems, Inc.
Closes openzfs#15887
  • Loading branch information
robn authored and lundman committed Mar 13, 2024
1 parent 833b85d commit bfe0146
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 56 deletions.
6 changes: 3 additions & 3 deletions cmd/zdb/zdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1906,7 +1906,7 @@ dump_dedup_ratio(const ddt_stat_t *dds)
}

static void
dump_ddt(ddt_t *ddt, enum ddt_type type, enum ddt_class class)
dump_ddt(ddt_t *ddt, ddt_type_t type, ddt_class_t class)
{
char name[DDT_NAMELEN];
ddt_entry_t dde;
Expand Down Expand Up @@ -1966,8 +1966,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];
for (enum ddt_type type = 0; type < DDT_TYPES; type++) {
for (enum ddt_class class = 0; class < DDT_CLASSES;
for (ddt_type_t type = 0; type < DDT_TYPES; type++) {
for (ddt_class_t class = 0; class < DDT_CLASSES;
class++) {
dump_ddt(ddt, type, class);
}
Expand Down
23 changes: 15 additions & 8 deletions include/sys/ddt.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,29 @@ struct abd;
/*
* On-disk DDT formats, in the desired search order (newest version first).
*/
enum ddt_type {
typedef enum {
DDT_TYPE_ZAP = 0,
DDT_TYPES
};
} ddt_type_t;

_Static_assert(DDT_TYPES <= UINT8_MAX,
"ddt_type_t must fit in a uint8_t");

/* New and updated entries recieve this type, see ddt_sync_entry() */
#define DDT_TYPE_DEFAULT (DDT_TYPE_ZAP)

/*
* DDT classes, in the desired search order (highest replication level first).
*/
enum ddt_class {
typedef enum {
DDT_CLASS_DITTO = 0,
DDT_CLASS_DUPLICATE,
DDT_CLASS_UNIQUE,
DDT_CLASSES
};
} ddt_class_t;

#define DDT_TYPE_CURRENT 0
_Static_assert(DDT_CLASSES < UINT8_MAX,
"ddt_class_t must fit in a uint8_t");

/*
* On-disk ddt entry: key (name) and physical storage (value).
Expand Down Expand Up @@ -116,8 +123,8 @@ struct ddt_entry {
ddt_phys_t dde_phys[DDT_PHYS_TYPES];
zio_t *dde_lead_zio[DDT_PHYS_TYPES];
struct abd *dde_repair_abd;
enum ddt_type dde_type;
enum ddt_class dde_class;
ddt_type_t dde_type;
ddt_class_t dde_class;
uint8_t dde_loading;
uint8_t dde_loaded;
kcondvar_t dde_cv;
Expand Down Expand Up @@ -182,7 +189,7 @@ extern ddt_entry_t *ddt_lookup(ddt_t *ddt, const blkptr_t *bp, boolean_t add);
extern void ddt_prefetch(spa_t *spa, const blkptr_t *bp);
extern void ddt_remove(ddt_t *ddt, ddt_entry_t *dde);

extern boolean_t ddt_class_contains(spa_t *spa, enum ddt_class max_class,
extern boolean_t ddt_class_contains(spa_t *spa, ddt_class_t max_class,
const blkptr_t *bp);

extern ddt_entry_t *ddt_repair_start(ddt_t *ddt, const blkptr_t *bp);
Expand Down
16 changes: 8 additions & 8 deletions include/sys/ddt_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ extern void ddt_key_fill(ddt_key_t *ddk, const blkptr_t *bp);

extern void ddt_stat_add(ddt_stat_t *dst, const ddt_stat_t *src, uint64_t neg);

extern void ddt_object_name(ddt_t *ddt, enum ddt_type type,
enum ddt_class clazz, char *name);
extern int ddt_object_walk(ddt_t *ddt, enum ddt_type type,
enum ddt_class clazz, uint64_t *walk, ddt_entry_t *dde);
extern int ddt_object_count(ddt_t *ddt, enum ddt_type type,
enum ddt_class clazz, uint64_t *count);
extern int ddt_object_info(ddt_t *ddt, enum ddt_type type,
enum ddt_class clazz, dmu_object_info_t *);
extern void ddt_object_name(ddt_t *ddt, ddt_type_t type, ddt_class_t clazz,
char *name);
extern int ddt_object_walk(ddt_t *ddt, ddt_type_t type, ddt_class_t clazz,
uint64_t *walk, ddt_entry_t *dde);
extern int ddt_object_count(ddt_t *ddt, ddt_type_t type, ddt_class_t clazz,
uint64_t *count);
extern int ddt_object_info(ddt_t *ddt, ddt_type_t type, ddt_class_t clazz,
dmu_object_info_t *);

#ifdef __cplusplus
}
Expand Down
62 changes: 31 additions & 31 deletions module/zfs/ddt.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ static const char *const ddt_class_name[DDT_CLASSES] = {
};

static void
ddt_object_create(ddt_t *ddt, enum ddt_type type, enum ddt_class class,
ddt_object_create(ddt_t *ddt, ddt_type_t type, ddt_class_t class,
dmu_tx_t *tx)
{
spa_t *spa = ddt->ddt_spa;
Expand All @@ -83,7 +83,7 @@ ddt_object_create(ddt_t *ddt, enum ddt_type type, enum ddt_class class,
}

static void
ddt_object_destroy(ddt_t *ddt, enum ddt_type type, enum ddt_class class,
ddt_object_destroy(ddt_t *ddt, ddt_type_t type, ddt_class_t class,
dmu_tx_t *tx)
{
spa_t *spa = ddt->ddt_spa;
Expand All @@ -107,7 +107,7 @@ ddt_object_destroy(ddt_t *ddt, enum ddt_type type, enum ddt_class class,
}

static int
ddt_object_load(ddt_t *ddt, enum ddt_type type, enum ddt_class class)
ddt_object_load(ddt_t *ddt, ddt_type_t type, ddt_class_t class)
{
ddt_object_t *ddo = &ddt->ddt_object_stats[type][class];
dmu_object_info_t doi;
Expand Down Expand Up @@ -147,7 +147,7 @@ ddt_object_load(ddt_t *ddt, enum ddt_type type, enum ddt_class class)
}

static void
ddt_object_sync(ddt_t *ddt, enum ddt_type type, enum ddt_class class,
ddt_object_sync(ddt_t *ddt, ddt_type_t type, ddt_class_t class,
dmu_tx_t *tx)
{
ddt_object_t *ddo = &ddt->ddt_object_stats[type][class];
Expand All @@ -173,13 +173,13 @@ ddt_object_sync(ddt_t *ddt, enum ddt_type type, enum ddt_class class,
}

static boolean_t
ddt_object_exists(ddt_t *ddt, enum ddt_type type, enum ddt_class class)
ddt_object_exists(ddt_t *ddt, ddt_type_t type, ddt_class_t class)
{
return (!!ddt->ddt_object[type][class]);
}

static int
ddt_object_lookup(ddt_t *ddt, enum ddt_type type, enum ddt_class class,
ddt_object_lookup(ddt_t *ddt, ddt_type_t type, ddt_class_t class,
ddt_entry_t *dde)
{
if (!ddt_object_exists(ddt, type, class))
Expand All @@ -190,7 +190,7 @@ ddt_object_lookup(ddt_t *ddt, enum ddt_type type, enum ddt_class class,
}

static void
ddt_object_prefetch(ddt_t *ddt, enum ddt_type type, enum ddt_class class,
ddt_object_prefetch(ddt_t *ddt, ddt_type_t type, ddt_class_t class,
ddt_entry_t *dde)
{
if (!ddt_object_exists(ddt, type, class))
Expand All @@ -201,7 +201,7 @@ ddt_object_prefetch(ddt_t *ddt, enum ddt_type type, enum ddt_class class,
}

static int
ddt_object_update(ddt_t *ddt, enum ddt_type type, enum ddt_class class,
ddt_object_update(ddt_t *ddt, ddt_type_t type, ddt_class_t class,
ddt_entry_t *dde, dmu_tx_t *tx)
{
ASSERT(ddt_object_exists(ddt, type, class));
Expand All @@ -211,7 +211,7 @@ ddt_object_update(ddt_t *ddt, enum ddt_type type, enum ddt_class class,
}

static int
ddt_object_remove(ddt_t *ddt, enum ddt_type type, enum ddt_class class,
ddt_object_remove(ddt_t *ddt, ddt_type_t type, ddt_class_t class,
ddt_entry_t *dde, dmu_tx_t *tx)
{
ASSERT(ddt_object_exists(ddt, type, class));
Expand All @@ -221,7 +221,7 @@ ddt_object_remove(ddt_t *ddt, enum ddt_type type, enum ddt_class class,
}

int
ddt_object_walk(ddt_t *ddt, enum ddt_type type, enum ddt_class class,
ddt_object_walk(ddt_t *ddt, ddt_type_t type, ddt_class_t class,
uint64_t *walk, ddt_entry_t *dde)
{
ASSERT(ddt_object_exists(ddt, type, class));
Expand All @@ -231,7 +231,7 @@ ddt_object_walk(ddt_t *ddt, enum ddt_type type, enum ddt_class class,
}

int
ddt_object_count(ddt_t *ddt, enum ddt_type type, enum ddt_class class,
ddt_object_count(ddt_t *ddt, ddt_type_t type, ddt_class_t class,
uint64_t *count)
{
ASSERT(ddt_object_exists(ddt, type, class));
Expand All @@ -241,7 +241,7 @@ ddt_object_count(ddt_t *ddt, enum ddt_type type, enum ddt_class class,
}

int
ddt_object_info(ddt_t *ddt, enum ddt_type type, enum ddt_class class,
ddt_object_info(ddt_t *ddt, ddt_type_t type, ddt_class_t class,
dmu_object_info_t *doi)
{
if (!ddt_object_exists(ddt, type, class))
Expand All @@ -252,7 +252,7 @@ ddt_object_info(ddt_t *ddt, enum ddt_type type, enum ddt_class class,
}

void
ddt_object_name(ddt_t *ddt, enum ddt_type type, enum ddt_class class,
ddt_object_name(ddt_t *ddt, ddt_type_t type, ddt_class_t class,
char *name)
{
(void) snprintf(name, DDT_NAMELEN, DMU_POOL_DDT,
Expand Down Expand Up @@ -460,8 +460,8 @@ ddt_lookup(ddt_t *ddt, const blkptr_t *bp, boolean_t add)
{
ddt_key_t search;
ddt_entry_t *dde;
enum ddt_type type;
enum ddt_class class;
ddt_type_t type;
ddt_class_t class;
avl_index_t where;
int error;

Expand Down Expand Up @@ -536,8 +536,8 @@ ddt_prefetch(spa_t *spa, const blkptr_t *bp)
ddt = ddt_select(spa, bp);
ddt_key_fill(&dde.dde_key, bp);

for (enum ddt_type type = 0; type < DDT_TYPES; type++) {
for (enum ddt_class class = 0; class < DDT_CLASSES; class++) {
for (ddt_type_t type = 0; type < DDT_TYPES; type++) {
for (ddt_class_t class = 0; class < DDT_CLASSES; class++) {
ddt_object_prefetch(ddt, type, class, &dde);
}
}
Expand Down Expand Up @@ -625,8 +625,8 @@ ddt_load(spa_t *spa)

for (enum zio_checksum c = 0; c < ZIO_CHECKSUM_FUNCTIONS; c++) {
ddt_t *ddt = spa->spa_ddt[c];
for (enum ddt_type type = 0; type < DDT_TYPES; type++) {
for (enum ddt_class class = 0; class < DDT_CLASSES;
for (ddt_type_t type = 0; type < DDT_TYPES; type++) {
for (ddt_class_t class = 0; class < DDT_CLASSES;
class++) {
error = ddt_object_load(ddt, type, class);
if (error != 0 && error != ENOENT)
Expand Down Expand Up @@ -657,7 +657,7 @@ ddt_unload(spa_t *spa)
}

boolean_t
ddt_class_contains(spa_t *spa, enum ddt_class max_class, const blkptr_t *bp)
ddt_class_contains(spa_t *spa, ddt_class_t max_class, const blkptr_t *bp)
{
ddt_t *ddt;
ddt_entry_t *dde;
Expand All @@ -673,8 +673,8 @@ ddt_class_contains(spa_t *spa, enum ddt_class max_class, const blkptr_t *bp)

ddt_key_fill(&(dde->dde_key), bp);

for (enum ddt_type type = 0; type < DDT_TYPES; type++) {
for (enum ddt_class class = 0; class <= max_class; class++) {
for (ddt_type_t type = 0; type < DDT_TYPES; type++) {
for (ddt_class_t class = 0; class <= max_class; class++) {
if (ddt_object_lookup(ddt, type, class, dde) == 0) {
kmem_cache_free(ddt_entry_cache, dde);
return (B_TRUE);
Expand All @@ -696,8 +696,8 @@ ddt_repair_start(ddt_t *ddt, const blkptr_t *bp)

dde = ddt_alloc(&ddk);

for (enum ddt_type type = 0; type < DDT_TYPES; type++) {
for (enum ddt_class class = 0; class < DDT_CLASSES; class++) {
for (ddt_type_t type = 0; type < DDT_TYPES; type++) {
for (ddt_class_t class = 0; class < DDT_CLASSES; class++) {
/*
* We can only do repair if there are multiple copies
* of the block. For anything in the UNIQUE class,
Expand Down Expand Up @@ -796,10 +796,10 @@ ddt_sync_entry(ddt_t *ddt, ddt_entry_t *dde, dmu_tx_t *tx, uint64_t txg)
dsl_pool_t *dp = ddt->ddt_spa->spa_dsl_pool;
ddt_phys_t *ddp = dde->dde_phys;
ddt_key_t *ddk = &dde->dde_key;
enum ddt_type otype = dde->dde_type;
enum ddt_type ntype = DDT_TYPE_CURRENT;
enum ddt_class oclass = dde->dde_class;
enum ddt_class nclass;
ddt_type_t otype = dde->dde_type;
ddt_type_t ntype = DDT_TYPE_DEFAULT;
ddt_class_t oclass = dde->dde_class;
ddt_class_t nclass;
uint64_t total_refcnt = 0;

ASSERT(dde->dde_loaded);
Expand Down Expand Up @@ -883,17 +883,17 @@ ddt_sync_table(ddt_t *ddt, dmu_tx_t *tx, uint64_t txg)
ddt_free(dde);
}

for (enum ddt_type type = 0; type < DDT_TYPES; type++) {
for (ddt_type_t type = 0; type < DDT_TYPES; type++) {
uint64_t add, count = 0;
for (enum ddt_class class = 0; class < DDT_CLASSES; class++) {
for (ddt_class_t class = 0; class < DDT_CLASSES; class++) {
if (ddt_object_exists(ddt, type, class)) {
ddt_object_sync(ddt, type, class, tx);
VERIFY0(ddt_object_count(ddt, type, class,
&add));
count += add;
}
}
for (enum ddt_class class = 0; class < DDT_CLASSES; class++) {
for (ddt_class_t class = 0; class < DDT_CLASSES; class++) {
if (count == 0 && ddt_object_exists(ddt, type, class))
ddt_object_destroy(ddt, type, class, tx);
}
Expand Down
8 changes: 4 additions & 4 deletions module/zfs/ddt_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ ddt_get_dedup_object_stats(spa_t *spa, ddt_object_t *ddo_total)
/* Sum the statistics we cached in ddt_object_sync(). */
for (enum zio_checksum c = 0; c < ZIO_CHECKSUM_FUNCTIONS; c++) {
ddt_t *ddt = spa->spa_ddt[c];
for (enum ddt_type type = 0; type < DDT_TYPES; type++) {
for (enum ddt_class class = 0; class < DDT_CLASSES;
for (ddt_type_t type = 0; type < DDT_TYPES; type++) {
for (ddt_class_t class = 0; class < DDT_CLASSES;
class++) {
ddt_object_t *ddo =
&ddt->ddt_object_stats[type][class];
Expand All @@ -156,8 +156,8 @@ ddt_get_dedup_histogram(spa_t *spa, ddt_histogram_t *ddh)
{
for (enum zio_checksum c = 0; c < ZIO_CHECKSUM_FUNCTIONS; c++) {
ddt_t *ddt = spa->spa_ddt[c];
for (enum ddt_type type = 0; type < DDT_TYPES && ddt; type++) {
for (enum ddt_class class = 0; class < DDT_CLASSES;
for (ddt_type_t type = 0; type < DDT_TYPES && ddt; type++) {
for (ddt_class_t class = 0; class < DDT_CLASSES;
class++) {
ddt_histogram_add(ddh,
&ddt->ddt_histogram_cache[type][class]);
Expand Down
4 changes: 2 additions & 2 deletions module/zfs/dsl_scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ static uint_t zfs_scan_checkpoint_intval = 7200; /* in seconds */
int zfs_scan_suspend_progress = 0; /* set to prevent scans from progressing */
static int zfs_no_scrub_io = B_FALSE; /* set to disable scrub i/o */
static int zfs_no_scrub_prefetch = B_FALSE; /* set to disable scrub prefetch */
static const enum ddt_class zfs_scrub_ddt_class_max = DDT_CLASS_DUPLICATE;
static const ddt_class_t zfs_scrub_ddt_class_max = DDT_CLASS_DUPLICATE;
/* max number of blocks to free in a single TXG */
static uint64_t zfs_async_block_max_blocks = UINT64_MAX;
/* max number of dedup blocks to free in a single TXG */
Expand Down Expand Up @@ -2962,7 +2962,7 @@ dsl_scan_ddt_entry(dsl_scan_t *scn, enum zio_checksum checksum,
* If there are N references to a deduped block, we don't want to scrub it
* N times -- ideally, we should scrub it exactly once.
*
* We leverage the fact that the dde's replication class (enum ddt_class)
* We leverage the fact that the dde's replication class (ddt_class_t)
* is ordered from highest replication class (DDT_CLASS_DITTO) to lowest
* (DDT_CLASS_UNIQUE) so that we may walk the DDT in that order.
*
Expand Down

0 comments on commit bfe0146

Please sign in to comment.