engines/libblkio: Allow setting option mem/iomem
authorAlberto Faria <afaria@redhat.com>
Thu, 1 Dec 2022 22:07:56 +0000 (22:07 +0000)
committerVincent Fu <vincent.fu@samsung.com>
Fri, 2 Dec 2022 21:24:03 +0000 (16:24 -0500)
This allows users to customize data buffer memory using fio's existing
options. Users become responsible for ensuring that the allocated memory
satisfies all constraints imposed by the libblkio driver under use.

Signed-off-by: Alberto Faria <afaria@redhat.com>
Signed-off-by: Vincent Fu <vincent.fu@samsung.com>
HOWTO.rst
engines/libblkio.c
fio.1

index 08140165e7966a27e4fa1cc212a4960854340a39..69ca1e79025c14c0fdb4483232a4244fa89f06af 100644 (file)
--- a/HOWTO.rst
+++ b/HOWTO.rst
@@ -2199,7 +2199,10 @@ I/O engine
                        Use the libblkio library
                        (https://gitlab.com/libblkio/libblkio). The specific
                        *driver* to use must be set using
-                       :option:`libblkio_driver`.
+                       :option:`libblkio_driver`. If
+                       :option:`mem`/:option:`iomem` is not specified, memory
+                       allocation is delegated to libblkio (and so is
+                       guaranteed to work with the selected *driver*).
 
 I/O engine specific parameters
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
index 7a5d4271808eed0ad2c9b9178ca2f36abc6b614f..11f45e2a59f17d4382b977d714d284a86d0c4d63 100644 (file)
@@ -26,7 +26,7 @@ struct fio_blkio_data {
        struct blkioq *q;
 
        bool has_mem_region; /* whether mem_region is valid */
-       struct blkio_mem_region mem_region;
+       struct blkio_mem_region mem_region; /* only if allocated by libblkio */
 
        struct blkio_completion *completions;
 };
@@ -271,6 +271,47 @@ err_free:
        return 1;
 }
 
+static int fio_blkio_post_init(struct thread_data *td)
+{
+       struct fio_blkio_data *data = td->io_ops_data;
+
+       if (!data->has_mem_region) {
+               /*
+                * Memory was allocated by the fio core and not iomem_alloc(),
+                * so we need to register it as a memory region here.
+                *
+                * `td->orig_buffer_size` is computed like `len` below, but then
+                * fio can add some padding to it to make sure it is
+                * sufficiently aligned to the page size and the mem_align
+                * option. However, this can make it become unaligned to the
+                * "mem-region-alignment" property in ways that the user can't
+                * control, so we essentially recompute `td->orig_buffer_size`
+                * here but without adding that padding.
+                */
+
+               unsigned long long max_block_size;
+               struct blkio_mem_region region;
+
+               max_block_size = max(td->o.max_bs[DDIR_READ],
+                                    max(td->o.max_bs[DDIR_WRITE],
+                                        td->o.max_bs[DDIR_TRIM]));
+
+               region = (struct blkio_mem_region) {
+                       .addr   = td->orig_buffer,
+                       .len    = (size_t)max_block_size *
+                                       (size_t)td->o.iodepth,
+                       .fd     = -1,
+               };
+
+               if (blkio_map_mem_region(data->b, &region) != 0) {
+                       fio_blkio_log_err(blkio_map_mem_region);
+                       return 1;
+               }
+       }
+
+       return 0;
+}
+
 static void fio_blkio_cleanup(struct thread_data *td)
 {
        struct fio_blkio_data *data = td->io_ops_data;
@@ -403,10 +444,11 @@ FIO_STATIC struct ioengine_ops ioengine = {
        .name                   = "libblkio",
        .version                = FIO_IOOPS_VERSION,
        .flags                  = FIO_DISKLESSIO | FIO_NOEXTEND |
-                                 FIO_NO_OFFLOAD,
+                                 FIO_NO_OFFLOAD | FIO_SKIPPABLE_IOMEM_ALLOC,
 
        .setup                  = fio_blkio_setup,
        .init                   = fio_blkio_init,
+       .post_init              = fio_blkio_post_init,
        .cleanup                = fio_blkio_cleanup,
 
        .iomem_alloc            = fio_blkio_iomem_alloc,
diff --git a/fio.1 b/fio.1
index 3615f25815a85a393fe5ce1853b5850dad864487..18428774025877806fb4756653e3f39c2d46cdb1 100644 (file)
--- a/fio.1
+++ b/fio.1
@@ -1995,7 +1995,9 @@ engine specific options. (See \fIhttps://xnvme.io/\fR).
 .TP
 .B libblkio
 Use the libblkio library (\fIhttps://gitlab.com/libblkio/libblkio\fR). The
-specific driver to use must be set using \fBlibblkio_driver\fR.
+specific driver to use must be set using \fBlibblkio_driver\fR. If
+\fBmem\fR/\fBiomem\fR is not specified, memory allocation is delegated to
+libblkio (and so is guaranteed to work with the selected driver).
 .SS "I/O engine specific parameters"
 In addition, there are some parameters which are only valid when a specific
 \fBioengine\fR is in use. These are used identically to normal parameters,