From 2316296a514711bb388d87b34742c04bb561d986 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Wed, 7 Nov 2012 19:47:47 +0100 Subject: [PATCH] zipf: seed zipf/pareto rand with filename hash and job id We don't want 4 jobs operating on the same file to use the same hot spots. Signed-off-by: Jens Axboe --- filesetup.c | 8 +++++--- lib/zipf.c | 15 +++++++++------ lib/zipf.h | 4 ++-- t/genzipf.c | 4 ++-- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/filesetup.c b/filesetup.c index ac69c65e..8636e166 100644 --- a/filesetup.c +++ b/filesetup.c @@ -12,6 +12,7 @@ #include "smalloc.h" #include "filehash.h" #include "os/os.h" +#include "hash.h" #ifdef FIO_HAVE_LINUX_FALLOCATE #include @@ -864,17 +865,18 @@ int pre_read_files(struct thread_data *td) static int __init_rand_distribution(struct thread_data *td, struct fio_file *f) { - unsigned int range_size; + unsigned int range_size, seed; unsigned long nranges; range_size = min(td->o.min_bs[DDIR_READ], td->o.min_bs[DDIR_WRITE]); nranges = (f->real_file_size + range_size - 1) / range_size; + seed = jhash(f->file_name, strlen(f->file_name), 0) * td->thread_number; if (td->o.random_distribution == FIO_RAND_DIST_ZIPF) - zipf_init(&f->zipf, nranges, td->o.zipf_theta); + zipf_init(&f->zipf, nranges, td->o.zipf_theta, seed); else - pareto_init(&f->zipf, nranges, td->o.pareto_h); + pareto_init(&f->zipf, nranges, td->o.pareto_h, seed); return 1; } diff --git a/lib/zipf.c b/lib/zipf.c index 21aaa36b..c7bb8a80 100644 --- a/lib/zipf.c +++ b/lib/zipf.c @@ -88,18 +88,20 @@ punt: zs->nranges = f.nranges; } -static void shared_rand_init(struct zipf_state *zs, unsigned long nranges) +static void shared_rand_init(struct zipf_state *zs, unsigned long nranges, + unsigned int seed) { memset(zs, 0, sizeof(*zs)); zs->nranges = nranges; - init_rand(&zs->rand); + init_rand_seed(&zs->rand, seed); zs->rand_off = __rand(&zs->rand); } -void zipf_init(struct zipf_state *zs, unsigned long nranges, double theta) +void zipf_init(struct zipf_state *zs, unsigned long nranges, double theta, + unsigned int seed) { - shared_rand_init(zs, nranges); + shared_rand_init(zs, nranges, seed); zs->theta = theta; zs->zeta2 = pow(1.0, zs->theta) + pow(0.5, zs->theta); @@ -129,9 +131,10 @@ unsigned long long zipf_next(struct zipf_state *zs) return (__hash_long(val - 1) + zs->rand_off) % zs->nranges; } -void pareto_init(struct zipf_state *zs, unsigned long nranges, double h) +void pareto_init(struct zipf_state *zs, unsigned long nranges, double h, + unsigned int seed) { - shared_rand_init(zs, nranges); + shared_rand_init(zs, nranges, seed); zs->pareto_pow = log(h) / log(1.0 - h); } diff --git a/lib/zipf.h b/lib/zipf.h index a23afe5e..dbcaffb2 100644 --- a/lib/zipf.h +++ b/lib/zipf.h @@ -14,10 +14,10 @@ struct zipf_state { unsigned long rand_off; }; -void zipf_init(struct zipf_state *zs, unsigned long nranges, double theta); +void zipf_init(struct zipf_state *zs, unsigned long nranges, double theta, unsigned int seed); unsigned long long zipf_next(struct zipf_state *zs); -void pareto_init(struct zipf_state *zs, unsigned long nranges, double h); +void pareto_init(struct zipf_state *zs, unsigned long nranges, double h, unsigned int seed); unsigned long long pareto_next(struct zipf_state *zs); #endif diff --git a/t/genzipf.c b/t/genzipf.c index c3ab4ae1..dfb89929 100644 --- a/t/genzipf.c +++ b/t/genzipf.c @@ -153,9 +153,9 @@ int main(int argc, char *argv[]) printf("Generating %s distribution with %f input and %lu ranges.\n", use_zipf ? "zipf" : "pareto", val, nranges); if (use_zipf) - zipf_init(&zs, nranges, val); + zipf_init(&zs, nranges, val, 1); else - pareto_init(&zs, nranges, val); + pareto_init(&zs, nranges, val, 1); hash_bits = 0; hash_size = nranges; -- 2.25.1