zipf/pareto: mix blocks with hashing
authorJens Axboe <axboe@kernel.dk>
Wed, 7 Nov 2012 10:39:30 +0000 (11:39 +0100)
committerJens Axboe <axboe@kernel.dk>
Wed, 7 Nov 2012 10:39:30 +0000 (11:39 +0100)
We don't want to favor any end of the block spectrum.
Mix with a hash.

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

diff --git a/hash.h b/hash.h
index 4b8c6bf0bcc49bd9b1f1b56c38c6e6b6243df22e..93dd8318ffa11dcb4324ab5ec7622880506916fd 100644 (file)
--- a/hash.h
+++ b/hash.h
@@ -28,7 +28,7 @@
 #error Define GOLDEN_RATIO_PRIME for your wordsize.
 #endif
 
 #error Define GOLDEN_RATIO_PRIME for your wordsize.
 #endif
 
-static inline unsigned long hash_long(unsigned long val, unsigned int bits)
+static inline unsigned long __hash_long(unsigned long val)
 {
        unsigned long hash = val;
 
 {
        unsigned long hash = val;
 
@@ -52,8 +52,13 @@ static inline unsigned long hash_long(unsigned long val, unsigned int bits)
        hash *= GOLDEN_RATIO_PRIME;
 #endif
 
        hash *= GOLDEN_RATIO_PRIME;
 #endif
 
+       return hash;
+}
+
+static inline unsigned long hash_long(unsigned long val, unsigned int bits)
+{
        /* High bits are more random, so use them. */
        /* High bits are more random, so use them. */
-       return hash >> (BITS_PER_LONG - bits);
+       return __hash_long(val) >> (BITS_PER_LONG - bits);
 }
        
 static inline unsigned long hash_ptr(void *ptr, unsigned int bits)
 }
        
 static inline unsigned long hash_ptr(void *ptr, unsigned int bits)
index 28e8d77e5602d13b95e73e561ce4df418750d441..527ae294cf9afd6212151e004e2220163e25f888 100644 (file)
@@ -9,6 +9,7 @@
 #include "../log.h"
 #include "zipf.h"
 #include "../minmax.h"
 #include "../log.h"
 #include "zipf.h"
 #include "../minmax.h"
+#include "../hash.h"
 #include "../os/os.h"
 
 struct fio_zipf_disk {
 #include "../os/os.h"
 
 struct fio_zipf_disk {
@@ -124,7 +125,7 @@ unsigned long long zipf_next(struct zipf_state *zs)
        else
                val = 1 + (unsigned long long)(n * pow(eta*rand_uni - eta + 1.0, alpha));
 
        else
                val = 1 + (unsigned long long)(n * pow(eta*rand_uni - eta + 1.0, alpha));
 
-       return val - 1;
+       return __hash_long(val - 1) % 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)
@@ -142,5 +143,5 @@ unsigned long long pareto_next(struct zipf_state *zs)
        double rand = (double) __rand(&zs->rand) / (double) FRAND_MAX;
        unsigned long long n = zs->nranges - 1;
 
        double rand = (double) __rand(&zs->rand) / (double) FRAND_MAX;
        unsigned long long n = zs->nranges - 1;
 
-       return n * pow(rand, zs->pareto_pow);
+       return __hash_long(n * pow(rand, zs->pareto_pow)) % zs->nranges;
 }
 }