engines/nvme: cache errno value
[fio.git] / io_u.c
diff --git a/io_u.c b/io_u.c
index 3f6c60ee887ef0e3aa74908fb73d0ddc36f32fbd..ca7ee68fde393e8cbd440a5deef9b830a1dbff41 100644 (file)
--- a/io_u.c
+++ b/io_u.c
@@ -513,6 +513,24 @@ static int get_next_offset(struct thread_data *td, struct io_u *io_u,
                return 1;
        }
 
+       /*
+        * For randtrimwrite, we decide whether to issue a trim or a write
+        * based on whether the offsets for the most recent trim and write
+        * operations match. If they don't match that means we just issued a
+        * new trim and the next operation should be a write. If they *do*
+        * match that means we just completed a trim+write pair and the next
+        * command should be a trim.
+        *
+        * This works fine for sequential workloads but for random workloads
+        * it's possible to complete a trim+write pair and then have the next
+        * randomly generated offset match the previous offset. If that happens
+        * we need to alter the offset for the last write operation in order
+        * to ensure that we issue a write operation the next time through.
+        */
+       if (td_randtrimwrite(td) && ddir == DDIR_TRIM &&
+           f->last_start[DDIR_TRIM] == io_u->offset)
+               f->last_start[DDIR_WRITE]--;
+
        io_u->verify_offset = io_u->offset;
        return 0;
 }
@@ -767,7 +785,15 @@ static enum fio_ddir get_rw_ddir(struct thread_data *td)
        else
                ddir = DDIR_INVAL;
 
-       td->rwmix_ddir = rate_ddir(td, ddir);
+       if (!should_check_rate(td)) {
+               /*
+                * avoid time-consuming call to utime_since_now() if rate checking
+                * isn't being used. this imrpoves IOPs 50%. See:
+                * https://github.com/axboe/fio/issues/1501#issuecomment-1418327049
+                */
+               td->rwmix_ddir = ddir;
+       } else
+               td->rwmix_ddir = rate_ddir(td, ddir);
        return td->rwmix_ddir;
 }
 
@@ -780,7 +806,7 @@ static void set_rw_ddir(struct thread_data *td, struct io_u *io_u)
 
        if (td_trimwrite(td)) {
                struct fio_file *f = io_u->file;
-               if (f->last_pos[DDIR_WRITE] == f->last_pos[DDIR_TRIM])
+               if (f->last_start[DDIR_WRITE] == f->last_start[DDIR_TRIM])
                        ddir = DDIR_TRIM;
                else
                        ddir = DDIR_WRITE;
@@ -958,10 +984,15 @@ static int fill_io_u(struct thread_data *td, struct io_u *io_u)
        offset = io_u->offset;
        if (td->o.zone_mode == ZONE_MODE_ZBD) {
                ret = zbd_adjust_block(td, io_u);
-               if (ret == io_u_eof)
+               if (ret == io_u_eof) {
+                       dprint(FD_IO, "zbd_adjust_block() returned io_u_eof\n");
                        return 1;
+               }
        }
 
+       if (td->o.fdp)
+               fdp_fill_dspec_data(td, io_u);
+
        if (io_u->offset + io_u->buflen > io_u->file->real_file_size) {
                dprint(FD_IO, "io_u %p, off=0x%llx + len=0x%llx exceeds file size=0x%llx\n",
                        io_u,
@@ -1978,7 +2009,7 @@ static void io_completed(struct thread_data *td, struct io_u **io_u_ptr,
        dprint_io_u(io_u, "complete");
 
        assert(io_u->flags & IO_U_F_FLIGHT);
-       io_u_clear(td, io_u, IO_U_F_FLIGHT | IO_U_F_BUSY_OK);
+       io_u_clear(td, io_u, IO_U_F_FLIGHT | IO_U_F_BUSY_OK | IO_U_F_PATTERN_DONE);
 
        /*
         * Mark IO ok to verify
@@ -2103,13 +2134,26 @@ static void ios_completed(struct thread_data *td,
        }
 }
 
+static void io_u_update_bytes_done(struct thread_data *td,
+                                  struct io_completion_data *icd)
+{
+       int ddir;
+
+       if (td->runstate == TD_VERIFYING) {
+               td->bytes_verified += icd->bytes_done[DDIR_READ];
+               return;
+       }
+
+       for (ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++)
+               td->bytes_done[ddir] += icd->bytes_done[ddir];
+}
+
 /*
  * Complete a single io_u for the sync engines.
  */
 int io_u_sync_complete(struct thread_data *td, struct io_u *io_u)
 {
        struct io_completion_data icd;
-       int ddir;
 
        init_icd(td, &icd, 1);
        io_completed(td, &io_u, &icd);
@@ -2122,8 +2166,7 @@ int io_u_sync_complete(struct thread_data *td, struct io_u *io_u)
                return -1;
        }
 
-       for (ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++)
-               td->bytes_done[ddir] += icd.bytes_done[ddir];
+       io_u_update_bytes_done(td, &icd);
 
        return 0;
 }
@@ -2135,7 +2178,7 @@ int io_u_queued_complete(struct thread_data *td, int min_evts)
 {
        struct io_completion_data icd;
        struct timespec *tvp = NULL;
-       int ret, ddir;
+       int ret;
        struct timespec ts = { .tv_sec = 0, .tv_nsec = 0, };
 
        dprint(FD_IO, "io_u_queued_complete: min=%d\n", min_evts);
@@ -2161,8 +2204,7 @@ int io_u_queued_complete(struct thread_data *td, int min_evts)
                return -1;
        }
 
-       for (ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++)
-               td->bytes_done[ddir] += icd.bytes_done[ddir];
+       io_u_update_bytes_done(td, &icd);
 
        return ret;
 }