diff options
author | Chris Mason <clm@fb.com> | 2020-02-12 06:18:30 -0800 |
---|---|---|
committer | Chris Mason <clm@fb.com> | 2020-02-12 06:18:30 -0800 |
commit | 88e08956e328749f7d8c93fdcac62a1221f66f88 (patch) | |
tree | d2909796e7efb23a551173cadc8704b4df0aa88c | |
parent | a03797b8e45d78cdd7a73f743c34d4d1e4bef063 (diff) | |
download | simoop-88e08956e328749f7d8c93fdcac62a1221f66f88.tar.gz |
simoop: move sync_file_range calls under -U/--writethrough
Make these optional
Signed-off-by: Chris Mason <clm@fb.com>
-rw-r--r-- | simoop.c | 36 |
1 files changed, 24 insertions, 12 deletions
@@ -83,6 +83,7 @@ static int du_threads = 0; static unsigned long thinking_mem = 128 * 1024 * 1024UL; /* should we fsync sometimes? */ static int funksync = 0; +static int writethrough = 0; /* are we just appending bytes onto the ends of the working set files */ static int append_mode = 0; static int truncate_original = 0; @@ -518,6 +519,7 @@ static void print_usage(void) "\t-z (--zallocate): use fallocate for initial file creation\n" "\t-N (--nocleanup): don't cleanup temp files from the last run\n" "\t-e (--erase): delete the data files at the start of the run\n" + "\t-U (--writethrough): sync_file_range every write\n" "\t dir1 [dir2 ... dirN]\n" "\nall sizes are in bytes k,m,g,t modifiers can be used\n" ); @@ -609,6 +611,9 @@ static void parse_options(int ac, char **av) case 'O': odirect = 1; break; + case 'U': + writethrough = 1; + break; case 'v': verify_writes = 1; break; @@ -1068,6 +1073,21 @@ static void maybe_toggle_odirect(int fd, unsigned long start, } } +static void maybe_write_through(int fd, loff_t start, loff_t bytes) +{ + int ret; + + if (!writethrough) + return; + + ret = sync_file_range(fd, start, bytes, + SYNC_FILE_RANGE_WRITE|SYNC_FILE_RANGE_WAIT_AFTER); + if (ret) { + perror("sync_file_range"); + exit(1); + } +} + static void send_pwrite(int fd, char *buf, loff_t start, ssize_t bytes) { ssize_t this_write; @@ -1082,7 +1102,6 @@ static void send_pwrite(int fd, char *buf, loff_t start, ssize_t bytes) */ this_write = VERIFY_ALIGNMENT; while (this_write > 0) { - int ret2; if (this_write > bytes) break; @@ -1093,11 +1112,7 @@ static void send_pwrite(int fd, char *buf, loff_t start, ssize_t bytes) exit(1); } - ret2 = sync_file_range(fd, start, this_write, SYNC_FILE_RANGE_WRITE|SYNC_FILE_RANGE_WAIT_AFTER); - if (ret2) { - perror("sync_file_range"); - exit(1); - } + maybe_write_through(fd, start, this_write); start += ret; this_write -= ret; @@ -1119,11 +1134,7 @@ static void send_pwrite(int fd, char *buf, loff_t start, ssize_t bytes) bytes -= ret; buf += ret; } - ret = sync_file_range(fd, start, bytes, SYNC_FILE_RANGE_WRITE|SYNC_FILE_RANGE_WAIT_AFTER); - if (ret) { - perror("sync_file_range"); - exit(1); - } + maybe_write_through(fd, start, bytes); maybe_fsync(fd); } @@ -1442,7 +1453,8 @@ static void write_to_file(char *path, int seq, char *buf) for (i = 0; i < 8; i++) dirty_an_inode(path); } - sync_file_range(fd, 0, 0, SYNC_FILE_RANGE_WRITE|SYNC_FILE_RANGE_WAIT_AFTER); + + maybe_write_through(fd, 0, 0); if (verify_writes && write_size >= BUF_SIZE) read_whole_fd(fd, name, buf, BUF_SIZE); |