From fc99bc0d82371cc704395a7718e78abd0e0d2709 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Wed, 4 Mar 2009 15:27:42 +0100 Subject: [PATCH] Realloc td->files to full size immediately For adding many files, we do as many reallocs() as we have files. This is slow, so do full allocs instead. Signed-off-by: Jens Axboe --- filesetup.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/filesetup.c b/filesetup.c index 088b77c3..461f130c 100644 --- a/filesetup.c +++ b/filesetup.c @@ -714,10 +714,15 @@ int add_file(struct thread_data *td, const char *fname) f->fd = -1; - dprint(FD_FILE, "resize file array to %d files\n", cur_files + 1); + if (td->files_size <= td->files_index) { + int new_size = td->o.nr_files; - td->files = realloc(td->files, (cur_files + 1) * sizeof(f)); - td->files[cur_files] = f; + dprint(FD_FILE, "resize file array to %d files\n", new_size); + + td->files = realloc(td->files, new_size * sizeof(f)); + td->files[cur_files] = f; + td->files_size = new_size; + } /* * init function, io engine may not be loaded yet -- 2.25.1