From 8cd5a3d32a95bbc34354dd5062e34d10ba12b0d1 Mon Sep 17 00:00:00 2001 From: jxdking Date: Tue, 13 Apr 2021 18:55:52 +0000 Subject: [PATCH] Code optimization and performance tweaking" Modified dsl_pool_wrlog_delay().Signed-off-by: jxdking --- module/zfs/dsl_pool.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/module/zfs/dsl_pool.c b/module/zfs/dsl_pool.c index 4a0b9d56e2ef..7ca4c85ce08f 100644 --- a/module/zfs/dsl_pool.c +++ b/module/zfs/dsl_pool.c @@ -612,10 +612,15 @@ dsl_pool_dirty_delta(dsl_pool_t *dp, int64_t delta) void dsl_pool_wrlog_delay(int64_t size, dsl_pool_t *dp, uint64_t txg) { + ASSERT3S(size, >=, 0); + ASSERT3U(txg, >=, TXG_INITIAL); + uint64_t last_total; + uint64_t txg_total; mutex_enter(&dp->dp_wrlog_lock); last_total = dp->dp_wrlog_total; + txg_total = dp->dp_wrlog_pertxg[txg & TXG_MASK]; dp->dp_wrlog_total += size; dp->dp_wrlog_pertxg[txg & TXG_MASK] += size; mutex_exit(&dp->dp_wrlog_lock); @@ -625,18 +630,26 @@ dsl_pool_wrlog_delay(int64_t size, dsl_pool_t *dp, uint64_t txg) "dp_wrlog_total: %llu", last_total); /* - * Current txg need to stay open to process current - * write transaction. We only can wait until txg - 1 - * is synced. + * Current txg needs to stay open to process current + * write transaction. Under heavy load, persumably txg - 2 + * is one syncing. Wait on it. */ - if (txg > 2) { - txg_wait_synced(dp, txg - 1); - } + txg_wait_synced(dp, txg - 2); } if (last_total >= zfs_wrlog_data_sync_percent * zfs_wrlog_data_max / 100) { - txg_kick(dp); + if (txg_total == last_total) { + // All data is in current txg, push it out + txg_kick(dp); + } else if (txg_total >= zfs_wrlog_data_max / 3) { + /* + * There is some data in previous txgs that are + * not synced yet. Hold it until current txg + * is 1/3 full as zfs_wrlog_data_max. + */ + txg_kick(dp); + } } } @@ -649,7 +662,7 @@ dsl_pool_wrlog_clear(dsl_pool_t *dp, uint64_t txg) mutex_exit(&dp->dp_wrlog_lock); dprintf("write log total cleared for txg: %llu, " - "dp_wrlog_total: %llu", txg, dp->dp_wrlog_total); + "remaining dp_wrlog_total: %llu", txg, dp->dp_wrlog_total); } #ifdef ZFS_DEBUG