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

Sequential SPA-level rebuild for mirror and dRAID #5153

Closed
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
20 changes: 17 additions & 3 deletions cmd/zpool/zpool_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -5444,7 +5444,8 @@ print_scan_status(pool_scan_stat_t *ps)
zfs_nicenum(ps->pss_processed, processed_buf, sizeof (processed_buf));

assert(ps->pss_func == POOL_SCAN_SCRUB ||
ps->pss_func == POOL_SCAN_RESILVER);
ps->pss_func == POOL_SCAN_RESILVER ||
ps->pss_func == POOL_SCAN_REBUILD);
/*
* Scan is finished or canceled.
*/
Expand All @@ -5453,16 +5454,20 @@ print_scan_status(pool_scan_stat_t *ps)
char *fmt = NULL;

if (ps->pss_func == POOL_SCAN_SCRUB) {
fmt = gettext("scrub repaired %s in %lluh%um with "
fmt = gettext("scrub repaired %s in %lluh%um%us with "
"%llu errors on %s");
} else if (ps->pss_func == POOL_SCAN_RESILVER) {
fmt = gettext("resilvered %s in %lluh%um with "
fmt = gettext("resilvered %s in %lluh%um%us with "
"%llu errors on %s");
} else if (ps->pss_func == POOL_SCAN_REBUILD) {
fmt = "rebuilt %s in %lluh%um%us with "
Copy link
Member

Choose a reason for hiding this comment

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

This needs to use gettext().

"%llu errors on %s";
}
/* LINTED */
(void) printf(fmt, processed_buf,
(u_longlong_t)(minutes_taken / 60),
(uint_t)(minutes_taken % 60),
(uint_t)((end - start) % 60),
(u_longlong_t)ps->pss_errors,
ctime((time_t *)&end));
return;
Expand All @@ -5473,6 +5478,9 @@ print_scan_status(pool_scan_stat_t *ps)
} else if (ps->pss_func == POOL_SCAN_RESILVER) {
(void) printf(gettext("resilver canceled on %s"),
ctime(&end));
} else if (ps->pss_func == POOL_SCAN_REBUILD) {
(void) printf("rebuild canceled on %s",
Copy link
Member

Choose a reason for hiding this comment

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

This needs to use gettext().

ctime(&end));
}
return;
}
Expand All @@ -5488,6 +5496,9 @@ print_scan_status(pool_scan_stat_t *ps)
} else if (ps->pss_func == POOL_SCAN_RESILVER) {
(void) printf(gettext("resilver in progress since %s"),
ctime(&start));
} else if (ps->pss_func == POOL_SCAN_REBUILD) {
(void) printf("rebuild in progress since %s",
Copy link
Member

Choose a reason for hiding this comment

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

This needs to use gettext().

ctime(&start));
}

examined = ps->pss_examined ? ps->pss_examined : 1;
Expand Down Expand Up @@ -5526,6 +5537,9 @@ print_scan_status(pool_scan_stat_t *ps)
} else if (ps->pss_func == POOL_SCAN_SCRUB) {
(void) printf(gettext("\t%s repaired, %.2f%% done\n"),
processed_buf, 100 * fraction_done);
} else if (ps->pss_func == POOL_SCAN_REBUILD) {
(void) printf(" %s rebuilt, %.2f%% done\n",
Copy link
Member

Choose a reason for hiding this comment

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

This needs to use gettext(). Also, the whitespace at the front should be "\t".

processed_buf, 100 * fraction_done);
}
}

