From e474b3a1c893b9c9d18b6c66eb9db5eaf0a0f958 Mon Sep 17 00:00:00 2001 From: jxdking Date: Fri, 30 Apr 2021 19:55:51 +0000 Subject: [PATCH] Maximize txg size to improve throughput Only quiesce new transaction group when previous syncing is getting close to completion, so that quiescing completed just in time for it. That's the time when previous txg's dirty size shrinks to about 5% of dp_dirty_total. (current txg takes 95% of dp_dirty_total) Some other style fixes regarding code review. Signed-off-by: jxdking --- module/zfs/dmu_tx.c | 3 +-- module/zfs/dsl_pool.c | 17 ++++++++++++----- module/zfs/txg.c | 3 ++- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/module/zfs/dmu_tx.c b/module/zfs/dmu_tx.c index fcdd9c296a86..5c166afe57b7 100644 --- a/module/zfs/dmu_tx.c +++ b/module/zfs/dmu_tx.c @@ -1056,9 +1056,8 @@ dmu_tx_assign(dmu_tx_t *tx, uint64_t txg_how) txg_rele_to_quiesce(&tx->tx_txgh); - if (dsl_pool_need_dirty_sync(tx->tx_pool, tx->tx_txg)) { + if (dsl_pool_need_dirty_sync(tx->tx_pool, tx->tx_txg)) txg_kick(tx->tx_pool, tx->tx_txg); - } return (0); } diff --git a/module/zfs/dsl_pool.c b/module/zfs/dsl_pool.c index 42aff2b093cf..c36b4ea4d3a1 100644 --- a/module/zfs/dsl_pool.c +++ b/module/zfs/dsl_pool.c @@ -899,10 +899,9 @@ dsl_pool_need_dirty_delay(dsl_pool_t *dp) { uint64_t delay_min_bytes = zfs_dirty_data_max * zfs_delay_min_dirty_percent / 100; - uint64_t dirty; mutex_enter(&dp->dp_lock); - dirty = dp->dp_dirty_total; + uint64_t dirty = dp->dp_dirty_total; mutex_exit(&dp->dp_lock); return (dirty > delay_min_bytes); @@ -911,15 +910,23 @@ dsl_pool_need_dirty_delay(dsl_pool_t *dp) boolean_t dsl_pool_need_dirty_sync(dsl_pool_t *dp, uint64_t txg) { - uint64_t dirty; uint64_t dirty_min_bytes = zfs_dirty_data_max * zfs_dirty_data_sync_percent / 100; mutex_enter(&dp->dp_lock); - dirty = dp->dp_dirty_pertxg[txg & TXG_MASK]; + uint64_t dirty = dp->dp_dirty_pertxg[txg & TXG_MASK]; + uint64_t total = dp->dp_dirty_total; mutex_exit(&dp->dp_lock); - return (dirty > dirty_min_bytes); + /* + * Only quiesce new transaction group when previous syncing is + * getting close to completion, so that quiescing completed just + * in time for it. That's the time when previous txg's dirty size + * shrinks to about 5% of dp_dirty_total (current txg takes 95% + * of dp_dirty_total) + */ + return (dirty > dirty_min_bytes && + dirty * 100 > total * 95); } void diff --git a/module/zfs/txg.c b/module/zfs/txg.c index 53915feaed1d..d7977e4393fc 100644 --- a/module/zfs/txg.c +++ b/module/zfs/txg.c @@ -779,6 +779,7 @@ txg_wait_open(dsl_pool_t *dp, uint64_t txg, boolean_t should_quiesce) * If there isn't a txg quiescing in the pipeline, push the txg * through the pipeline by quiescing the open txg. * It is fine there is a txg still syncing. + * Pass in the txg number of the transaction that should be closed and synced. */ void txg_kick(dsl_pool_t *dp, uint64_t txg) @@ -788,7 +789,7 @@ txg_kick(dsl_pool_t *dp, uint64_t txg) ASSERT(!dsl_pool_config_held(dp)); mutex_enter(&tx->tx_sync_lock); - txg = txg == 0 ? tx->tx_open_txg : txg; + txg = (txg == 0 ? tx->tx_open_txg : txg); if (txg == tx->tx_open_txg && !txg_is_quiescing(dp) && tx->tx_quiesce_txg_waiting <= tx->tx_open_txg &&