summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2018-09-17 11:00:50 -0600
committerJens Axboe <axboe@kernel.dk>2018-09-17 11:00:50 -0600
commitabb60c32c26d6421283d2a72170508dfb2b94507 (patch)
treeee809dbb1edb67e54e9cdcdc445ef8b2180ff35d
parenta0c84dd4354eaf0a84b8bf0a3126f65301f2206f (diff)
downloadfio-abb60c32c26d6421283d2a72170508dfb2b94507.tar.gz
fio-abb60c32c26d6421283d2a72170508dfb2b94507.tar.bz2
Random distribution 32-bit fixes
We calculate and use nranges as an unsigned long, but that can be 32-bit on some platforms and hence overflow. Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--filesetup.c4
-rw-r--r--lib/zipf.c12
-rw-r--r--lib/zipf.h8
3 files changed, 12 insertions, 12 deletions
diff --git a/filesetup.c b/filesetup.c
index 580403db..6108ca30 100644
--- a/filesetup.c
+++ b/filesetup.c
@@ -1192,13 +1192,13 @@ bool pre_read_files(struct thread_data *td)
static void __init_rand_distribution(struct thread_data *td, struct fio_file *f)
{
unsigned int range_size, seed;
- unsigned long nranges;
+ uint64_t nranges;
uint64_t fsize;
range_size = min(td->o.min_bs[DDIR_READ], td->o.min_bs[DDIR_WRITE]);
fsize = min(f->real_file_size, f->io_size);
- nranges = (fsize + range_size - 1) / range_size;
+ 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)
diff --git a/lib/zipf.c b/lib/zipf.c
index 1ff85680..321a4fb9 100644
--- a/lib/zipf.c
+++ b/lib/zipf.c
@@ -8,7 +8,7 @@
static void zipf_update(struct zipf_state *zs)
{
- unsigned long to_gen;
+ uint64_t to_gen;
unsigned int i;
/*
@@ -22,7 +22,7 @@ static void zipf_update(struct zipf_state *zs)
zs->zetan += pow(1.0 / (double) (i + 1), zs->theta);
}
-static void shared_rand_init(struct zipf_state *zs, unsigned long nranges,
+static void shared_rand_init(struct zipf_state *zs, uint64_t nranges,
unsigned int seed)
{
memset(zs, 0, sizeof(*zs));
@@ -32,7 +32,7 @@ static void shared_rand_init(struct zipf_state *zs, unsigned long nranges,
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, uint64_t nranges, double theta,
unsigned int seed)
{
shared_rand_init(zs, nranges, seed);
@@ -43,7 +43,7 @@ void zipf_init(struct zipf_state *zs, unsigned long nranges, double theta,
zipf_update(zs);
}
-unsigned long long zipf_next(struct zipf_state *zs)
+uint64_t zipf_next(struct zipf_state *zs)
{
double alpha, eta, rand_uni, rand_z;
unsigned long long n = zs->nranges;
@@ -70,14 +70,14 @@ unsigned long long zipf_next(struct zipf_state *zs)
return (val + zs->rand_off) % zs->nranges;
}
-void pareto_init(struct zipf_state *zs, unsigned long nranges, double h,
+void pareto_init(struct zipf_state *zs, uint64_t nranges, double h,
unsigned int seed)
{
shared_rand_init(zs, nranges, seed);
zs->pareto_pow = log(h) / log(1.0 - h);
}
-unsigned long long pareto_next(struct zipf_state *zs)
+uint64_t pareto_next(struct zipf_state *zs)
{
double rand = (double) __rand(&zs->rand) / (double) FRAND32_MAX;
unsigned long long n;
diff --git a/lib/zipf.h b/lib/zipf.h
index a4aa163c..16b65f57 100644
--- a/lib/zipf.h
+++ b/lib/zipf.h
@@ -16,11 +16,11 @@ struct zipf_state {
bool disable_hash;
};
-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 zipf_init(struct zipf_state *zs, uint64_t nranges, double theta, unsigned int seed);
+uint64_t zipf_next(struct zipf_state *zs);
-void pareto_init(struct zipf_state *zs, unsigned long nranges, double h, unsigned int seed);
-unsigned long long pareto_next(struct zipf_state *zs);
+void pareto_init(struct zipf_state *zs, uint64_t nranges, double h, unsigned int seed);
+uint64_t pareto_next(struct zipf_state *zs);
void zipf_disable_hash(struct zipf_state *zs);
#endif