mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
added missing implementation for aligned memory allocator
This commit is contained in:
parent
b8a8476a92
commit
bfec0b2f00
3 changed files with 24 additions and 12 deletions
|
@ -15,7 +15,7 @@
|
|||
|
||||
#define HUGEPAGESIZE (1 << 21)
|
||||
|
||||
typedef void *(*memzone_allocator_t)(size_t len);
|
||||
typedef void *(*memzone_allocator_t)(size_t len, size_t alignment);
|
||||
typedef int (*memzone_deallocator_t)(void *ptr, size_t len);
|
||||
|
||||
enum memtype_flags {
|
||||
|
|
29
lib/memory.c
29
lib/memory.c
|
@ -34,15 +34,20 @@ int memory_init()
|
|||
|
||||
void * memory_alloc(const struct memtype *m, size_t len)
|
||||
{
|
||||
debug(DBG_MEM | 2, "Allocating %#zx bytes of %s memory", len, m->name);
|
||||
return m->alloc(len);
|
||||
void *ptr = m->alloc(len, sizeof(void *));
|
||||
|
||||
debug(DBG_MEM | 2, "Allocated %#zx bytes of %s memory: %p", len, m->name, ptr);
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void * memory_alloc_aligned(const struct memtype *m, size_t len, size_t alignment)
|
||||
{
|
||||
debug(DBG_MEM | 2, "Allocating %#zx bytes of %#zx-byte-aligned %s memory", len, alignment, m->name);
|
||||
warn("%s: not implemented yet!", __FUNCTION__);
|
||||
return memory_alloc(m, len);
|
||||
void *ptr = m->alloc(len, alignment);
|
||||
|
||||
debug(DBG_MEM | 2, "Allocated %#zx bytes of %#zx-byte-aligned %s memory: %p", len, alignment, m->name, ptr);
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
int memory_free(const struct memtype *m, void *ptr, size_t len)
|
||||
|
@ -51,9 +56,17 @@ int memory_free(const struct memtype *m, void *ptr, size_t len)
|
|||
return m->free(ptr, len);
|
||||
}
|
||||
|
||||
static void * memory_heap_alloc(size_t len)
|
||||
static void * memory_heap_alloc(size_t len, size_t alignment)
|
||||
{
|
||||
return malloc(len);
|
||||
void *ptr;
|
||||
int ret;
|
||||
|
||||
if (alignment < sizeof(void *))
|
||||
alignment = sizeof(void *);
|
||||
|
||||
ret = posix_memalign(&ptr, alignment, len);
|
||||
|
||||
return ret ? NULL : ptr;
|
||||
}
|
||||
|
||||
int memory_heap_free(void *ptr, size_t len)
|
||||
|
@ -64,7 +77,7 @@ int memory_heap_free(void *ptr, size_t len)
|
|||
}
|
||||
|
||||
/** Allocate memory backed by hugepages with malloc() like interface */
|
||||
static void * memory_hugepage_alloc(size_t len)
|
||||
static void * memory_hugepage_alloc(size_t len, size_t alignment)
|
||||
{
|
||||
int prot = PROT_READ | PROT_WRITE;
|
||||
int flags = MAP_PRIVATE | MAP_ANONYMOUS;
|
||||
|
|
|
@ -15,8 +15,7 @@
|
|||
#include "utils.h"
|
||||
|
||||
TheoryDataPoints(memory, aligned) = {
|
||||
// DataPoints(size_t, 1, 32, 55, 1 << 10, 1 << 20),
|
||||
DataPoints(size_t, 1<<12),
|
||||
DataPoints(size_t, 1, 32, 55, 1 << 10, 1 << 20),
|
||||
DataPoints(size_t, 1, 8, 1 << 12),
|
||||
DataPoints(const struct memtype *, &memtype_heap, &memtype_hugepage)
|
||||
};
|
||||
|
@ -28,7 +27,7 @@ Theory((size_t len, size_t align, const struct memtype *m), memory, aligned) {
|
|||
ptr = memory_alloc_aligned(m, len, align);
|
||||
cr_assert_neq(ptr, NULL, "Failed to allocate memory");
|
||||
|
||||
//cr_assert(IS_ALIGNED(ptr, align));
|
||||
cr_assert(IS_ALIGNED(ptr, align));
|
||||
|
||||
if (m == &memtype_hugepage) {
|
||||
cr_assert(IS_ALIGNED(ptr, HUGEPAGESIZE));
|
||||
|
|
Loading…
Add table
Reference in a new issue