From 58c4ebeee879b4542c9b334b4bf9434b42aee179 Mon Sep 17 00:00:00 2001 From: Xin LI Date: Mon, 6 Oct 2014 05:54:39 +0000 Subject: [PATCH] 5176 lock contention on godfather zio Reviewed by: Adam Leventhal Reviewed by: Alex Reece Reviewed by: Christopher Siden Reviewed by: George Wilson Reviewed by: Richard Elling Reviewed by: Bayard Bell Approved by: Garrett D'Amore Author: Matthew Ahrens illumos/illumos-gate@6f834bc197c703a6568554c889157fb345bac079 --- cmd/zdb/zdb.c | 10 ++++++---- uts/common/fs/zfs/spa.c | 22 +++++++++++++++++----- uts/common/fs/zfs/sys/spa_impl.h | 3 ++- uts/common/fs/zfs/zio.c | 2 +- 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/cmd/zdb/zdb.c b/cmd/zdb/zdb.c index 2def6241b711..c886a9dc7298 100644 --- a/cmd/zdb/zdb.c +++ b/cmd/zdb/zdb.c @@ -2565,10 +2565,12 @@ dump_block_stats(spa_t *spa) * all async I/Os to complete. */ if (dump_opt['c']) { - (void) zio_wait(spa->spa_async_zio_root); - spa->spa_async_zio_root = zio_root(spa, NULL, NULL, - ZIO_FLAG_CANFAIL | ZIO_FLAG_SPECULATIVE | - ZIO_FLAG_GODFATHER); + for (int i = 0; i < max_ncpus; i++) { + (void) zio_wait(spa->spa_async_zio_root[i]); + spa->spa_async_zio_root[i] = zio_root(spa, NULL, NULL, + ZIO_FLAG_CANFAIL | ZIO_FLAG_SPECULATIVE | + ZIO_FLAG_GODFATHER); + } } if (zcb.zcb_haderrors) { diff --git a/uts/common/fs/zfs/spa.c b/uts/common/fs/zfs/spa.c index 72870b589891..be308e2f8730 100644 --- a/uts/common/fs/zfs/spa.c +++ b/uts/common/fs/zfs/spa.c @@ -1222,7 +1222,9 @@ spa_unload(spa_t *spa) * Wait for any outstanding async I/O to complete. */ if (spa->spa_async_zio_root != NULL) { - (void) zio_wait(spa->spa_async_zio_root); + for (int i = 0; i < max_ncpus; i++) + (void) zio_wait(spa->spa_async_zio_root[i]); + kmem_free(spa->spa_async_zio_root, max_ncpus * sizeof (void *)); spa->spa_async_zio_root = NULL; } @@ -2141,8 +2143,13 @@ spa_load_impl(spa_t *spa, uint64_t pool_guid, nvlist_t *config, /* * Create "The Godfather" zio to hold all async IOs */ - spa->spa_async_zio_root = zio_root(spa, NULL, NULL, - ZIO_FLAG_CANFAIL | ZIO_FLAG_SPECULATIVE | ZIO_FLAG_GODFATHER); + spa->spa_async_zio_root = kmem_alloc(max_ncpus * sizeof (void *), + KM_SLEEP); + for (int i = 0; i < max_ncpus; i++) { + spa->spa_async_zio_root[i] = zio_root(spa, NULL, NULL, + ZIO_FLAG_CANFAIL | ZIO_FLAG_SPECULATIVE | + ZIO_FLAG_GODFATHER); + } /* * Parse the configuration into a vdev tree. We explicitly set the @@ -3481,8 +3488,13 @@ spa_create(const char *pool, nvlist_t *nvroot, nvlist_t *props, /* * Create "The Godfather" zio to hold all async IOs */ - spa->spa_async_zio_root = zio_root(spa, NULL, NULL, - ZIO_FLAG_CANFAIL | ZIO_FLAG_SPECULATIVE | ZIO_FLAG_GODFATHER); + spa->spa_async_zio_root = kmem_alloc(max_ncpus * sizeof (void *), + KM_SLEEP); + for (int i = 0; i < max_ncpus; i++) { + spa->spa_async_zio_root[i] = zio_root(spa, NULL, NULL, + ZIO_FLAG_CANFAIL | ZIO_FLAG_SPECULATIVE | + ZIO_FLAG_GODFATHER); + } /* * Create the root vdev. diff --git a/uts/common/fs/zfs/sys/spa_impl.h b/uts/common/fs/zfs/sys/spa_impl.h index 739b95988c25..48b28eb5a139 100644 --- a/uts/common/fs/zfs/sys/spa_impl.h +++ b/uts/common/fs/zfs/sys/spa_impl.h @@ -204,7 +204,8 @@ struct spa { uint64_t spa_failmode; /* failure mode for the pool */ uint64_t spa_delegation; /* delegation on/off */ list_t spa_config_list; /* previous cache file(s) */ - zio_t *spa_async_zio_root; /* root of all async I/O */ + /* per-CPU array of root of async I/O: */ + zio_t **spa_async_zio_root; zio_t *spa_suspend_zio_root; /* root of all suspended I/O */ kmutex_t spa_suspend_lock; /* protects suspend_zio_root */ kcondvar_t spa_suspend_cv; /* notification of resume */ diff --git a/uts/common/fs/zfs/zio.c b/uts/common/fs/zfs/zio.c index d8833f67079d..b154cb639d5d 100644 --- a/uts/common/fs/zfs/zio.c +++ b/uts/common/fs/zfs/zio.c @@ -1367,7 +1367,7 @@ zio_nowait(zio_t *zio) */ spa_t *spa = zio->io_spa; - zio_add_child(spa->spa_async_zio_root, zio); + zio_add_child(spa->spa_async_zio_root[CPU_SEQID], zio); } zio_execute(zio);