filesetup: better handle non-uniform distributions
authorVincent Fu <vincent.fu@samsung.com>
Thu, 20 Apr 2023 15:12:22 +0000 (15:12 +0000)
committerVincent Fu <vincent.fu@samsung.com>
Thu, 20 Apr 2023 15:24:39 +0000 (15:24 +0000)
When we have a random workload with multiple files, randrepeat=0, and a
non-uniform random distribution, the offsets touched will follow the
same sequence for all files:

$ ./fio --name=test --nrfiles=2 --randrepeat=0 --filesize=16k \
--debug=io --rw=randread --norandommap \
--random_distribution=normal:50 | grep complete:

io       23042 complete: io_u 0x55bd982f6000: off=0x2000,len=0x1000,ddir=0,file=test.0.0
io       23042 complete: io_u 0x55bd982f6000: off=0x2000,len=0x1000,ddir=0,file=test.0.1
io       23042 complete: io_u 0x55bd982f6000: off=0x3000,len=0x1000,ddir=0,file=test.0.0
io       23042 complete: io_u 0x55bd982f6000: off=0x3000,len=0x1000,ddir=0,file=test.0.1
io       23042 complete: io_u 0x55bd982f6000: off=0x2000,len=0x1000,ddir=0,file=test.0.0
io       23042 complete: io_u 0x55bd982f6000: off=0x2000,len=0x1000,ddir=0,file=test.0.1
io       23042 complete: io_u 0x55bd982f6000: off=0x3000,len=0x1000,ddir=0,file=test.0.0
io       23042 complete: io_u 0x55bd982f6000: off=0x3000,len=0x1000,ddir=0,file=test.0.1

Notice that the blocks touched for test.0.0 and test.0.1 follow the same
sequence.

This patch allows the sequence of offsets touched to differ between
files by always involving the filename in the seed used for each file.
The randrepeat setting will still be respected as it is involved in
determining the value for td->rand_seeds[FIO_RAND_BLOCK_OFF].

With the patch applied the above invocation produces output like:

io       23022 complete: io_u 0x55ed2cd2c000: off=0x2000,len=0x1000,ddir=0,file=test.0.0
io       23022 complete: io_u 0x55ed2cd2c000: off=0x2000,len=0x1000,ddir=0,file=test.0.1
io       23022 complete: io_u 0x55ed2cd2c000: off=0x3000,len=0x1000,ddir=0,file=test.0.0
io       23022 complete: io_u 0x55ed2cd2c000: off=0x2000,len=0x1000,ddir=0,file=test.0.1
io       23022 complete: io_u 0x55ed2cd2c000: off=0x2000,len=0x1000,ddir=0,file=test.0.0
io       23022 complete: io_u 0x55ed2cd2c000: off=0x3000,len=0x1000,ddir=0,file=test.0.1
io       23022 complete: io_u 0x55ed2cd2c000: off=0x1000,len=0x1000,ddir=0,file=test.0.0
io       23022 complete: io_u 0x55ed2cd2c000: off=0x2000,len=0x1000,ddir=0,file=test.0.1

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

index 14c7610849218194c475366d8fe2f641084fa6ba..816d10816e58acf2ba871bc8b78e733849914432 100644 (file)
@@ -1447,9 +1447,8 @@ static void __init_rand_distribution(struct thread_data *td, struct fio_file *f)
 
        nranges = (fsize + range_size - 1ULL) / range_size;
 
-       seed = jhash(f->file_name, strlen(f->file_name), 0) * td->thread_number;
-       if (!td->o.rand_repeatable)
-               seed = td->rand_seeds[FIO_RAND_BLOCK_OFF];
+       seed = jhash(f->file_name, strlen(f->file_name), 0) * td->thread_number *
+               td->rand_seeds[FIO_RAND_BLOCK_OFF];
 
        if (td->o.random_distribution == FIO_RAND_DIST_ZIPF)
                zipf_init(&f->zipf, nranges, td->o.zipf_theta.u.f, td->o.random_center.u.f, seed);