randtrimwrite: write at same offset as trim
authorVincent Fu <vincent.fu@samsung.com>
Thu, 29 Sep 2022 23:58:17 +0000 (16:58 -0700)
committerVincent Fu <vincent.fu@samsung.com>
Mon, 3 Oct 2022 21:36:57 +0000 (17:36 -0400)
We need to do a little bit more to make sure that the writes land on the
offsets that were trimmed.

We only have a single random seed for offsets. So we need to just use
the offset from trim commands when issuing writes.

When we have variable block sizes we need to make sure that the trim and
write commands are the same size.

When randommap is enabled we have to let it adjust the block size for
trim commands to make sure that the trim command does not touch any
blocks that have already been touched.

For sizes of write commands just use the size of the trim command.

Fixes: c16dc793a3c45780f67ce65244b6e91323dee014 "Add randtrimwrite data
direction"

Signed-off-by: Vincent Fu <vincent.fu@samsung.com>
io_ddir.h
io_u.c

index 7227e9ee7f026f353ec0945cc22632a437bca5f0..217eb62862efb74938193da9e2f4b786282a6cf1 100644 (file)
--- a/io_ddir.h
+++ b/io_ddir.h
@@ -52,6 +52,8 @@ enum td_ddir {
 #define file_randommap(td, f)  (!(td)->o.norandommap && fio_file_axmap((f)))
 #define td_trimwrite(td)       (((td)->o.td_ddir & TD_DDIR_TRIMWRITE) \
                                        == TD_DDIR_TRIMWRITE)
+#define td_randtrimwrite(td)   (((td)->o.td_ddir & TD_DDIR_RANDTRIMWRITE) \
+                                       == TD_DDIR_RANDTRIMWRITE)
 
 static inline int ddir_sync(enum fio_ddir ddir)
 {
diff --git a/io_u.c b/io_u.c
index eec378ddc0258169e3edbeb84046f7f27cef6282..3f6c60ee887ef0e3aa74908fb73d0ddc36f32fbd 100644 (file)
--- a/io_u.c
+++ b/io_u.c
@@ -417,7 +417,13 @@ static int get_next_block(struct thread_data *td, struct io_u *io_u,
 
        b = offset = -1ULL;
 
-       if (rw_seq) {
+       if (td_randtrimwrite(td) && ddir == DDIR_WRITE) {
+               /* don't mark randommap for these writes */
+               io_u_set(td, io_u, IO_U_F_BUSY_OK);
+               offset = f->last_start[DDIR_TRIM];
+               *is_random = true;
+               ret = 0;
+       } else if (rw_seq) {
                if (td_random(td)) {
                        if (should_do_random(td, ddir)) {
                                ret = get_next_rand_block(td, f, ddir, &b);
@@ -530,6 +536,12 @@ static unsigned long long get_next_buflen(struct thread_data *td, struct io_u *i
 
        assert(ddir_rw(ddir));
 
+       if (td_randtrimwrite(td) && ddir == DDIR_WRITE) {
+               struct fio_file *f = io_u->file;
+
+               return f->last_pos[DDIR_TRIM] - f->last_start[DDIR_TRIM];
+       }
+
        if (td->o.bs_is_seq_rand)
                ddir = is_random ? DDIR_WRITE : DDIR_READ;