The following changes since commit 7e8ad197a8d219e2fc181c881143f11891e7d0d5: os-mac.h: implement fio_set_odirect() (2011-04-23 13:46:59 +0200) are available in the git repository at: git://git.kernel.dk/fio.git master Jens Axboe (2): Add simple aligned alloc helper Remove solaris posix_memalign() helper Makefile | 5 +++-- fio.c | 8 +++++--- memalign.c | 35 +++++++++++++++++++++++++++++++++++ memalign.h | 7 +++++++ solaris.c | 16 ---------------- 5 files changed, 50 insertions(+), 21 deletions(-) create mode 100644 memalign.c create mode 100644 memalign.h delete mode 100644 solaris.c --- Diff of recent changes: diff --git a/Makefile b/Makefile index 1d81562..c45a1b1 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,8 @@ SOURCE = gettime.c fio.c ioengines.c init.c stat.c log.c time.c filesetup.c \ eta.c verify.c memory.c io_u.c parse.c mutex.c options.c \ rbtree.c smalloc.c filehash.c profile.c debug.c lib/rand.c \ lib/num2str.c $(wildcard crc/*.c) engines/cpu.c \ - engines/mmap.c engines/sync.c engines/null.c engines/net.c + engines/mmap.c engines/sync.c engines/null.c engines/net.c \ + memalign.c ifeq ($(UNAME), Linux) SOURCE += diskutil.c fifo.c blktrace.c helpers.c cgroup.c trim.c \ @@ -24,7 +25,7 @@ ifeq ($(UNAME), Linux) CFLAGS += -rdynamic endif ifeq ($(UNAME), SunOS) - SOURCE += fifo.c lib/strsep.c helpers.c solaris.c engines/posixaio.c \ + SOURCE += fifo.c lib/strsep.c helpers.c engines/posixaio.c \ engines/solarisaio.c LIBS += -lpthread -ldl -laio -lrt -lnsl -lsocket CPPFLAGS += -D__EXTENSIONS__ diff --git a/fio.c b/fio.c index e205b3a..a737a31 100644 --- a/fio.c +++ b/fio.c @@ -45,6 +45,7 @@ #include "cgroup.h" #include "profile.h" #include "lib/rand.h" +#include "memalign.h" unsigned long page_mask; unsigned long page_size; @@ -796,7 +797,7 @@ static void cleanup_io_u(struct thread_data *td) io_u = flist_entry(entry, struct io_u, list); flist_del(&io_u->list); - free(io_u); + fio_memfree(io_u, sizeof(*io_u)); } free_io_mem(td); @@ -843,8 +844,9 @@ static int init_io_u(struct thread_data *td) if (td->terminate) return 1; - if (posix_memalign(&ptr, cl_align, sizeof(*io_u))) { - log_err("fio: posix_memalign=%s\n", strerror(errno)); + ptr = fio_memalign(cl_align, sizeof(*io_u)); + if (!ptr) { + log_err("fio: unable to allocate aligned memory\n"); break; } diff --git a/memalign.c b/memalign.c new file mode 100644 index 0000000..87667b4 --- /dev/null +++ b/memalign.c @@ -0,0 +1,35 @@ +#include <stdlib.h> +#include <assert.h> + +#include "memalign.h" + +struct align_footer { + unsigned int offset; +}; + +#define PTR_ALIGN(ptr, mask) \ + (char *) (((unsigned long) ((ptr) + (mask)) & ~(mask))) + +void *fio_memalign(size_t alignment, size_t size) +{ + struct align_footer *f; + void *ptr, *ret = NULL; + + assert(!(alignment & (alignment - 1))); + + ptr = malloc(size + alignment + size + sizeof(*f) - 1); + if (ptr) { + ret = PTR_ALIGN(ptr, alignment); + f = ret + size; + f->offset = (unsigned long) ret - (unsigned long) ptr; + } + + return ret; +} + +void fio_memfree(void *ptr, size_t size) +{ + struct align_footer *f = ptr + size; + + free(ptr - f->offset); +} diff --git a/memalign.h b/memalign.h new file mode 100644 index 0000000..df412e2 --- /dev/null +++ b/memalign.h @@ -0,0 +1,7 @@ +#ifndef FIO_MEMALIGN_H +#define FIO_MEMALIGN_H + +extern void *fio_memalign(size_t alignment, size_t size); +extern void fio_memfree(void *ptr, size_t size); + +#endif diff --git a/solaris.c b/solaris.c deleted file mode 100644 index 869e8d8..0000000 --- a/solaris.c +++ /dev/null @@ -1,16 +0,0 @@ -#include <stdlib.h> -#include <errno.h> -#include "compiler/compiler.h" - -/* - * Some Solaris versions don't have posix_memalign(), provide a private - * weak alternative - */ -int __weak posix_memalign(void **ptr, size_t align, size_t size) -{ - *ptr = memalign(align, size); - if (*ptr) - return 0; - - return ENOMEM; -} -- To unsubscribe from this list: send the line "unsubscribe fio" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html