From cf0977ad72e97ae7d2aad1f0b6a2fe1a0209bbe7 Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Tue, 12 Jan 2021 15:25:52 -0700 Subject: 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 --- module/zfs/vdev.c | 39 +++++++++++++++++++++++++++++++++++++-- module/zfs/vdev_label.c | 3 ++- 2 files changed, 39 insertions(+), 3 deletions(-) (limited to 'module/zfs') 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); -- cgit v1.2.3