fdp: support random placement id selection
authorAnkit Kumar <ankit.kumar@samsung.com>
Wed, 12 Jul 2023 10:20:40 +0000 (15:50 +0530)
committerVincent Fu <vincent.fu@samsung.com>
Thu, 13 Jul 2023 16:38:14 +0000 (12:38 -0400)
Allow user to either roundrobin or select random placement ID from
the available placement IDs.

Signed-off-by: Ankit Kumar <ankit.kumar@samsung.com>
Signed-off-by: Vincent Fu <vincent.fu@samsung.com>
HOWTO.rst
fdp.c
fdp.h
fio.1
fio.h
init.c
options.c
thread_options.h

index 2e1e55c26e8e9228b32852b877e56fe2d9220e2e..24789f41686dcdeb0bb5549a7e77fdb79082432d 100644 (file)
--- a/HOWTO.rst
+++ b/HOWTO.rst
@@ -2435,6 +2435,21 @@ with the caveat that when used on the command line, they must come after the
 
        Enable Flexible Data Placement mode for write commands.
 
+.. option:: fdp_pli_select=str : [io_uring_cmd]
+
+       Defines how fio decides which placement ID to use next. The following
+       types are defined:
+
+               **random**
+                       Choose a placement ID at random (uniform).
+
+               **roundrobin**
+                       Round robin over available placement IDs. This is the
+                       default.
+
+       The available placement ID index/indices is defined by the option
+       :option:`fdp_pli`.
+
 .. option:: fdp_pli=str : [io_uring_cmd]
 
        Select which Placement ID Index/Indicies this job is allowed to use for
diff --git a/fdp.c b/fdp.c
index 6e124ce6005232a6c1838a4cf4edfdd9ceeb2cc0..49c80d2c613466cf9e5d98171dd4c4bf727ad7a9 100644 (file)
--- a/fdp.c
+++ b/fdp.c
@@ -119,10 +119,16 @@ void fdp_fill_dspec_data(struct thread_data *td, struct io_u *io_u)
                return;
        }
 
-       if (ruhs->pli_loc >= ruhs->nr_ruhs)
-               ruhs->pli_loc = 0;
+       if (td->o.fdp_pli_select == FIO_FDP_RR) {
+               if (ruhs->pli_loc >= ruhs->nr_ruhs)
+                       ruhs->pli_loc = 0;
+
+               dspec = ruhs->plis[ruhs->pli_loc++];
+       } else {
+               ruhs->pli_loc = rand_between(&td->fdp_state, 0, ruhs->nr_ruhs - 1);
+               dspec = ruhs->plis[ruhs->pli_loc];
+       }
 
-       dspec = ruhs->plis[ruhs->pli_loc++];
        io_u->dtype = FDP_DIR_DTYPE;
        io_u->dspec = dspec;
 }
diff --git a/fdp.h b/fdp.h
index 6ecbfcbe3b5e7b1c2effa9918ef8629c925aaea7..accbac384a349046e7a21dd4603351d0fdfdeb00 100644 (file)
--- a/fdp.h
+++ b/fdp.h
@@ -6,6 +6,16 @@
 #define FDP_DIR_DTYPE  2
 #define FDP_MAX_RUHS   128
 
