From 687270767de17dbad53c50e03e5d73d52505405c Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Thu, 15 Mar 2007 20:49:25 +0100 Subject: [PATCH] Untangle the file creation mess Still needs a lot of work, will do a rewrite of this soonish. At least it should work now. Signed-off-by: Jens Axboe --- filesetup.c | 78 +++++++++++++++++++++++++++++++++++++++++------------ fio.c | 3 +++ fio.h | 1 + init.c | 18 +------------ 4 files changed, 66 insertions(+), 34 deletions(-) diff --git a/filesetup.c b/filesetup.c index 3b3f8684..08155db1 100644 --- a/filesetup.c +++ b/filesetup.c @@ -119,6 +119,28 @@ static unsigned long long set_rand_file_size(struct thread_data *td, return ret; } +static int fill_file_size(struct thread_data *td, struct fio_file *f, + unsigned long long *file_size, int new_files) +{ + if (!td->o.file_size_low) { + f->file_size = *file_size / new_files; + f->real_file_size = f->file_size; + } else { + /* + * If we don't have enough space left for a file + * of the minimum size, bail. + */ + if (*file_size < td->o.file_size_low) + return 1; + + f->file_size = set_rand_file_size(td, *file_size); + f->real_file_size = f->file_size; + *file_size -= f->file_size; + } + + return 0; +} + static int create_files(struct thread_data *td) { struct fio_file *f; @@ -150,8 +172,17 @@ static int create_files(struct thread_data *td) * unless specifically asked for overwrite, let normal io extend it */ can_extend = !td->o.overwrite && !(td->io_ops->flags & FIO_NOEXTEND); - if (can_extend) + if (can_extend) { + for_each_file(td, f, i) { + if (fill_file_size(td, f, &total_file_size, new_files)) { + log_info("fio: limited to %d files\n", i); + td->o.nr_files = i; + break; + } + } + return 0; + } local_file_size = total_file_size; if (!local_file_size) @@ -170,22 +201,11 @@ static int create_files(struct thread_data *td) continue; } - if (!td->o.file_size_low) - f->file_size = total_file_size / new_files; - else { - /* - * If we don't have enough space left for a file - * of the minimum size, bail. - */ - if (local_file_size < td->o.file_size_low) { - log_info("fio: limited to %d files\n", i); - new_files -= (td->o.nr_files - i); - td->o.nr_files = i; - break; - } - - f->file_size = set_rand_file_size(td, local_file_size); - local_file_size -= f->file_size; + if (fill_file_size(td, f, &local_file_size, new_files)) { + log_info("fio: limited to %d files\n", i); + new_files -= (td->o.nr_files - i); + td->o.nr_files = i; + break; } total_file_size += f->file_size; @@ -461,6 +481,30 @@ int setup_files(struct thread_data *td) return err; } +int init_random_map(struct thread_data *td) +{ + int num_maps, blocks; + struct fio_file *f; + unsigned int i; + + if (td->o.norandommap) + return 0; + + for_each_file(td, f, i) { + blocks = (f->real_file_size + td->o.rw_min_bs - 1) / td->o.rw_min_bs; + num_maps = (blocks + BLOCKS_PER_MAP-1)/ BLOCKS_PER_MAP; + f->file_map = malloc(num_maps * sizeof(long)); + if (!f->file_map) { + log_err("fio: failed allocating random map. If running a large number of jobs, try the 'norandommap' option\n"); + return 1; + } + f->num_maps = num_maps; + memset(f->file_map, 0, num_maps * sizeof(long)); + } + + return 0; +} + void close_files(struct thread_data *td) { struct fio_file *f; diff --git a/fio.c b/fio.c index de5c976e..a4168564 100644 --- a/fio.c +++ b/fio.c @@ -773,6 +773,9 @@ static void *thread_main(void *data) if (open_files(td)) goto err; + if (init_random_map(td)) + goto err; + if (td->o.exec_prerun) { if (system(td->o.exec_prerun) < 0) goto err; diff --git a/fio.h b/fio.h index cfbe3783..6e9311be 100644 --- a/fio.h +++ b/fio.h @@ -692,6 +692,7 @@ extern void add_file(struct thread_data *, const char *); extern void get_file(struct fio_file *); extern void put_file(struct thread_data *, struct fio_file *); extern int add_dir_files(struct thread_data *, const char *); +extern int init_random_map(struct thread_data *); /* * ETA/status stuff diff --git a/init.c b/init.c index e38d6778..23fe8dc6 100644 --- a/init.c +++ b/init.c @@ -323,9 +323,7 @@ static int exists_and_not_file(const char *filename) static int init_random_state(struct thread_data *td) { unsigned long seeds[6]; - int fd, num_maps, blocks; - struct fio_file *f; - unsigned int i; + int fd; fd = open("/dev/urandom", O_RDONLY); if (fd == -1) { @@ -356,20 +354,6 @@ static int init_random_state(struct thread_data *td) if (td->o.rand_repeatable) seeds[4] = FIO_RANDSEED * td->thread_number; - if (!td->o.norandommap) { - for_each_file(td, f, i) { - blocks = (f->real_file_size + td->o.rw_min_bs - 1) / td->o.rw_min_bs; - num_maps = (blocks + BLOCKS_PER_MAP-1)/ BLOCKS_PER_MAP; - f->file_map = malloc(num_maps * sizeof(long)); - if (!f->file_map) { - log_err("fio: failed allocating random map. If running a large number of jobs, try the 'norandommap' option\n"); - return 1; - } - f->num_maps = num_maps; - memset(f->file_map, 0, num_maps * sizeof(long)); - } - } - os_random_seed(seeds[4], &td->random_state); return 0; } -- 2.25.1