From c39906450ba553a65545c90863addde0152a465e Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Thu, 19 Jul 2007 10:17:09 +0200 Subject: [PATCH] Fix bad alignment in buffer size allocation We typically end up allocating a block more than we need. Usually not a problem for normal memory, but when we are dealing with scarce resources such as hugepages, it can be problematic. For many threads the memory waste could also be a problem. Signed-off-by: Jens Axboe --- fio.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/fio.c b/fio.c index fcf3ae80..94da6b48 100644 --- a/fio.c +++ b/fio.c @@ -614,7 +614,6 @@ static void fill_io_buf(struct thread_data *td, struct io_u *io_u, int max_bs) static int init_io_u(struct thread_data *td) { - unsigned long long buf_size; struct io_u *io_u; unsigned int max_bs; int i, max_units; @@ -626,20 +625,18 @@ static int init_io_u(struct thread_data *td) max_units = td->o.iodepth; max_bs = max(td->o.max_bs[DDIR_READ], td->o.max_bs[DDIR_WRITE]); - buf_size = (unsigned long long) max_bs * (unsigned long long) max_units; - buf_size += page_mask; - if (buf_size != (size_t) buf_size) { - log_err("fio: IO memory too large. Reduce max_bs or iodepth\n"); - return 1; - } - - td->orig_buffer_size = buf_size; + td->orig_buffer_size = (unsigned long long) max_bs * (unsigned long long) max_units; if (td->o.mem_type == MEM_SHMHUGE || td->o.mem_type == MEM_MMAPHUGE) td->orig_buffer_size = (td->orig_buffer_size + td->o.hugepage_size - 1) & ~(td->o.hugepage_size - 1); else if (td->orig_buffer_size & page_mask) td->orig_buffer_size = (td->orig_buffer_size + page_mask) & ~page_mask; + if (td->orig_buffer_size != (size_t) td->orig_buffer_size) { + log_err("fio: IO memory too large. Reduce max_bs or iodepth\n"); + return 1; + } + if (allocate_io_mem(td)) return 1; -- 2.25.1