diff options
author | Alan Somers <[email protected]> | 2021-01-12 15:25:52 -0700 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2021-01-26 19:36:51 -0800 |
commit | cf0977ad72e97ae7d2aad1f0b6a2fe1a0209bbe7 (patch) | |
tree | f27444b3a2240ae85d06e77e1ebcd105470cc780 | |
parent | 67874d5487f74c11503cb4f195c7a658f628b168 (diff) |
Parallelize vdev_validate
The runtime of vdev_validate is dominated by the disk accesses in
vdev_label_read_config. Speed it up by validating all vdevs in
parallel using a taskq.
Sponsored by: Axcient
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Alan Somers <[email protected]>
Closes #11470
-rw-r--r-- | include/sys/vdev_impl.h | 2 | ||||
-rw-r--r-- | module/zfs/vdev.c | 39 | ||||
-rw-r--r-- | module/zfs/vdev_label.c | 3 |
3 files changed, 41 insertions, 3 deletions
diff --git a/include/sys/vdev_impl.h b/include/sys/vdev_impl.h index c509d390f..db4fe1447 100644 --- a/include/sys/vdev_impl.h +++ b/include/sys/vdev_impl.h @@ -271,7 +271,9 @@ struct vdev { boolean_t vdev_nonrot; /* true if solid state */ int vdev_load_error; /* error on last load */ int vdev_open_error; /* error on last open */ + int vdev_validate_error; /* error on last validate */ kthread_t *vdev_open_thread; /* thread opening children */ + kthread_t *vdev_validate_thread; /* thread validating children */ uint64_t vdev_crtxg; /* txg when top-level was added */ /* diff --git a/module/zfs/vdev.c b/module/zfs/vdev.c index 018e48c38..36001e0a6 100644 --- a/module/zfs/vdev.c +++ b/module/zfs/vdev.c @@ -2136,6 +2136,16 @@ vdev_open(vdev_t *vd) return (0); } +static void +vdev_validate_child(void *arg) +{ + vdev_t *vd = arg; + + vd->vdev_validate_thread = curthread; + vd->vdev_validate_error = vdev_validate(vd); + vd->vdev_validate_thread = NULL; +} + /* * Called once the vdevs are all opened, this routine validates the label * contents. This needs to be done before vdev_load() so that we don't @@ -2150,18 +2160,43 @@ int vdev_validate(vdev_t *vd) { spa_t *spa = vd->vdev_spa; + taskq_t *tq = NULL; nvlist_t *label; uint64_t guid = 0, aux_guid = 0, top_guid; uint64_t state; nvlist_t *nvl; uint64_t txg; + int children = vd->vdev_children; if (vdev_validate_skip) return (0); - for (uint64_t c = 0; c < vd->vdev_children; c++) - if (vdev_validate(vd->vdev_child[c]) != 0) + if (children > 0) { + tq = taskq_create("vdev_validate", children, minclsyspri, + children, children, TASKQ_PREPOPULATE); + } + + for (uint64_t c = 0; c < children; c++) { + vdev_t *cvd = vd->vdev_child[c]; + + if (tq == NULL || vdev_uses_zvols(cvd)) { + vdev_validate_child(cvd); + } else { + VERIFY(taskq_dispatch(tq, vdev_validate_child, cvd, + TQ_SLEEP) != TASKQID_INVALID); + } + } + if (tq != NULL) { + taskq_wait(tq); + taskq_destroy(tq); + } + for (int c = 0; c < children; c++) { + int error = vd->vdev_child[c]->vdev_validate_error; + + if (error != 0) return (SET_ERROR(EBADF)); + } + /* * If the device has already failed, or was marked offline, don't do diff --git a/module/zfs/vdev_label.c b/module/zfs/vdev_label.c index d5966e1bd..04202a9f8 100644 --- a/module/zfs/vdev_label.c +++ b/module/zfs/vdev_label.c @@ -763,7 +763,8 @@ vdev_label_read_config(vdev_t *vd, uint64_t txg) int flags = ZIO_FLAG_CONFIG_WRITER | ZIO_FLAG_CANFAIL | ZIO_FLAG_SPECULATIVE; - ASSERT(spa_config_held(spa, SCL_STATE_ALL, RW_WRITER) == SCL_STATE_ALL); + ASSERT(vd->vdev_validate_thread == curthread || + spa_config_held(spa, SCL_STATE_ALL, RW_WRITER) == SCL_STATE_ALL); if (!vdev_readable(vd)) return (NULL); |