iolog: add version 3 with timestamp support
v2 cover iolog: add version 3 with timestamp support
This set of patches introduces version 3 of the iolog replay. This version adds support for timestamps on both iolog_read and iolog_write. The 'wait' action is no longer supported with version 3, as the same behavior can be achieved with timestamps, and it keeps the iolog file easier to follow. This could also allow to potentially deprecate the 'wait' action eventually.
Changes from v1:
* Add commit messages to #2 and #3, and fix the format of #1.
* Store fio_gettime() in td->last_issue directly rather than memcpying to it in commit #1.
Mohamad Gebai (3):
iolog: add version 3 to support timestamp-based replay
iolog: add iolog_write for version 3
iolog: update man page for version 3
HOWTO.rst | 29 ++++++++++++++- blktrace.c | 17 ++------- fio.h | 4 ++- iolog.c | 104 ++++++++++++++++++++++++++++++++++++++++++----------- iolog.h | 8 ++--- 5 files changed, 121 insertions(+), 41 deletions(-)
Signature · 1 line
2.30.2
PATCH v2 1/3 iolog: add version 3 to support timestamp-based replay
Version 3 format looks as follows:
timestamp filename action offset length
All file and IO actions must have timestamps, including 'add'. The 'wait' action is not allowed with version 3 so that we can leave all timing functionality to timestamps.
--- blktrace.c | 17 ++--------- fio.h | 3 +- iolog.c | 89 +++++++++++++++++++++++++++++++++++++++++++----------- iolog.h | 8 ++--- 4 files changed, 80 insertions(+), 37 deletions(-)
blktrace.c +3 -14
@@ -306,39 +306,28 @@ static bool handle_trace_flush(struct thread_data *td, struct blk_io_trace *t, }/* * We only care for queue traces, most of the others are side effects * due to internal workings of the block layer. */ static bool queue_trace (struct thread_data *td,struct blk_io_trace *t,unsigned long *ios,unsigned long long *bs,struct file_cache *cache) { -unsigned long long *last_ttime = &td->io_log_blktrace_last_ttime; +unsigned long long *last_ttime = &td->io_log_last_ttime;unsigned long long delay =0 ;if ((t->action &0xffff ) != __BLK_TA_QUEUE)return false;if (!(t->action &BLK_TC_ACT (BLK_TC_NOTIFY ))) { -if (!*last_ttime || td->o.no_stall || t->time < *last_ttime) - delay =0 ; -else if (td->o.replay_time_scale ==100 ) - delay = t->time - *last_ttime; -else { -double tmp = t->time - *last_ttime; -double scale; - - scale = (double )100.0 / (double ) td->o.replay_time_scale; - tmp *= scale; - delay = tmp; - } + delay =delay_since_ttime (td, t->time); *last_ttime = t->time; }t_bytes_align (&td->o, t);if (t->action &BLK_TC_ACT (BLK_TC_NOTIFY ))return handle_trace_notify (t);else if (t->action &BLK_TC_ACT (BLK_TC_DISCARD ))return handle_trace_discard (td, t, delay, ios, bs, cache);else if (t->action &BLK_TC_ACT (BLK_TC_FLUSH ))
@@ -415,21 +404,21 @@ static void depth_end(struct blk_io_trace *t, int *this_depth, int *depth)bool init_blktrace_read (struct thread_data *td,const char *filename,int need_swap) {int old_state; td->io_log_rfile =fopen (filename,"rb" );if (!td->io_log_rfile) {td_verror (td, errno,"open blktrace file" ); goto err; } td->io_log_blktrace_swap = need_swap; - td->io_log_blktrace_last_ttime =0 ; + td->io_log_last_ttime =0 ; td->o.size =0 ;free_release_files (td); old_state =td_bump_runstate (td,TD_SETTING_UP );if (!read_blktrace (td)) { goto err; }
fio.h +2 -1
@@ -424,24 +424,25 @@ struct thread_data {struct flist_head io_hist_list;unsigned long io_hist_len;/* * For IO replaying */ struct flist_head io_log_list;FILE *io_log_rfile;unsigned int io_log_blktrace;unsigned int io_log_blktrace_swap; -unsigned long long io_log_blktrace_last_ttime; +unsigned long long io_log_last_ttime;unsigned int io_log_current;unsigned int io_log_checkmark;unsigned int io_log_highmark; +unsigned int io_log_version;struct timespec io_log_highmark_time;/* * For tracking/handling discards */ struct flist_head trim_list;unsigned long trim_entries;/* * for fileservice, how often to switch to a new file
iolog.c +71 -18
307 lines not on this page · raw message
iolog.h +4 -4
@@ -220,24 +220,22 @@ struct io_piece {struct flist_head trim_list;union {int fileno;struct fio_file *file; };unsigned long long offset;unsigned short numberio;unsigned long len;unsigned int flags;enum fio_ddir ddir; -union { -unsigned long delay; -unsigned int file_action; - }; +unsigned long delay; +unsigned int file_action; };/* * Log exports */ enum file_log_act {FIO_LOG_ADD_FILE ,FIO_LOG_OPEN_FILE ,FIO_LOG_CLOSE_FILE ,FIO_LOG_UNLINK_FILE ,
@@ -252,20 +250,22 @@ extern void log_io_piece(struct thread_data *, struct io_u *);extern void unlog_io_piece (struct thread_data *,struct io_u *);extern void trim_io_piece (const struct io_u *);extern void queue_io_piece (struct thread_data *,struct io_piece *);extern void prune_io_piece_log (struct thread_data *);extern void write_iolog_close (struct thread_data *);int64_t iolog_items_to_fetch (struct thread_data *td);extern int iolog_compress_init (struct thread_data *,struct sk_out *);extern void iolog_compress_exit (struct thread_data *);extern size_t log_chunk_sizes (struct io_log *);extern int init_io_u_buffers (struct thread_data *); +extern unsigned long long delay_since_ttime (const struct thread_data *, +unsigned long long );#ifdef CONFIG_ZLIB extern int iolog_file_inflate (const char *);#endif /* * Logging */ struct log_params {struct thread_data *td;
Signature · 1 line
2.30.2
PATCH v2 2/3 iolog: add iolog_write for version 3
In reply to Mohamad GebaiAdd timestamps to all actions for iolog version 3. Fio now generates iolog files using version 3 by default, and only supports writing using that version. Reading iolog v2 still works as expected.
--- fio.h | 1 + iolog.c | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-)
fio.h +1 -0
@@ -425,20 +425,21 @@ struct thread_data {unsigned long io_hist_len;/* * For IO replaying */ struct flist_head io_log_list;FILE *io_log_rfile;unsigned int io_log_blktrace;unsigned int io_log_blktrace_swap;unsigned long long io_log_last_ttime; +struct timespec io_log_start_time;unsigned int io_log_current;unsigned int io_log_checkmark;unsigned int io_log_highmark;unsigned int io_log_version;struct timespec io_log_highmark_time;/* * For tracking/handling discards */ struct flist_head trim_list;
iolog.c +12 -3
@@ -34,46 +34,54 @@ static const char iolog_ver2[] = "fio version 2 iolog";static const char iolog_ver3[] ="fio version 3 iolog" ;void queue_io_piece (struct thread_data *td,struct io_piece *ipo) {flist_add_tail (&ipo->list, &td->io_log_list); td->total_io_size += ipo->len; }void log_io_u (const struct thread_data *td,const struct io_u *io_u) { +struct timespec now; +if (!td->o.write_iolog_file)return ; -fprintf (td->iolog_f,"%s %s %llu %llu\n" , io_u->file->file_name, +fio_gettime (&now,NULL ); +fprintf (td->iolog_f,"%lu %s %s %llu %llu\n" ,utime_since_now (&td->io_log_start_time), + io_u->file->file_name,io_ddir_name (io_u->ddir), io_u->offset, io_u->buflen); + }void log_file (struct thread_data *td,struct fio_file *f,enum file_log_act what) {const char *act[] = {"add" ,"open" ,"close" }; +struct timespec now;assert (what <3 );if (!td->o.write_iolog_file)return ;/* * this happens on the pre-open/close done before the job starts */ if (!td->iolog_f)return ; -fprintf (td->iolog_f,"%s %s\n" , f->file_name, act[what]); +fio_gettime (&now,NULL ); +fprintf (td->iolog_f,"%lu %s %s\n" ,utime_since_now (&td->io_log_start_time), + f->file_name, act[what]); }static void iolog_delay (struct thread_data *td,unsigned long delay) {uint64_t usec =utime_since_now (&td->last_issue);unsigned long orig_delay = delay;uint64_t this_delay;struct timespec ts;if (delay < td->time_offset) {
@@ -731,25 +739,26 @@ static bool init_iolog_write(struct thread_data *td)perror ("fopen write iolog" );return false; }/* * That's it for writing, setup a log buffer and we're done. */ td->iolog_f = f; td->iolog_buf =malloc (8192 );setvbuf (f, td->iolog_buf, _IOFBF,8192 ); +fio_gettime (&td->io_log_start_time,NULL );/* * write our version line */ -if (fprintf (f,"%s\n" , iolog_ver2) <0 ) { +if (fprintf (f,"%s\n" , iolog_ver3) <0 ) {perror ("iolog init\n" );return false; }/* * add all known files */ for_each_file (td, ff, i)log_file (td, ff,FIO_LOG_ADD_FILE );
Signature · 1 line
2.30.2
PATCH v2 3/3 iolog: update man page for version 3
In reply to Mohamad GebaiAdd documentation for iolog version 3, mainly the differences between versions 2 and 3.
--- HOWTO.rst | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-)
HOWTO.rst +28 -1
@@ -4391,33 +4391,60 @@ The `filename` is given as an absolute path. The `action` can be one of these: The file I/O action format:: filename action offset length The `filename` is given as an absolute path, and has to have been added and opened before it can be used with this format. The `offset` and `length` are given in bytes. The `action` can be one of these: **wait** Wait for `offset` microseconds. Everything below 100 is discarded. - The time is relative to the previous `wait` statement. + The time is relative to the previous `wait` statement. Note that + action `wait` is not allowed as of version 3, as the same behavior + can be achieved using timestamps. **read** Read `length` bytes beginning from `offset`. **write** Write `length` bytes beginning from `offset`. **sync** :manpage:`fsync(2)` the file. **datasync** :manpage:`fdatasync(2)` the file. **trim** Trim the given file from the given `offset` for `length` bytes. +Trace file format v3 +~~~~~~~~~~~~~~~~~~~~ + +The third version of the trace file format was added in fio version 3.30. It +forces each action to have a timestamp associated with it. + +The first line of the trace file has to be:: + + fio version 3 iolog + +Following this can be lines in two different formats, which are described below. + +The file management format:: + + timestamp filename action + +The file I/O action format:: + + timestamp filename action offset length + +The `timestamp` is relative to the beginning of the run (ie starts at 0). The +`filename`, `action`, `offset` and `length` are identical to version 2, except +that version 3 does not allow the `wait` action. + + I/O Replay - Merging Traces --------------------------- Colocation is a common practice used to get the most out of a machine. Knowing which workloads play nicely with each other and which ones don't is a much harder task. While fio can replay workloads concurrently via multiple jobs, it leaves some variability up to the scheduler making results harder to reproduce. Merging is a way to make the order of events consistent. Merging is integrated into I/O replay and done when a
Signature · 1 line
2.30.2
RE: [PATCH v2 3/3] iolog: update man page for version 3
Quoted 7 lines
-----Original Message-----
From: Mohamad Gebai [mailto:[email protected]]
Sent: Thursday, April 7, 2022 10:50 AM
To: [email protected]
Cc: Mohamad Gebai <[email protected]>
Subject: [PATCH v2 3/3] iolog: update man page for version 3
Quoted 8 lines
Add documentation for iolog version 3, mainly the differences between versions 2 and 3.
Signed-off-by Mohamad Gebai <[email protected]>--- HOWTO.rst | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-)
Please also update fio.1