mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2024-12-25 18:59:33 +03:00
ddt: simplify entry load and flags
Only a single bit is needed to track entry state, and definitely not two whole bytes. Some light refactoring in ddt_lookup() is needed to support this, but it reads a lot better 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
This commit is contained in:
parent
2cffddd405
commit
406562c563
@ -117,6 +117,10 @@ enum ddt_phys_type {
|
|||||||
/*
|
/*
|
||||||
* In-core ddt entry
|
* In-core ddt entry
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* State flags for dde_flags */
|
||||||
|
#define DDE_FLAG_LOADED (1 << 0) /* entry ready for use */
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
/* key must be first for ddt_key_compare */
|
/* key must be first for ddt_key_compare */
|
||||||
ddt_key_t dde_key;
|
ddt_key_t dde_key;
|
||||||
@ -125,8 +129,7 @@ typedef struct {
|
|||||||
struct abd *dde_repair_abd;
|
struct abd *dde_repair_abd;
|
||||||
ddt_type_t dde_type;
|
ddt_type_t dde_type;
|
||||||
ddt_class_t dde_class;
|
ddt_class_t dde_class;
|
||||||
uint8_t dde_loading;
|
uint8_t dde_flags;
|
||||||
uint8_t dde_loaded;
|
|
||||||
kcondvar_t dde_cv;
|
kcondvar_t dde_cv;
|
||||||
avl_node_t dde_node;
|
avl_node_t dde_node;
|
||||||
} ddt_entry_t;
|
} ddt_entry_t;
|
||||||
|
@ -448,7 +448,7 @@ ddt_alloc(const ddt_key_t *ddk)
|
|||||||
static void
|
static void
|
||||||
ddt_free(ddt_entry_t *dde)
|
ddt_free(ddt_entry_t *dde)
|
||||||
{
|
{
|
||||||
ASSERT(!dde->dde_loading);
|
ASSERT(dde->dde_flags & DDE_FLAG_LOADED);
|
||||||
|
|
||||||
for (int p = 0; p < DDT_PHYS_TYPES; p++)
|
for (int p = 0; p < DDT_PHYS_TYPES; p++)
|
||||||
ASSERT3P(dde->dde_lead_zio[p], ==, NULL);
|
ASSERT3P(dde->dde_lead_zio[p], ==, NULL);
|
||||||
@ -483,26 +483,37 @@ ddt_lookup(ddt_t *ddt, const blkptr_t *bp, boolean_t add)
|
|||||||
|
|
||||||
ddt_key_fill(&search, bp);
|
ddt_key_fill(&search, bp);
|
||||||
|
|
||||||
|
/* Find an existing live entry */
|
||||||
dde = avl_find(&ddt->ddt_tree, &search, &where);
|
dde = avl_find(&ddt->ddt_tree, &search, &where);
|
||||||
if (dde == NULL) {
|
if (dde != NULL) {
|
||||||
if (!add)
|
/* Found it. If it's already loaded, we can just return it. */
|
||||||
return (NULL);
|
if (dde->dde_flags & DDE_FLAG_LOADED)
|
||||||
dde = ddt_alloc(&search);
|
|
||||||
avl_insert(&ddt->ddt_tree, dde, where);
|
|
||||||
}
|
|
||||||
|
|
||||||
while (dde->dde_loading)
|
|
||||||
cv_wait(&dde->dde_cv, &ddt->ddt_lock);
|
|
||||||
|
|
||||||
if (dde->dde_loaded)
|
|
||||||
return (dde);
|
return (dde);
|
||||||
|
|
||||||
dde->dde_loading = B_TRUE;
|
/* Someone else is loading it, wait for it. */
|
||||||
|
while (!(dde->dde_flags & DDE_FLAG_LOADED))
|
||||||
|
cv_wait(&dde->dde_cv, &ddt->ddt_lock);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ddt_tree is now stable, so unlock and let everyone else keep moving.
|
||||||
|
* Anyone landing on this entry will find it without DDE_FLAG_LOADED,
|
||||||
|
* and go to sleep waiting for it above.
|
||||||
|
*/
|
||||||
ddt_exit(ddt);
|
ddt_exit(ddt);
|
||||||
|
|
||||||
|
/* Search all store objects for the entry. */
|
||||||
error = ENOENT;
|
error = ENOENT;
|
||||||
|
|
||||||
for (type = 0; type < DDT_TYPES; type++) {
|
for (type = 0; type < DDT_TYPES; type++) {
|
||||||
for (class = 0; class < DDT_CLASSES; class++) {
|
for (class = 0; class < DDT_CLASSES; class++) {
|
||||||
error = ddt_object_lookup(ddt, type, class, dde);
|
error = ddt_object_lookup(ddt, type, class, dde);
|
||||||
@ -517,17 +528,16 @@ ddt_lookup(ddt_t *ddt, const blkptr_t *bp, boolean_t add)
|
|||||||
|
|
||||||
ddt_enter(ddt);
|
ddt_enter(ddt);
|
||||||
|
|
||||||
ASSERT(!dde->dde_loaded);
|
ASSERT(!(dde->dde_flags & DDE_FLAG_LOADED));
|
||||||
ASSERT(dde->dde_loading);
|
|
||||||
|
|
||||||
dde->dde_type = type; /* will be DDT_TYPES if no entry found */
|
dde->dde_type = type; /* will be DDT_TYPES if no entry found */
|
||||||
dde->dde_class = class; /* will be DDT_CLASSES if no entry found */
|
dde->dde_class = class; /* will be DDT_CLASSES if no entry found */
|
||||||
dde->dde_loaded = B_TRUE;
|
|
||||||
dde->dde_loading = B_FALSE;
|
|
||||||
|
|
||||||
if (error == 0)
|
if (error == 0)
|
||||||
ddt_stat_update(ddt, dde, -1ULL);
|
ddt_stat_update(ddt, dde, -1ULL);
|
||||||
|
|
||||||
|
/* Entry loaded, everyone can proceed now */
|
||||||
|
dde->dde_flags |= DDE_FLAG_LOADED;
|
||||||
cv_broadcast(&dde->dde_cv);
|
cv_broadcast(&dde->dde_cv);
|
||||||
|
|
||||||
return (dde);
|
return (dde);
|
||||||
@ -812,8 +822,7 @@ ddt_sync_entry(ddt_t *ddt, ddt_entry_t *dde, dmu_tx_t *tx, uint64_t txg)
|
|||||||
ddt_class_t nclass;
|
ddt_class_t nclass;
|
||||||
uint64_t total_refcnt = 0;
|
uint64_t total_refcnt = 0;
|
||||||
|
|
||||||
ASSERT(dde->dde_loaded);
|
ASSERT(dde->dde_flags & DDE_FLAG_LOADED);
|
||||||
ASSERT(!dde->dde_loading);
|
|
||||||
|
|
||||||
for (int p = 0; p < DDT_PHYS_TYPES; p++, ddp++) {
|
for (int p = 0; p < DDT_PHYS_TYPES; p++, ddp++) {
|
||||||
ASSERT3P(dde->dde_lead_zio[p], ==, NULL);
|
ASSERT3P(dde->dde_lead_zio[p], ==, NULL);
|
||||||
|
Loading…
Reference in New Issue
Block a user