From 43c63a78d3f902b4bf941841579834bbfabd5c62 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Mon, 21 May 2007 13:23:30 +0200 Subject: [PATCH 1/1] Improve random pattern without norandommap Using the random map, random workloads have a natural tendency to get less random at the end of the run, due to failures to find a new unused random offset. Improve the logic to avoid this problem. Signed-off-by: Jens Axboe --- io_u.c | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/io_u.c b/io_u.c index e892ec75..c824d7ec 100644 --- a/io_u.c +++ b/io_u.c @@ -109,20 +109,40 @@ static int get_next_rand_offset(struct thread_data *td, struct fio_file *f, *b = 0; else *b = ((max_blocks - 1) * r / (unsigned long long) (RAND_MAX+1.0)); + /* + * if we are not maintaining a random map, we are done. + */ if (td->o.norandommap) - break; + return 0; + + /* + * calculate map offset and chec if it's free + */ rb = *b + (f->file_offset / td->o.min_bs[ddir]); - loops--; - } while (!random_map_free(td, f, rb) && loops); + if (random_map_free(td, f, rb)) + return 0; + + } while (--loops); /* - * if we failed to retrieve a truly random offset within - * the loops assigned, see if there are free ones left at all + * we get here, if we didn't suceed in looking up a block. generate + * a random start offset into the filemap, and find the first free + * block from there. */ - if (!loops && get_next_free_block(td, f, b)) - return 1; + loops = 10; + do { + f->last_free_lookup = (f->num_maps - 1) * (r / (RAND_MAX+1.0)); + if (!get_next_free_block(td, f, b)) + return 0; - return 0; + r = os_random_long(&td->random_state); + } while (--loops); + + /* + * that didn't work either, try exhaustive search from the start + */ + f->last_free_lookup = 0; + return get_next_free_block(td, f, b); } /* -- 2.25.1