+/*
+ * How fio chooses what placement identifier to use next. Choice of
+ * uniformly random, or roundrobin.
+ */
+
+enum {
+       FIO_FDP_RANDOM  = 0x1,
+       FIO_FDP_RR      = 0x2,
+};
+
 struct fio_ruhs_info {
        uint32_t nr_ruhs;
        uint32_t pli_loc;
diff --git a/fio.1 b/fio.1
index 73b7e8c9eaae925ee8fb004ca77742bd6da11f15..0257513ba50f819f3b728e3163084c4afa817639 100644 (file)
--- a/fio.1
+++ b/fio.1
@@ -2195,6 +2195,22 @@ file blocks are fully allocated and the disk request could be issued immediately
 .BI (io_uring_cmd)fdp \fR=\fPbool
 Enable Flexible Data Placement mode for write commands.
 .TP
+.BI (io_uring_cmd)fdp_pli_select \fR=\fPstr
+Defines how fio decides which placement ID to use next. The following types
+are defined:
+.RS
+.RS
+.TP
+.B random
+Choose a placement ID at random (uniform).
+.TP
+.B roundrobin
+Round robin over available placement IDs. This is the default.
+.RE
+.P
+The available placement ID index/indices is defined by \fBfdp_pli\fR option.
+.RE
+.TP
 .BI (io_uring_cmd)fdp_pli \fR=\fPstr
 Select which Placement ID Index/Indicies this job is allowed to use for writes.
 By default, the job will cycle through all available Placement IDs, so use this
diff --git a/fio.h b/fio.h
index c5453d131b28d4c571973fe26a1433516b2cc6d7..a54f57c93e3e0f40e076d19b230f4933e6782dab 100644 (file)
--- a/fio.h
+++ b/fio.h
@@ -144,6 +144,7 @@ enum {
        FIO_RAND_POISSON3_OFF,
        FIO_RAND_PRIO_CMDS,
        FIO_RAND_DEDUPE_WORKING_SET_IX,
+       FIO_RAND_FDP_OFF,
        FIO_RAND_NR_OFFS,
 };
 
@@ -262,6 +263,7 @@ struct thread_data {
        struct frand_state verify_state_last_do_io;
        struct frand_state trim_state;
        struct frand_state delay_state;
+       struct frand_state fdp_state;
 
        struct frand_state buf_state;
        struct frand_state buf_state_prev;
diff --git a/init.c b/init.c
index 10e63cca6cf7fd738a20b9c329357e5eb158fab5..105339fa28e0b855af65da9cb6a3c30529156e8d 100644 (file)
--- a/init.c
+++ b/init.c
@@ -1082,6 +1082,8 @@ void td_fill_rand_seeds(struct thread_data *td)
 
        init_rand_seed(&td->buf_state, td->rand_seeds[FIO_RAND_BUF_OFF], use64);
        frand_copy(&td->buf_state_prev, &td->buf_state);
+
+       init_rand_seed(&td->fdp_state, td->rand_seeds[FIO_RAND_FDP_OFF], use64);
 }
 
 static int setup_random_seeds(struct thread_data *td)
index a7c4ef6edbaa2c66a12703544a9ca8970114a048..0f739317248cb95ada08ef1219dc8472bb8946c1 100644 (file)
--- a/options.c
+++ b/options.c
@@ -3679,6 +3679,26 @@ struct fio_option fio_options[FIO_MAX_OPTS] = {
                .category = FIO_OPT_C_IO,
                .group  = FIO_OPT_G_INVALID,
        },
+       {
+               .name   = "fdp_pli_select",
+               .lname  = "FDP Placement ID select",
+               .type   = FIO_OPT_STR,
+               .off1   = offsetof(struct thread_options, fdp_pli_select),
+               .help   = "Select which FDP placement ID to use next",
+               .def    = "roundrobin",
+               .category = FIO_OPT_C_IO,
+               .group  = FIO_OPT_G_INVALID,
+               .posval = {
+                         { .ival = "random",
+                           .oval = FIO_FDP_RANDOM,
+                           .help = "Choose a Placement ID at random (uniform)",
+                         },
+                         { .ival = "roundrobin",
+                           .oval = FIO_FDP_RR,
+                           .help = "Round robin select Placement IDs",
+                         },
+               },
+       },
        {
                .name   = "fdp_pli",
                .lname  = "FDP Placement ID indicies",
index a24ebee69c47af1b82643cd73a2446bb80d88f98..1715b36c672b31d48b2a5dbb8700a96e9ed1ab01 100644 (file)
@@ -388,6 +388,7 @@ struct thread_options {
 
 #define FIO_MAX_PLIS 16
        unsigned int fdp;
+       unsigned int fdp_pli_select;
        unsigned int fdp_plis[FIO_MAX_PLIS];
        unsigned int fdp_nrpli;
 
@@ -703,6 +704,7 @@ struct thread_options_pack {
        uint32_t log_prio;
 
        uint32_t fdp;
+       uint32_t fdp_pli_select;
        uint32_t fdp_plis[FIO_MAX_PLIS];
        uint32_t fdp_nrpli;