Test fsync/fdatasync/sync_file_range for the next i/o only if should_fsync(td)
authorTomohiro Kusumi <tkusumi@tuxera.com>
Mon, 20 Mar 2017 21:28:47 +0000 (23:28 +0200)
committerJens Axboe <axboe@fb.com>
Tue, 21 Mar 2017 13:16:11 +0000 (07:16 -0600)
Checking an inline function should_fsync() first is better since
should_fsync() itself contains td_write() as a condition to return true,
and there's no need for non-write td to go through the rest of checks
when they result in false due to td->io_issues[DDIR_WRITE] being 0.

(This commit directly goes on top of the previous one)

Signed-off-by: Tomohiro Kusumi <tkusumi@tuxera.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
io_u.c

diff --git a/io_u.c b/io_u.c
index 1de35c8..c6d814b 100644 (file)
--- a/io_u.c
+++ b/io_u.c
@@ -717,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
+        * 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.fsync_blocks && td->io_issues[DDIR_WRITE] &&
-           !(td->io_issues[DDIR_WRITE] % td->o.fsync_blocks) &&
-           should_fsync(td))
-               return DDIR_SYNC;
-
-       /*
-        * see if it's time to fdatasync
-        */
-       if (td->o.fdatasync_blocks && td->io_issues[DDIR_WRITE] &&
-           !(td->io_issues[DDIR_WRITE] % td->o.fdatasync_blocks) &&
-           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->io_issues[DDIR_WRITE] % td->sync_file_range_nr) &&
-           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)) {
                /*