Fix bad alignment in buffer size allocation
authorJens Axboe <jens.axboe@oracle.com>
Thu, 19 Jul 2007 08:17:09 +0000 (10:17 +0200)
committerJens Axboe <jens.axboe@oracle.com>
Thu, 19 Jul 2007 08:17:09 +0000 (10:17 +0200)
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 <jens.axboe@oracle.com>
fio.c

diff --git a/fio.c b/fio.c
index fcf3ae80c1fd5316c0ce121434eef2426b4471fe..94da6b48744ca7a5bc9fccb019e082c2fb01da30 100644 (file)
--- 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;