[PATCH] fio: use one big allocation for io units
authorJens Axboe <axboe@suse.de>
Wed, 26 Oct 2005 14:47:33 +0000 (16:47 +0200)
committerJens Axboe <axboe@suse.de>
Wed, 26 Oct 2005 14:47:33 +0000 (16:47 +0200)
fio.c

diff --git a/fio.c b/fio.c
index e7bdaeadf9f2df0e2058e69c41c2ee8448622fc1..345bd33afebdeff355494ae6b2f25bf14e2fa9fb 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -166,7 +166,6 @@ struct io_u {
        struct timeval start_time;
        struct timeval issue_time;
 
-       void *mem;
        char *buf;
        unsigned int buflen;
        unsigned long long offset;
@@ -202,6 +201,7 @@ struct thread_data {
        int error;
        int fd;
        pid_t pid;
+       char *orig_buffer;
        volatile int terminate;
        volatile int runstate;
        unsigned int ddir;
@@ -790,31 +790,36 @@ static void cleanup_io_u(struct thread_data *td)
                io_u = list_entry(entry, struct io_u, list);
 
                list_del(&io_u->list);
-               free(io_u->mem);
                free(io_u);
        }
+
+       free(td->orig_buffer);
 }
 
 static void init_io_u(struct thread_data *td)
 {
        struct io_u *io_u;
        int i, max_units;
+       char *p;
 
        if (!td->use_aio)
                max_units = 1;
        else
                max_units = td->aio_depth;
 
+       p = malloc(td->bs * max_units + MASK);
+       td->orig_buffer = ALIGN(p);
+
        INIT_LIST_HEAD(&td->io_u_freelist);
        INIT_LIST_HEAD(&td->io_u_busylist);
 
+       p = td->orig_buffer;
        for (i = 0; i < max_units; i++) {
                io_u = malloc(sizeof(*io_u));
                memset(io_u, 0, sizeof(*io_u));
                INIT_LIST_HEAD(&io_u->list);
 
-               io_u->mem = malloc(td->bs + MASK);
-               io_u->buf = ALIGN(io_u->mem);
+               io_u->buf = p + td->bs * i;
                io_u->buflen = td->bs;
 
                list_add(&io_u->list, &td->io_u_freelist);