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 <atkachuk@wasabi.com>
Reviewed-by: Alexander Motin <alexander.motin@TrueNAS.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #18482
This commit is contained in:
Brian Behlendorf
2026-05-02 09:55:39 -07:00
committed by Tony Hutter
parent 76fd64ac9f
commit fc87e269e2
+4 -1
View File
@@ -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);