zbd: change some f->zbd_info conditionals to asserts
authorNiklas Cassel <niklas.cassel@wdc.com>
Mon, 14 Jun 2021 13:49:05 +0000 (13:49 +0000)
committerJens Axboe <axboe@kernel.dk>
Mon, 14 Jun 2021 14:54:55 +0000 (08:54 -0600)
Unfortunately, generic fio code calls some zbd_* functions unconditionally.
These functions will be called regardless if zonemode == ZONE_MODE_NONE,
ZONE_MODE_STRIDED or ZONE_MODE_ZBD, and cannot be optimized.

However, some functions are only called when zonemode == ZONE_MODE_ZBD.
Since f->zbd_info will always be non-NULL for a job with zonemode=zbd,
these functions can be optimized to not check if f->zbd_info is set.

Signed-off-by: Niklas Cassel <niklas.cassel@wdc.com>
Reviewed-by: Damien Le Moal <damien.lemoal@wdc.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
zbd.c

diff --git a/zbd.c b/zbd.c
index aab4d741365b952743422a9c1b16fad6716f6aab..8e99eb95dc6261101c48e6ea84ab5edf1601c316 100644 (file)
--- a/zbd.c
+++ b/zbd.c
@@ -808,8 +808,7 @@ int zbd_setup_files(struct thread_data *td)
                struct fio_zone_info *z;
                int zi;
 
                struct fio_zone_info *z;
                int zi;
 
-               if (!zbd)
-                       continue;
+               assert(zbd);
 
                f->min_zone = zbd_zone_idx(f, f->file_offset);
                f->max_zone = zbd_zone_idx(f, f->file_offset + f->io_size);
 
                f->min_zone = zbd_zone_idx(f, f->file_offset);
                f->max_zone = zbd_zone_idx(f, f->file_offset + f->io_size);
@@ -1470,8 +1469,7 @@ static void zbd_queue_io(struct thread_data *td, struct io_u *io_u, int q,
        uint32_t zone_idx;
        uint64_t zone_end;
 
        uint32_t zone_idx;
        uint64_t zone_end;
 
-       if (!zbd_info)
-               return;
+       assert(zbd_info);
 
        zone_idx = zbd_zone_idx(f, io_u->offset);
        assert(zone_idx < zbd_info->nr_zones);
 
        zone_idx = zbd_zone_idx(f, io_u->offset);
        assert(zone_idx < zbd_info->nr_zones);
@@ -1531,8 +1529,7 @@ static void zbd_put_io(struct thread_data *td, const struct io_u *io_u)
        struct fio_zone_info *z;
        uint32_t zone_idx;
 
        struct fio_zone_info *z;
        uint32_t zone_idx;
 
-       if (!zbd_info)
-               return;
+       assert(zbd_info);
 
        zone_idx = zbd_zone_idx(f, io_u->offset);
        assert(zone_idx < zbd_info->nr_zones);
 
        zone_idx = zbd_zone_idx(f, io_u->offset);
        assert(zone_idx < zbd_info->nr_zones);
@@ -1588,6 +1585,7 @@ void setup_zbd_zone_mode(struct thread_data *td, struct io_u *io_u)
 
        assert(td->o.zone_mode == ZONE_MODE_ZBD);
        assert(td->o.zone_size);
 
        assert(td->o.zone_mode == ZONE_MODE_ZBD);
        assert(td->o.zone_size);
+       assert(f->zbd_info);
 
        zone_idx = zbd_zone_idx(f, f->last_pos[ddir]);
        z = get_zone(f, zone_idx);
 
        zone_idx = zbd_zone_idx(f, f->last_pos[ddir]);
        z = get_zone(f, zone_idx);
@@ -1662,6 +1660,7 @@ enum fio_ddir zbd_adjust_ddir(struct thread_data *td, struct io_u *io_u,
         * devices with all empty zones. Overwrite the first I/O direction as
         * write to make sure data to read exists.
         */
         * devices with all empty zones. Overwrite the first I/O direction as
         * write to make sure data to read exists.
         */
+       assert(io_u->file->zbd_info);
        if (ddir != DDIR_READ || !td_rw(td))
                return ddir;
 
        if (ddir != DDIR_READ || !td_rw(td))
                return ddir;
 
@@ -1691,9 +1690,7 @@ enum io_u_action zbd_adjust_block(struct thread_data *td, struct io_u *io_u)
        uint64_t new_len;
        int64_t range;
 
        uint64_t new_len;
        int64_t range;
 
-       if (!f->zbd_info)
-               return io_u_accept;
-
+       assert(f->zbd_info);
        assert(min_bs);
        assert(is_valid_offset(f, io_u->offset));
        assert(io_u->buflen);
        assert(min_bs);
        assert(is_valid_offset(f, io_u->offset));
        assert(io_u->buflen);