Skip to content

Commit

Permalink
bdevperf: use rand_r() twice to get 64-bit values
Browse files Browse the repository at this point in the history
rand_r() only returns up to RAND_MAX which is
INT32_MAX.  This means that on sufficiently large
bdevs, especially with smaller block sizes, bdevperf
may not be issuing I/O across the full range of the
bdev.

Found while investigating issue spdk#2908.

Signed-off-by: Jim Harris <[email protected]>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/16768 (master)

(cherry picked from commit 0d11cf9)
Change-Id: I16db684a57a96f138e709008bded4471428944b6
Signed-off-by: Krzysztof Karas <[email protected]>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/17693
Reviewed-by: Ben Walker <[email protected]>
Reviewed-by: Konrad Sztyber <[email protected]>
Tested-by: SPDK CI Jenkins <[email protected]>
Reviewed-by: Jim Harris <[email protected]>
  • Loading branch information
jimharris committed Apr 24, 2023
1 parent b2e6e62 commit 503d8e8
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion examples/bdev/bdevperf/bdevperf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1094,11 +1094,17 @@ static void
bdevperf_submit_single(struct bdevperf_job *job, struct bdevperf_task *task)
{
uint64_t offset_in_ios;
uint64_t rand_value;

if (job->zipf) {
offset_in_ios = spdk_zipf_generate(job->zipf);
} else if (job->is_random) {
offset_in_ios = rand_r(&job->seed) % job->size_in_ios;
/* RAND_MAX is only INT32_MAX, so use 2 calls to rand_r to
* get a large enough value to ensure we are issuing I/O
* uniformly across the whole bdev.
*/
rand_value = (uint64_t)rand_r(&job->seed) * RAND_MAX + rand_r(&job->seed);
offset_in_ios = rand_value % job->size_in_ios;
} else {
offset_in_ios = job->offset_in_ios++;
if (job->offset_in_ios == job->size_in_ios) {
Expand Down

0 comments on commit 503d8e8

Please sign in to comment.