From 3f96645f7a0b26f018fc7386c4f9116526d24e0a Mon Sep 17 00:00:00 2001 From: Dmitry Fomichev Date: Tue, 6 Feb 2024 19:57:51 +0900 Subject: [PATCH] zbd: avoid assertions during sequential read I/O MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The following assert has been observed to be triggered if the I/O offset + I/O size exceeds the device capacity in a sequential read workload - “zbd.c:110: zone_lock: Assertion `f->min_zone <= nz && nz < f->max_zone' failed.” The code in zbd_zone_align_file_sizes() rounds down the I/O size to avoid these situations, but it is bypassed if td->o.td_ddir == TD_DDIR_READ. Avoid this issue by modifying zbd_zone_align_file_sizes() to round down the I/O size for read I/Os and leave the I/O offset untouched. Fixes: bfbdd35b3e8f ("Add support for zoned block devices") Signed-off-by: Dmitry Fomichev Reviewed-by: Shin'ichiro Kawasaki Tested-by: Shin'ichiro Kawasaki Link: https://lore.kernel.org/r/20240206105755.214891-2-dmitry.fomichev@wdc.com Signed-off-by: Vincent Fu --- zbd.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/zbd.c b/zbd.c index 61b5b688..7577472e 100644 --- a/zbd.c +++ b/zbd.c @@ -674,9 +674,20 @@ static bool zbd_zone_align_file_sizes(struct thread_data *td, return false; } + if (td->o.td_ddir == TD_DDIR_READ) { + z = zbd_offset_to_zone(f, f->file_offset + f->io_size); + new_end = z->start; + if (f->file_offset + f->io_size > new_end) { + log_info("%s: rounded io_size from %"PRIu64" to %"PRIu64"\n", + f->file_name, f->io_size, + new_end - f->file_offset); + f->io_size = new_end - f->file_offset; + } + return true; + } + z = zbd_offset_to_zone(f, f->file_offset); - if ((f->file_offset != z->start) && - (td->o.td_ddir != TD_DDIR_READ)) { + if (f->file_offset != z->start) { new_offset = zbd_zone_end(z); if (new_offset >= f->file_offset + f->io_size) { log_info("%s: io_size must be at least one zone\n", @@ -692,8 +703,7 @@ static bool zbd_zone_align_file_sizes(struct thread_data *td, z = zbd_offset_to_zone(f, f->file_offset + f->io_size); new_end = z->start; - if ((td->o.td_ddir != TD_DDIR_READ) && - (f->file_offset + f->io_size != new_end)) { + if (f->file_offset + f->io_size != new_end) { if (new_end <= f->file_offset) { log_info("%s: io_size must be at least one zone\n", f->file_name); -- 2.25.1