From 073974b24aac23610e9e13e3eb56438ad108ab31 Mon Sep 17 00:00:00 2001 From: Vincent Fu Date: Thu, 20 Apr 2023 15:12:22 +0000 Subject: [PATCH] filesetup: better handle non-uniform distributions 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 --- filesetup.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/filesetup.c b/filesetup.c index 14c76108..816d1081 100644 --- a/filesetup.c +++ b/filesetup.c @@ -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); -- 2.25.1