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 \
#include "cgroup.h"
#include "profile.h"
#include "lib/rand.h"
+#include "memalign.h"
unsigned long page_mask;
unsigned long page_size;
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);
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;
}
--- /dev/null
+#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);
+}
--- /dev/null
+#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