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

9185 metaslab_verify_weight_and_frag() shouldn't cause side-effects #9209

Closed
wants to merge 1 commit into from
Closed
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
14 changes: 14 additions & 0 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.


/* some extra verification for in-core tree if you can */
if (msp->ms_loaded) {
range_tree_stat_verify(msp->ms_allocatable);
Expand Down