From fc87e269e29151a232ac76a476161fecefdd9517 Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Sat, 2 May 2026 09:55:39 -0700 Subject: [PATCH] Initialize vr_last_txg for rebuild Only call txg_wait_synced() when rebuild IOs were issued for this metaslab. This is a small optimization since in practice the first metaslab is very likely to have allocations and cause vr_last_txg to be initialized. After this point when processing empty metaslabs txg_wait_synced() is called but with an already committed txg so it will not wait. Still it's better not to call txg_wait_synced() at all when it's not needed. Reviewed-by: Andriy Tkachuk Reviewed-by: Alexander Motin Signed-off-by: Brian Behlendorf Closes #18482 --- module/zfs/vdev_rebuild.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/module/zfs/vdev_rebuild.c b/module/zfs/vdev_rebuild.c index 384421206..599a3881a 100644 --- a/module/zfs/vdev_rebuild.c +++ b/module/zfs/vdev_rebuild.c @@ -823,6 +823,7 @@ vdev_rebuild_thread(void *arg) uint64_t limit = (arc_c_max / 2) / MAX(rvd->vdev_children, 1); vr->vr_bytes_inflight_max = MIN(limit, MAX(1ULL << 20, zfs_rebuild_vdev_limit * vd->vdev_children)); + vr->vr_last_txg = 0; /* * Removal of vdevs from the vdev tree may eliminate the need @@ -914,7 +915,9 @@ vdev_rebuild_thread(void *arg) * to avoid any interfering allocations. Otherwise, we might * see checksum errors after scrub. */ - txg_wait_synced(dp, vr->vr_last_txg); + if (vr->vr_last_txg != 0) + txg_wait_synced(dp, vr->vr_last_txg); + metaslab_enable(msp, B_FALSE, B_FALSE); spa_config_enter(spa, SCL_CONFIG, FTAG, RW_READER);