Test fsync/fdatasync/sync_file_range for the next i/o only if should_fsync(td)
[fio.git] / io_u.c
diff --git a/io_u.c b/io_u.c
index e12382b83f3c959d03cc7c8babea40b8947d02c7..c6d814bf6d8765904f74b9ac01c0dfeaf48cb77a 100644 (file)
--- a/io_u.c
+++ b/io_u.c
@@ -533,6 +533,7 @@ static unsigned int __get_next_buflen(struct thread_data *td, struct io_u *io_u,
        unsigned int buflen = 0;
        unsigned int minbs, maxbs;
        uint64_t frand_max, r;
+       bool power_2;
 
        assert(ddir_rw(ddir));
 
@@ -577,9 +578,11 @@ static unsigned int __get_next_buflen(struct thread_data *td, struct io_u *io_u,
                        }
                }
 
-               if (!td->o.bs_unaligned && is_power_of_2(minbs))
+               power_2 = is_power_of_2(minbs);
+               if (!td->o.bs_unaligned && power_2)
                        buflen &= ~(minbs - 1);
-
+               else if (!td->o.bs_unaligned && !power_2) 
+                       buflen -= buflen % minbs; 
        } while (!io_u_fits(td, io_u, buflen));
 
        return buflen;
@@ -643,7 +646,7 @@ int io_u_quiesce(struct thread_data *td)
        }
 
        while (td->io_u_in_flight) {
-               int fio_unused ret;
+               int ret;
 
                ret = io_u_queued_complete(td, 1);
                if (ret > 0)
@@ -714,28 +717,22 @@ static enum fio_ddir get_rw_ddir(struct thread_data *td)
        enum fio_ddir ddir;
 
        /*
-        * see if it's time to fsync
-        */
-       if (td->o.fsync_blocks &&
-          !(td->io_issues[DDIR_WRITE] % td->o.fsync_blocks) &&
-            td->io_issues[DDIR_WRITE] && should_fsync(td))
-               return DDIR_SYNC;
-
-       /*
-        * see if it's time to fdatasync
+        * See if it's time to fsync/fdatasync/sync_file_range first,
+        * and if not then move on to check regular I/Os.
         */
-       if (td->o.fdatasync_blocks &&
-          !(td->io_issues[DDIR_WRITE] % td->o.fdatasync_blocks) &&
-            td->io_issues[DDIR_WRITE] && should_fsync(td))
-               return DDIR_DATASYNC;
-
-       /*
-        * see if it's time to sync_file_range
-        */
-       if (td->sync_file_range_nr &&
-          !(td->io_issues[DDIR_WRITE] % td->sync_file_range_nr) &&
-            td->io_issues[DDIR_WRITE] && should_fsync(td))
-               return DDIR_SYNC_FILE_RANGE;
+       if (should_fsync(td)) {
+               if (td->o.fsync_blocks && td->io_issues[DDIR_WRITE] &&
+                   !(td->io_issues[DDIR_WRITE] % td->o.fsync_blocks))
+                       return DDIR_SYNC;
+
+               if (td->o.fdatasync_blocks && td->io_issues[DDIR_WRITE] &&
+                   !(td->io_issues[DDIR_WRITE] % td->o.fdatasync_blocks))
+                       return DDIR_DATASYNC;
+
+               if (td->sync_file_range_nr && td->io_issues[DDIR_WRITE] &&
+                   !(td->io_issues[DDIR_WRITE] % td->sync_file_range_nr))
+                       return DDIR_SYNC_FILE_RANGE;
+       }
 
        if (td_rw(td)) {
                /*
@@ -1734,6 +1731,9 @@ static void account_io_completion(struct thread_data *td, struct io_u *io_u,
        if (td->parent)
                td = td->parent;
 
+       if (!td->o.stats)
+               return;
+
        if (no_reduce)
                lusec = utime_since(&io_u->issue_time, &icd->time);
 
@@ -1960,7 +1960,7 @@ int io_u_queued_complete(struct thread_data *td, int min_evts)
        int ret, ddir;
        struct timespec ts = { .tv_sec = 0, .tv_nsec = 0, };
 
-       dprint(FD_IO, "io_u_queued_completed: min=%d\n", min_evts);
+       dprint(FD_IO, "io_u_queued_complete: min=%d\n", min_evts);
 
        if (!min_evts)
                tvp = &ts;
@@ -1994,7 +1994,7 @@ int io_u_queued_complete(struct thread_data *td, int min_evts)
  */
 void io_u_queued(struct thread_data *td, struct io_u *io_u)
 {
-       if (!td->o.disable_slat && ramp_time_over(td)) {
+       if (!td->o.disable_slat && ramp_time_over(td) && td->o.stats) {
                unsigned long slat_time;
 
                slat_time = utime_since(&io_u->start_time, &io_u->issue_time);