From 71e6e5a2fd5c00ee42ecac36037a539fcad1efae Mon Sep 17 00:00:00 2001 From: Adam Kupczyk Date: Thu, 9 Aug 2018 16:05:22 +0200 Subject: [PATCH] iolog replay: Realloc io_u buffers to adapt to operation size. When iolog is read in chunked mode, some prefetching is done. Based on this size of buffers are determined. Further operations may need larger buffers. If so, io_u buffers are reallocated. Example that cause problem when read_iolog_chunked=1: fio version 2 iolog rbd_data.0 add rbd_data.0 open rbd_data.0 write 0 4096 (x20) rbd_data.0 write 0 4096000 (x10) rbd_data.0 close Signed-off-by: Adam Kupczyk --- backend.c | 115 +++++++++++++++++++++++++++++++----------------------- iolog.c | 11 +++++- iolog.h | 1 + 3 files changed, 77 insertions(+), 50 deletions(-) diff --git a/backend.c b/backend.c index 4b4ecdef..f6cfbdd8 100644 --- a/backend.c +++ b/backend.c @@ -1201,19 +1201,10 @@ static void cleanup_io_u(struct thread_data *td) static int init_io_u(struct thread_data *td) { struct io_u *io_u; - unsigned long long max_bs, min_write; int cl_align, i, max_units; - int data_xfer = 1, err; - char *p; + int err; max_units = td->o.iodepth; - max_bs = td_max_bs(td); - min_write = td->o.min_bs[DDIR_WRITE]; - td->orig_buffer_size = (unsigned long long) max_bs - * (unsigned long long) max_units; - - if (td_ioengine_flagged(td, FIO_NOIO) || !(td_read(td) || td_write(td))) - data_xfer = 0; err = 0; err += !io_u_rinit(&td->io_u_requeues, td->o.iodepth); @@ -1225,6 +1216,70 @@ static int init_io_u(struct thread_data *td) return 1; } + cl_align = os_cache_line_size(); + + for (i = 0; i < max_units; i++) { + void *ptr; + + if (td->terminate) + return 1; + + ptr = fio_memalign(cl_align, sizeof(*io_u)); + if (!ptr) { + log_err("fio: unable to allocate aligned memory\n"); + break; + } + + io_u = ptr; + memset(io_u, 0, sizeof(*io_u)); + INIT_FLIST_HEAD(&io_u->verify_list); + dprint(FD_MEM, "io_u alloc %p, index %u\n", io_u, i); + + io_u->index = i; + io_u->flags = IO_U_F_FREE; + io_u_qpush(&td->io_u_freelist, io_u); + + /* + * io_u never leaves this stack, used for iteration of all + * io_u buffers. + */ + io_u_qpush(&td->io_u_all, io_u); + + if (td->io_ops->io_u_init) { + int ret = td->io_ops->io_u_init(td, io_u); + + if (ret) { + log_err("fio: failed to init engine data: %d\n", ret); + return 1; + } + } + } + + init_io_u_buffers(td); + + if (init_file_completion_logging(td, max_units)) + return 1; + + return 0; +} + +int init_io_u_buffers(struct thread_data *td) +{ + struct io_u *io_u; + unsigned long long max_bs, min_write; + int i, max_units; + int data_xfer = 1; + char *p; + + max_units = td->o.iodepth; + max_bs = td_max_bs(td); + min_write = td->o.min_bs[DDIR_WRITE]; + td->orig_buffer_size = (unsigned long long) max_bs + * (unsigned long long) max_units; + + if (td_ioengine_flagged(td, FIO_NOIO) || !(td_read(td) || td_write(td))) + data_xfer = 0; + /* * if we may later need to do address alignment, then add any * possible adjustment here so that we don't cause a buffer @@ -1256,23 +1311,8 @@ static int init_io_u(struct thread_data *td) else p = td->orig_buffer; - cl_align = os_cache_line_size(); - for (i = 0; i < max_units; i++) { - void *ptr; - - if (td->terminate) - return 1; - - ptr = fio_memalign(cl_align, sizeof(*io_u)); - if (!ptr) { - log_err("fio: unable to allocate aligned memory\n"); - break; - } - - io_u = ptr; - memset(io_u, 0, sizeof(*io_u)); - INIT_FLIST_HEAD(&io_u->verify_list); + io_u = td->io_u_all.io_us[i]; dprint(FD_MEM, "io_u alloc %p, index %u\n", io_u, i); if (data_xfer) { @@ -1289,32 +1329,9 @@ static int init_io_u(struct thread_data *td) fill_verify_pattern(td, io_u->buf, max_bs, io_u, 0, 0); } } - - io_u->index = i; - io_u->flags = IO_U_F_FREE; - io_u_qpush(&td->io_u_freelist, io_u); - - /* - * io_u never leaves this stack, used for iteration of all - * io_u buffers. - */ - io_u_qpush(&td->io_u_all, io_u); - - if (td->io_ops->io_u_init) { - int ret = td->io_ops->io_u_init(td, io_u); - - if (ret) { - log_err("fio: failed to init engine data: %d\n", ret); - return 1; - } - } - p += max_bs; } - if (init_file_completion_logging(td, max_units)) - return 1; - return 0; } diff --git a/iolog.c b/iolog.c index bd2a2145..0f95c608 100644 --- a/iolog.c +++ b/iolog.c @@ -389,6 +389,7 @@ static bool read_iolog2(struct thread_data *td) char *rfname, *fname, *act; char *str, *p; enum fio_ddir rw; + bool realloc = false; int64_t items_to_fetch = 0; if (td->o.read_iolog_chunked) { @@ -501,8 +502,10 @@ static bool read_iolog2(struct thread_data *td) ipo_bytes_align(td->o.replay_align, ipo); ipo->len = bytes; - if (rw != DDIR_INVAL && bytes > td->o.max_bs[rw]) + if (rw != DDIR_INVAL && bytes > td->o.max_bs[rw]) { + realloc = true; td->o.max_bs[rw] = bytes; + } ipo->fileno = fileno; ipo->file_action = file_action; td->o.size += bytes; @@ -539,6 +542,12 @@ static bool read_iolog2(struct thread_data *td) return false; } td->o.td_ddir = TD_DDIR_RW; + if (realloc && td->orig_buffer) + { + io_u_quiesce(td); + free_io_mem(td); + init_io_u_buffers(td); + } return true; } diff --git a/iolog.h b/iolog.h index 3b8c9014..17be908f 100644 --- a/iolog.h +++ b/iolog.h @@ -244,6 +244,7 @@ extern void write_iolog_close(struct thread_data *); 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 *); #ifdef CONFIG_ZLIB extern int iolog_file_inflate(const char *); -- 2.25.1