Expand Down
2 changes: 2 additions & 0 deletions include/sys/dsl_scan.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ typedef struct dsl_scan {
uint64_t scn_sync_start_time;
zio_t *scn_zio_root;

boolean_t scn_is_sequential;

/* for freeing blocks */
boolean_t scn_is_bptree;
boolean_t scn_async_destroying;
Expand Down
1 change: 1 addition & 0 deletions include/sys/fs/zfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,7 @@ typedef enum pool_scan_func {
POOL_SCAN_NONE,
POOL_SCAN_SCRUB,
POOL_SCAN_RESILVER,
POOL_SCAN_REBUILD, /* sequential SPA scan */
POOL_SCAN_FUNCS
} pool_scan_func_t;

Expand Down
1 change: 1 addition & 0 deletions include/sys/metaslab_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ struct metaslab {
boolean_t ms_condense_wanted;
boolean_t ms_loaded;
boolean_t ms_loading;
boolean_t ms_rebuilding;

int64_t ms_deferspace; /* sum of ms_defermap[] space */
uint64_t ms_weight; /* weight vs. others in group */
Expand Down
59 changes: 55 additions & 4 deletions module/zfs/dsl_scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ static scan_cb_t *scan_funcs[POOL_SCAN_FUNCS] = {
NULL,
dsl_scan_scrub_cb, /* POOL_SCAN_SCRUB */
dsl_scan_scrub_cb, /* POOL_SCAN_RESILVER */
NULL, /* POOL_SCAN_REBUILD */
};

int
Expand Down Expand Up @@ -338,7 +339,8 @@ dsl_scan_done(dsl_scan_t *scn, boolean_t complete, dmu_tx_t *tx)
spa_history_log_internal(spa, "scan done", tx,
"errors=%llu", spa_get_errlog_size(spa));

if (DSL_SCAN_IS_SCRUB_RESILVER(scn)) {
if (DSL_SCAN_IS_SCRUB_RESILVER(scn) ||
scn->scn_phys.scn_func == POOL_SCAN_REBUILD) {
Copy link
Member

Choose a reason for hiding this comment

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

This should probably be a DSL_SCAN_IS_REBUILD define for consistency.

mutex_enter(&spa->spa_scrub_lock);
while (spa->spa_scrub_inflight > 0) {
cv_wait(&spa->spa_scrub_io_cv,
Expand Down Expand Up @@ -1508,6 +1510,35 @@ dsl_scan_active(dsl_scan_t *scn)
return (used != 0);
}

static void
spa_scan_setup_sync(dmu_tx_t *tx)
{
dsl_scan_t *scn = dmu_tx_pool(tx)->dp_scan;
spa_t *spa = scn->scn_dp->dp_spa;

ASSERT(scn->scn_phys.scn_state != DSS_SCANNING);

bzero(&scn->scn_phys, sizeof (scn->scn_phys));
scn->scn_phys.scn_func = POOL_SCAN_REBUILD;
scn->scn_phys.scn_state = DSS_SCANNING;
scn->scn_phys.scn_min_txg = 0;
scn->scn_phys.scn_max_txg = tx->tx_txg;
scn->scn_phys.scn_ddt_class_max = 0;
scn->scn_phys.scn_start_time = gethrestime_sec();
scn->scn_phys.scn_errors = 0;
/* HH: or just the draid vd? */
scn->scn_phys.scn_to_examine = spa->spa_root_vdev->vdev_stat.vs_alloc;
scn->scn_restart_txg = 0;
scn->scn_done_txg = 0;

scn->scn_sync_start_time = gethrtime();
scn->scn_pausing = B_FALSE;
spa->spa_scrub_active = B_TRUE;
spa_scan_stat_init(spa);

spa->spa_scrub_started = B_TRUE;
}

void
dsl_scan_sync(dsl_pool_t *dp, dmu_tx_t *tx)
{
Expand All @@ -1523,11 +1554,18 @@ dsl_scan_sync(dsl_pool_t *dp, dmu_tx_t *tx)
if (dsl_scan_restarting(scn, tx)) {
pool_scan_func_t func = POOL_SCAN_SCRUB;
dsl_scan_done(scn, B_FALSE, tx);
if (vdev_resilver_needed(spa->spa_root_vdev, NULL, NULL))
func = POOL_SCAN_RESILVER;
if (vdev_resilver_needed(spa->spa_root_vdev, NULL, NULL)) {
if (scn->scn_is_sequential)
func = POOL_SCAN_REBUILD;
else
func = POOL_SCAN_RESILVER;
}
zfs_dbgmsg("restarting scan func=%u txg=%llu",
func, tx->tx_txg);
dsl_scan_setup_sync(&func, tx);
if (func == POOL_SCAN_REBUILD)
spa_scan_setup_sync(tx);
else
dsl_scan_setup_sync(&func, tx);
}

/*
Expand All @@ -1550,6 +1588,18 @@ dsl_scan_sync(dsl_pool_t *dp, dmu_tx_t *tx)
if (!scn->scn_async_stalled && !dsl_scan_active(scn))
return;

if (scn->scn_phys.scn_func == POOL_SCAN_REBUILD) {
Copy link
Member

Choose a reason for hiding this comment

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

This could then use DSL_SCAN_IS_REBUILD.

if (scn->scn_visited_this_txg == 19890604) {
Copy link
Member

Choose a reason for hiding this comment

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

Can you explain this magic number?

Copy link
Author

Choose a reason for hiding this comment

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

It's just a historical date that happened to pop up. Anything else would work, like the usual deadbeef babyface stuff.

ASSERT(!scn->scn_pausing);
/* finished with scan. */
dsl_scan_done(scn, B_TRUE, tx);
scn->scn_visited_this_txg = 0;
dsl_scan_sync_state(scn, tx);
}
/* HH: sequential scan is mostly handled in the open-context scan thread */
return;
}

scn->scn_visited_this_txg = 0;
scn->scn_pausing = B_FALSE;
scn->scn_sync_start_time = gethrtime();
Expand Down Expand Up @@ -1751,6 +1801,7 @@ dsl_resilver_restart(dsl_pool_t *dp, uint64_t txg)
} else {
dp->dp_scan->scn_restart_txg = txg;
}
dp->dp_scan->scn_is_sequential = B_FALSE;
zfs_dbgmsg("restarting resilver txg=%llu", txg);
}

Expand Down
6 changes: 4 additions & 2 deletions module/zfs/metaslab.c
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,7 @@ metaslab_block_alloc(metaslab_t *msp, uint64_t size)
range_tree_t *rt = msp->ms_tree;

VERIFY(!msp->ms_condensing);
VERIFY(!msp->ms_rebuilding);

start = msp->ms_ops->msop_alloc(msp, size);
if (start != -1ULL) {
Expand Down Expand Up @@ -2093,7 +2094,7 @@ metaslab_group_alloc(metaslab_group_t *mg, uint64_t psize, uint64_t asize,
/*
* If the selected metaslab is condensing, skip it.
*/
if (msp->ms_condensing)
if (msp->ms_condensing || msp->ms_rebuilding)
continue;

was_active = msp->ms_weight & METASLAB_ACTIVE_MASK;
Expand Down Expand Up @@ -2148,7 +2149,7 @@ metaslab_group_alloc(metaslab_group_t *mg, uint64_t psize, uint64_t asize,
* we can't manipulate this metaslab until it's committed
* to disk.
*/
if (msp->ms_condensing) {
if (msp->ms_condensing || msp->ms_rebuilding) {
mutex_exit(&msp->ms_lock);
continue;
}
Expand Down Expand Up @@ -2501,6 +2502,7 @@ metaslab_claim_dva(spa_t *spa, const dva_t *dva, uint64_t txg)
}

VERIFY(!msp->ms_condensing);
VERIFY(!msp->ms_rebuilding);
VERIFY0(P2PHASE(offset, 1ULL << vd->vdev_ashift));
VERIFY0(P2PHASE(size, 1ULL << vd->vdev_ashift));
VERIFY3U(range_tree_space(msp->ms_tree) - size, <=, msp->ms_size);
Expand Down
Loading