From cdb2869d240f4de3c2d0feef2d2ab3bf73d5bf47 Mon Sep 17 00:00:00 2001 From: jxdking Date: Wed, 30 Jun 2021 01:20:35 +0000 Subject: [PATCH] Improvement based on code review. Switch back to tx_quiesce_more_cv for txg_kick(). Signed-off-by: jxdking --- module/zfs/txg.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/module/zfs/txg.c b/module/zfs/txg.c index c9eb84bbdb12..895fde2434a8 100644 --- a/module/zfs/txg.c +++ b/module/zfs/txg.c @@ -498,6 +498,14 @@ txg_wait_callbacks(dsl_pool_t *dp) taskq_wait_outstanding(tx->tx_commit_cb_taskq, 0); } +static boolean_t +txg_is_syncing(dsl_pool_t *dp) +{ + tx_state_t *tx = &dp->dp_tx; + ASSERT(MUTEX_HELD(&tx->tx_sync_lock)); + return (tx->tx_syncing_txg != 0); +} + static boolean_t txg_is_quiescing(dsl_pool_t *dp) { @@ -794,13 +802,26 @@ txg_kick(dsl_pool_t *dp, uint64_t txg) ASSERT(!dsl_pool_config_held(dp)); + /* Fast return path outside tx_sync_lock */ if (tx->tx_sync_txg_waiting >= txg) return; mutex_enter(&tx->tx_sync_lock); if (tx->tx_sync_txg_waiting < txg) { + + /* + * Always update tx_sync_txg_waiting, so that even if kick + * condition below is not applicable, this txg will be picked + * up by sync thread eventually. + */ tx->tx_sync_txg_waiting = txg; - cv_broadcast(&tx->tx_sync_more_cv); + + if (!txg_is_syncing(dp) && + !txg_is_quiescing(dp) && + tx->tx_quiesce_txg_waiting <= txg) { + tx->tx_quiesce_txg_waiting = txg + 1; + cv_broadcast(&tx->tx_quiesce_more_cv); + } } mutex_exit(&tx->tx_sync_lock); }