diff --git a/include/villas/memory.h b/include/villas/memory.h index b21d1b1a4..cf1d7acd5 100644 --- a/include/villas/memory.h +++ b/include/villas/memory.h @@ -13,6 +13,8 @@ #ifndef _MEMORY_H_ #define _MEMORY_H_ +#define HUGEPAGESIZE (1 << 21) + typedef void *(*memzone_allocator_t)(size_t len); typedef int (*memzone_deallocator_t)(void *ptr, size_t len); diff --git a/lib/memory.c b/lib/memory.c index df4eccd7e..7525a1c0c 100644 --- a/lib/memory.c +++ b/lib/memory.c @@ -65,6 +65,8 @@ static void * memory_hugepage_alloc(size_t len) static int memory_hugepage_free(void *ptr, size_t len) { + len = ALIGN(len, HUGEPAGESIZE); /* ugly see: https://lkml.org/lkml/2015/3/27/171 */ + return munmap(ptr, len); } diff --git a/tests/memory.c b/tests/memory.c index fc40bd610..234e6defd 100644 --- a/tests/memory.c +++ b/tests/memory.c @@ -14,8 +14,6 @@ #include "memory.h" #include "utils.h" -#define HUGEPAGESIZE (1 << 21) - TheoryDataPoints(memory, aligned) = { // DataPoints(size_t, 1, 32, 55, 1 << 10, 1 << 20), DataPoints(size_t, 1<<12), @@ -31,12 +29,11 @@ Theory((size_t len, size_t align, const struct memtype *m), memory, aligned) { cr_assert_neq(ptr, NULL, "Failed to allocate memory"); //cr_assert(IS_ALIGNED(ptr, align)); - + if (m == &memtype_hugepage) { cr_assert(IS_ALIGNED(ptr, HUGEPAGESIZE)); - len = ALIGN(len, HUGEPAGESIZE); /* ugly see: https://lkml.org/lkml/2015/3/27/171 */ } - + ret = memory_free(m, ptr, len); cr_assert_eq(ret, 0, "Failed to release memory: ret=%d, ptr=%p, len=%zu: %s", ret, ptr, len, strerror(errno)); } \ No newline at end of file