Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't preload at or after final dirty txg #9216

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/sys/metaslab.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ uint64_t metaslab_allocated_space(metaslab_t *);

void metaslab_sync(metaslab_t *, uint64_t);
void metaslab_sync_done(metaslab_t *, uint64_t);
void metaslab_sync_reassess(metaslab_group_t *);
void metaslab_sync_reassess(metaslab_group_t *, uint64_t);
uint64_t metaslab_largest_allocatable(metaslab_t *);

/*
Expand Down
23 changes: 21 additions & 2 deletions module/zfs/metaslab.c
Original file line number Diff line number Diff line change
Expand Up @@ -1820,6 +1820,20 @@ metaslab_verify_weight_and_frag(metaslab_t *msp)
if (!spa_writeable(msp->ms_group->mg_vd->vdev_spa))
return;

/*
* This is a verification function and thus should not
* introduce any side-effects/mutations on the system.
* Unfortunately, calling metaslab_set_fragmentation()
* through metaslab_weight() later in this codepath
* can dirty an otherwise undirty metaslab and set
* ms_condense_wanted if the metaslab's spacemap hasn't
* been upgraded (e.g. after enabling SPACEMAP_HISTOGRAMS
* in a old pool). To avoid mutating system state, we skip
* those metaslabs.
*/
if (msp->ms_sm->sm_dbuf->db_size != sizeof (space_map_phys_t))
return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment explains this well, but this seems like this is exposing a poorly-designed corner of the code. Could we do something like pass a nodirty flag to metaslab_weight(), or have a metaslab_weight_impl(), which just recalculates the weight and doesn't check about condensing? That way, if metaslab_weight() decides to mutate the metaslab due to some other condition, the relevant code will be close by, and we won't have to add another check here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

realized this is actually part of #9209. copied my comment over there. This commit is good to go.


/* some extra verification for in-core tree if you can */
if (msp->ms_loaded) {
range_tree_stat_verify(msp->ms_allocatable);
Expand Down Expand Up @@ -3987,7 +4001,7 @@ metaslab_sync_done(metaslab_t *msp, uint64_t txg)
}

void
metaslab_sync_reassess(metaslab_group_t *mg)
metaslab_sync_reassess(metaslab_group_t *mg, uint64_t txg)
{
spa_t *spa = mg->mg_class->mc_spa;

Expand All @@ -4001,8 +4015,13 @@ metaslab_sync_reassess(metaslab_group_t *mg)
* is no longer active since we dirty metaslabs as we remove a
* a device, thus potentially making the metaslab group eligible
* for preloading.
*
* We also forbid preloading if the pool is at or beyond the final
* dirty txg. If we don't, and the metaslab is dirtied after it is
* loaded, we will be violating the "final dirty txg" invariant, which
* will cause an assertion failure in metaslab_sync.
*/
if (mg->mg_activation_count > 0) {
if (mg->mg_activation_count > 0 && spa_final_dirty_txg(spa) < txg) {
metaslab_group_preload(mg);
}
spa_config_exit(spa, SCL_ALLOC, FTAG);
Expand Down
2 changes: 1 addition & 1 deletion module/zfs/vdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -3263,7 +3263,7 @@ vdev_sync_done(vdev_t *vd, uint64_t txg)
metaslab_sync_done(msp, txg);

if (reassess)
metaslab_sync_reassess(vd->vdev_mg);
metaslab_sync_reassess(vd->vdev_mg, txg);
}

void
Expand Down