zipf: seed zipf/pareto rand with filename hash and job id
authorJens Axboe <axboe@kernel.dk>
Wed, 7 Nov 2012 18:47:47 +0000 (19:47 +0100)
committerJens Axboe <axboe@kernel.dk>
Wed, 7 Nov 2012 18:47:47 +0000 (19:47 +0100)
We don't want 4 jobs operating on the same file to use the
same hot spots.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
filesetup.c
lib/zipf.c
lib/zipf.h
t/genzipf.c

index ac69c65ea8f44956debb01bca32bef41c2675fb2..8636e16661b3bad68a70e28a6805e227c5e9e543 100644 (file)
@@ -12,6 +12,7 @@
 #include "smalloc.h"
 #include "filehash.h"
 #include "os/os.h"
+#include "hash.h"
 
 #ifdef FIO_HAVE_LINUX_FALLOCATE
 #include <linux/falloc.h>
@@ -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;
 }
index 21aaa36b1910655ccda093053a03470988736a8d..c7bb8a80799ce88adedae2a139dd3ea5e59a30d4 100644 (file)
@@ -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);
 }
 
index a23afe5e88457ffd7b8c7cda83b2d1b9ce6cbb28..dbcaffb2453069442b2aa998267f846c2e15b47f 100644 (file)
@@ -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
index c3ab4ae1b1d8608214269dad4dda966d32540130..dfb89929eb00e2e24e2775878903e8eecc670372 100644 (file)
@@ -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;