iolog replay: Realloc io_u buffers to adapt to operation size.
authorAdam Kupczyk <akupczyk@redhat.com>
Thu, 9 Aug 2018 14:05:22 +0000 (16:05 +0200)
committerAdam Kupczyk <akupczyk@redhat.com>
Thu, 9 Aug 2018 14:15:56 +0000 (16:15 +0200)
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 <akupczyk@redhat.com>
backend.c
iolog.c
iolog.h

index 4b4ecdef220b3b026306538161aebceb1dbea333..f6cfbdd8288230be53136b8ad002439c862118df 100644 (file)
--- 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;
 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 cl_align, i, max_units;
-       int data_xfer = 1, err;
-       char *p;
+       int err;
 
        max_units = td->o.iodepth;
 
        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);
 
        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;
        }
 
                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
        /*
         * 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;
 
        else
                p = td->orig_buffer;
 
-       cl_align = os_cache_line_size();
-
        for (i = 0; i < max_units; i++) {
        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) {
                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);
                        }
                }
                                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;
        }
 
                p += max_bs;
        }
 
-       if (init_file_completion_logging(td, max_units))
-               return 1;
-
        return 0;
 }
 
        return 0;
 }
 
diff --git a/iolog.c b/iolog.c
index bd2a2145c0c6ffad99ae96a438b093ee328e235f..0f95c6080ea8d49fde24e868af82369d1dc7be2e 100644 (file)
--- 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;
        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) {
        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;
                        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;
                                td->o.max_bs[rw] = bytes;
+                       }
                        ipo->fileno = fileno;
                        ipo->file_action = file_action;
                        td->o.size += 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;
                        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;
        }
 
                return true;
        }
 
diff --git a/iolog.h b/iolog.h
index 3b8c9014566186e28d5a8fc213e7b76196140034..17be908f6ef405a79a14627511e5bfbb50768d85 100644 (file)
--- 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 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 *);
 
 #ifdef CONFIG_ZLIB
 extern int iolog_file_inflate(const char *);