engines/libblkio: Add option libblkio_write_zeroes_on_trim
authorAlberto Faria <afaria@redhat.com>
Thu, 1 Dec 2022 22:07:59 +0000 (22:07 +0000)
committerVincent Fu <vincent.fu@samsung.com>
Fri, 2 Dec 2022 21:24:03 +0000 (16:24 -0500)
When set, trim IOs will be submitted as blkioq_write_zeroes() requests
instead of blkioq_discard() requests.

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 f77d76ccf817496fc18f8ba0fdc6b00758d5a224..273b7a68bd6de7d59a8c9c9f4225b92222f64cb9 100644 (file)
--- a/HOWTO.rst
+++ b/HOWTO.rst
@@ -2891,6 +2891,10 @@ with the caveat that when used on the command line, they must come after the
 
        Submit vectored read and write requests.
 
+.. option:: libblkio_write_zeroes_on_trim : [libblkio]
+
+       Submit trims as "write zeroes" requests instead of discard requests.
+
 I/O depth
 ~~~~~~~~~
 
index 219bb0dc4bd8750848107be2483a61cb1f7adee8..66a9bd31f81ed6d195c54e421aa45764d8a4bcb4 100644 (file)
@@ -41,6 +41,7 @@ struct fio_blkio_options {
 
        unsigned int hipri;
        unsigned int vectored;
+       unsigned int write_zeroes_on_trim;
 };
 
 static struct fio_option options[] = {
@@ -89,6 +90,16 @@ static struct fio_option options[] = {
                .category = FIO_OPT_C_ENGINE,
                .group  = FIO_OPT_G_LIBBLKIO,
        },
+       {
+               .name   = "libblkio_write_zeroes_on_trim",
+               .lname  = "Use blkioq_write_zeroes() for TRIM",
+               .type   = FIO_OPT_STR_SET,
+               .off1   = offsetof(struct fio_blkio_options,
+                                  write_zeroes_on_trim),
+               .help   = "Use blkioq_write_zeroes() for TRIM instead of blkioq_discard()",
+               .category = FIO_OPT_C_ENGINE,
+               .group  = FIO_OPT_G_LIBBLKIO,
+       },
        {
                .name = NULL,
        },
@@ -455,8 +466,13 @@ static enum fio_q_status fio_blkio_queue(struct thread_data *td,
                        }
                        break;
                case DDIR_TRIM:
-                       blkioq_discard(data->q, io_u->offset, io_u->xfer_buflen,
-                                      io_u, 0);
+                       if (options->write_zeroes_on_trim) {
+                               blkioq_write_zeroes(data->q, io_u->offset,
+                                                   io_u->xfer_buflen, io_u, 0);
+                       } else {
+                               blkioq_discard(data->q, io_u->offset,
+                                              io_u->xfer_buflen, io_u, 0);
+                       }
                        break;
                case DDIR_SYNC:
                case DDIR_DATASYNC:
diff --git a/fio.1 b/fio.1
index 9b8995b57e4787d949049d4720bac632e9686309..ad061caa0d9117f35a08301729084efb571d1dc5 100644 (file)
--- a/fio.1
+++ b/fio.1
@@ -2637,6 +2637,9 @@ Use poll queues.
 .TP
 .BI (libblkio)libblkio_vectored
 Submit vectored read and write requests.
+.TP
+.BI (libblkio)libblkio_write_zeroes_on_trim
+Submit trims as "write zeroes" requests instead of discard requests.
 .SS "I/O depth"
 .TP
 .BI iodepth \fR=\fPint