summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAdam Kupczyk <akupczyk@redhat.com>2020-12-29 13:17:17 +0100
committerAdam Kupczyk <akupczyk@redhat.com>2021-01-11 17:18:28 +0100
commita87c90fd72823d5438d724e5a57ced8d1f7bed3f (patch)
treee0a4a223d1649cbcf045fcb9568456adce0876d3 /lib
parent674428a527931d86bfb164abcc847508b3be2742 (diff)
downloadfio-a87c90fd72823d5438d724e5a57ced8d1f7bed3f.tar.gz
fio-a87c90fd72823d5438d724e5a57ced8d1f7bed3f.tar.bz2
distibutions: Extend flexibility of non-uniform random distributions
This change affects options random_distribution and file_service_type. For pareto, zipf and gauss distribution a contept of `center` is implemented. It allows to fix in place a value that is most probable to access. Example: fio --randseed=1 --ioengine=libaio --rw=randwrite --nrfiles=16 --bs=4k \ --size=256m --allow_file_create=1 --write_iolog=log.txt \ --file_service_type=gauss:10:0.1 --filename_format=object.\$filenum --name=x cat log.txt |grep write |cut -f 1 -d " " |sort |uniq -c | sort -n | \ sed "s/[.]/ /" | while read a b c; do echo $c $b $a; done |sort -n 0 object 13429 1 object 17928 2 object 14724 3 object 7845 4 object 2476 5 object 468 6 object 44 7 object 3 12 object 24 13 object 318 14 object 1795 15 object 6482 Signed-off-by: Adam Kupczyk <akupczyk@redhat.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/gauss.c8
-rw-r--r--lib/gauss.h3
-rw-r--r--lib/zipf.c12
-rw-r--r--lib/zipf.h6
4 files changed, 19 insertions, 10 deletions
diff --git a/lib/gauss.c b/lib/gauss.c
index 3f84dbc6..c64f61e7 100644
--- a/lib/gauss.c
+++ b/lib/gauss.c
@@ -40,11 +40,11 @@ unsigned long long gauss_next(struct gauss_state *gs)
if (!gs->disable_hash)
sum = __hash_u64(sum);
- return sum % gs->nranges;
+ return (sum + gs->rand_off) % gs->nranges;
}
void gauss_init(struct gauss_state *gs, unsigned long nranges, double dev,
- unsigned int seed)
+ double center, unsigned int seed)
{
memset(gs, 0, sizeof(*gs));
init_rand_seed(&gs->r, seed, 0);
@@ -55,6 +55,10 @@ void gauss_init(struct gauss_state *gs, unsigned long nranges, double dev,
if (gs->stddev > nranges / 2)
gs->stddev = nranges / 2;
}
+ if (center == -1)
+ gs->rand_off = 0;
+ else
+ gs->rand_off = nranges * (center - 0.5);
}
void gauss_disable_hash(struct gauss_state *gs)
diff --git a/lib/gauss.h b/lib/gauss.h
index 478aa146..19e3a666 100644
--- a/lib/gauss.h
+++ b/lib/gauss.h
@@ -8,11 +8,12 @@ struct gauss_state {
struct frand_state r;
uint64_t nranges;
unsigned int stddev;
+ unsigned int rand_off;
bool disable_hash;
};
void gauss_init(struct gauss_state *gs, unsigned long nranges, double dev,
- unsigned int seed);
+ double center, unsigned int seed);
unsigned long long gauss_next(struct gauss_state *gs);
void gauss_disable_hash(struct gauss_state *gs);
diff --git a/lib/zipf.c b/lib/zipf.c
index 321a4fb9..14d7928f 100644
--- a/lib/zipf.c
+++ b/lib/zipf.c
@@ -23,19 +23,21 @@ static void zipf_update(struct zipf_state *zs)
}
static void shared_rand_init(struct zipf_state *zs, uint64_t nranges,
- unsigned int seed)
+ double center, unsigned int seed)
{
memset(zs, 0, sizeof(*zs));
zs->nranges = nranges;
init_rand_seed(&zs->rand, seed, 0);
zs->rand_off = __rand(&zs->rand);
+ if (center != -1)
+ zs->rand_off = nranges * center;
}
void zipf_init(struct zipf_state *zs, uint64_t nranges, double theta,
- unsigned int seed)
+ double center, unsigned int seed)
{
- shared_rand_init(zs, nranges, seed);
+ shared_rand_init(zs, nranges, center, seed);
zs->theta = theta;
zs->zeta2 = pow(1.0, zs->theta) + pow(0.5, zs->theta);
@@ -71,9 +73,9 @@ uint64_t zipf_next(struct zipf_state *zs)
}
void pareto_init(struct zipf_state *zs, uint64_t nranges, double h,
- unsigned int seed)
+ double center, unsigned int seed)
{
- shared_rand_init(zs, nranges, seed);
+ shared_rand_init(zs, nranges, center, seed);
zs->pareto_pow = log(h) / log(1.0 - h);
}
diff --git a/lib/zipf.h b/lib/zipf.h
index 16b65f57..332e3b2f 100644
--- a/lib/zipf.h
+++ b/lib/zipf.h
@@ -16,10 +16,12 @@ struct zipf_state {
bool disable_hash;
};
-void zipf_init(struct zipf_state *zs, uint64_t nranges, double theta, unsigned int seed);
+void zipf_init(struct zipf_state *zs, uint64_t nranges, double theta,
+ double center, unsigned int seed);
uint64_t zipf_next(struct zipf_state *zs);
-void pareto_init(struct zipf_state *zs, uint64_t nranges, double h, unsigned int seed);
+void pareto_init(struct zipf_state *zs, uint64_t nranges, double h,
+ double center, unsigned int seed);
uint64_t pareto_next(struct zipf_state *zs);
void zipf_disable_hash(struct zipf_state *zs);