[PATCH v4 2/8] zbd: fix write zone accounting
Shin'ichiro Kawasaki <[email protected]> Tue, 3 Mar 2026 10:31:53 +0900
| Newsgroups | org.kernel.vger.fio |
|---|---|
| Message-ID | <[email protected]> |
Currently, zbd_convert_to_write_zones() calls io_u_quiesce() when the number of write target zones hits one of the limits of write zones. This wait by io_u_quiesce() significantly degrade the performance. While I tried to remove the io_u_quiesce(), I observed that the test case 58 of t/zbd/test-zbd-support failed with null_blk devices that have a max_active_zones limit set. The failure cause is an incorrect write target zone accounting in zbd_convert_to_write_zones(). This function checks the current write target zones, and selects one of them as the next write target zone. After the zone selection, it locks the zone. However, when the zone is locked, another job such as a trim workload or a write workload with the zone_reset_threshold option might have already reset the zone and removed it from the write target zones array. This unexpected zone removal from the array caused an incorrect zone accounting and the test case failure. To avoid the incorrect zone accounting, call zbd_write_zone_get() after the selected zone gets locked. If the zone is removed from the write target zones array, the function adds the zone back to the array. Reviewed-by: Damien Le Moal <[email protected]> Signed-off-by: Shin'ichiro Kawasaki <[email protected]> --- zbd.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/zbd.c b/zbd.c index cf825601..2e600f97 100644 --- a/zbd.c +++ b/zbd.c @@ -1692,7 +1692,15 @@ retry: z = zbd_get_zone(f, zone_idx); zone_lock(td, f, z); - if (zbd_zone_remainder(z) >= min_bs) { + /* + * If the zone has remainder larger than min_bs, the next write + * fits the zone. In that case, choose the zone for the write. + * The zone might be already removed from zbdi->write_zones[] by + * other jobs at this moment. Call zbd_write_zone_get() to + * ensure that the zone for the write is in the array. + */ + if (zbd_zone_remainder(z) >= min_bs && + zbd_write_zone_get(td, f, z)) { need_zone_finish = false; goto out; } -- 2.49.0