From cf0977ad72e97ae7d2aad1f0b6a2fe1a0209bbe7 Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Tue, 12 Jan 2021 15:25:52 -0700 Subject: [PATCH] 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 Signed-off-by: Alan Somers Closes #11470 --- include/sys/vdev_impl.h | 2 ++ module/zfs/vdev.c | 39 +++++++++++++++++++++++++++++++++++++-- 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 c509d390fc76..db4fe1447ebc 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 018e48c3867f..36001e0a6626 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 d5966e1bd459..04202a9f8960 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);