diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index acc57b3e6..7de34db24 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,8 +6,8 @@ variables: CRITERION_OPTS: --ignore-warnings DOCKER_FILE: packaging/docker/Dockerfile.dev DOCKER_TAG: ${CI_COMMIT_REF_NAME} - DOCKER_IMAGE: villas/node - DOCKER_IMAGE_DEV: villas/node-dev + DOCKER_IMAGE: registry.git.rwth-aachen.de/acs/public/villas/villasnode/node + DOCKER_IMAGE_DEV: registry.git.rwth-aachen.de/acs/public/villas/villasnode/node-dev MAKE_OPTS: -j32 RELEASEVER: 29 @@ -170,6 +170,8 @@ test:integration: packaging:docker: stage: packaging + before_script: + - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY script: - docker build --build-arg BUILDER_IMAGE=${DOCKER_IMAGE_DEV}:${DOCKER_TAG} diff --git a/include/villas/memory.h b/include/villas/memory.h index a7d370dac..a82991fc2 100644 --- a/include/villas/memory.h +++ b/include/villas/memory.h @@ -73,9 +73,9 @@ int memory_lock(size_t lock); * @retval nullptr If allocation failed. * @retval <>0 If allocation was successful. */ -void * memory_alloc(struct memory_type *m, size_t len); +void * memory_alloc(size_t len, struct memory_type *m = memory_default); -void * memory_alloc_aligned(struct memory_type *m, size_t len, size_t alignment); +void * memory_alloc_aligned(size_t len, size_t alignment, struct memory_type *m = memory_default); int memory_free(void *ptr); diff --git a/include/villas/memory/ib.h b/include/villas/memory/ib.h index 356c1efa2..6e0f98041 100644 --- a/include/villas/memory/ib.h +++ b/include/villas/memory/ib.h @@ -26,8 +26,8 @@ #include struct memory_ib { - struct ibv_pd *pd; - struct memory_type *parent; + struct ibv_pd *pd; + struct memory_type *parent; }; struct ibv_mr * memory_ib_get_mr(void *ptr); diff --git a/include/villas/memory_type.h b/include/villas/memory_type.h index 8e3a97e49..fbe2553d6 100644 --- a/include/villas/memory_type.h +++ b/include/villas/memory_type.h @@ -30,8 +30,8 @@ struct memory_type; struct node; -typedef struct memory_allocation * (*memory_allocator_t)(struct memory_type *mem, size_t len, size_t alignment); -typedef int (*memory_deallocator_t)(struct memory_type *mem, struct memory_allocation * ma); +typedef struct memory_allocation * (*memory_allocator_t)(size_t len, size_t alignment, struct memory_type *mem); +typedef int (*memory_deallocator_t)(struct memory_allocation * ma, struct memory_type *mem); enum class MemoryFlags { MMAP = (1 << 0), @@ -53,12 +53,11 @@ struct memory_type { }; extern struct memory_type memory_heap; -extern struct memory_type memory_hugepage; +extern struct memory_type memory_mmap; +extern struct memory_type memory_mmap_hugetlb; +extern struct memory_type *memory_default; struct memory_type * memory_ib(struct node *n, struct memory_type *parent); struct memory_type * memory_managed(void *ptr, size_t len); int memory_hugepage_init(int hugepages); - -struct memory_type * memory_type_lookup(enum MemoryFlags flags); - diff --git a/include/villas/node.h b/include/villas/node.h index ecb988920..e67f91175 100644 --- a/include/villas/node.h +++ b/include/villas/node.h @@ -193,7 +193,7 @@ struct node_type * node_type(struct node *n) return n->_vt; } -struct memory_type * node_memory_type(struct node *n, struct memory_type *parent); +struct memory_type * node_memory_type(struct node *n); bool node_is_valid_name(const char *name); diff --git a/include/villas/pool.h b/include/villas/pool.h index 259950080..8deec4774 100644 --- a/include/villas/pool.h +++ b/include/villas/pool.h @@ -57,7 +57,7 @@ struct pool { * @retval 0 The pool has been successfully initialized. * @retval <>0 There was an error during the pool initialization. */ -int pool_init(struct pool *p, size_t cnt, size_t blocksz, struct memory_type *mem); +int pool_init(struct pool *p, size_t cnt, size_t blocksz, struct memory_type *mem = memory_default); /** Destroy and release memory used by pool. */ int pool_destroy(struct pool *p); diff --git a/include/villas/queue.h b/include/villas/queue.h index dbb87af4a..95113f079 100644 --- a/include/villas/queue.h +++ b/include/villas/queue.h @@ -41,9 +41,7 @@ #include #include - -/* Forward declarations */ -struct memory_type; +#include typedef char cacheline_pad_t[CACHELINE_SIZE]; @@ -73,7 +71,7 @@ struct queue { }; /** Initialize MPMC queue */ -int queue_init(struct queue *q, size_t size, struct memory_type *mem); +int queue_init(struct queue *q, size_t size, struct memory_type *mem = memory_default); /** Desroy MPMC queue and release memory */ int queue_destroy(struct queue *q); diff --git a/include/villas/queue_signalled.h b/include/villas/queue_signalled.h index 916052cd1..e51a965ba 100644 --- a/include/villas/queue_signalled.h +++ b/include/villas/queue_signalled.h @@ -64,7 +64,7 @@ struct queue_signalled { #define queue_signalled_available(q) queue_available(&((q)->queue)) -int queue_signalled_init(struct queue_signalled *qs, size_t size, struct memory_type *mem, enum QueueSignalledMode mode = QueueSignalledMode::AUTO, int flags = 0); +int queue_signalled_init(struct queue_signalled *qs, size_t size, struct memory_type *mem = memory_default, enum QueueSignalledMode mode = QueueSignalledMode::AUTO, int flags = 0); int queue_signalled_destroy(struct queue_signalled *qs); diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 56e5d1ea8..a32728748 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -45,8 +45,8 @@ set(LIB_SRC mapping.cpp memory.cpp memory/heap.cpp - memory/hugepage.cpp memory/managed.cpp + memory/mmap.cpp node_direction.cpp node_type.cpp node.cpp diff --git a/lib/memory.cpp b/lib/memory.cpp index f649ef872..86cc9d3d9 100644 --- a/lib/memory.cpp +++ b/lib/memory.cpp @@ -44,9 +44,18 @@ int memory_init(int hugepages) info("Initialize memory sub-system: #hugepages=%d", hugepages); - ret = memory_hugepage_init(hugepages); - if (ret) - return ret; + if (hugepages > 0) { + ret = memory_hugepage_init(hugepages); + if (ret) + return ret; + + memory_default = &memory_mmap_hugetlb; + } + else { + memory_default = &memory_mmap; + + warning("Hugepage allocator disabled."); + } size_t lock = kernel_get_hugepage_size() * hugepages; @@ -105,16 +114,16 @@ int memory_lock(size_t lock) return 0; } -void * memory_alloc(struct memory_type *m, size_t len) +void * memory_alloc(size_t len, struct memory_type *m) { - return memory_alloc_aligned(m, len, sizeof(void *)); + return memory_alloc_aligned(len, sizeof(void *), m); } -void * memory_alloc_aligned(struct memory_type *m, size_t len, size_t alignment) +void * memory_alloc_aligned(size_t len, size_t alignment, struct memory_type *m) { - struct memory_allocation *ma = m->alloc(m, len, alignment); + struct memory_allocation *ma = m->alloc(len, alignment, m); if (ma == nullptr) { - warning("Memory allocation of type %s failed. reason=%s", m->name, strerror(errno) ); + warning("Memory allocation of type %s failed. reason=%s", m->name, strerror(errno)); return nullptr; } @@ -136,16 +145,16 @@ int memory_free(void *ptr) debug(LOG_MEM | 5, "Releasing %#zx bytes of %s memory: %p", ma->length, ma->type->name, ma->address); - ret = ma->type->free(ma->type, ma); + ret = ma->type->free(ma, ma->type); if (ret) return ret; /* Remove allocation entry */ auto iter = allocations.find(ptr); - if (iter == allocations.end()) + if (iter == allocations.end()) return -1; - allocations.erase(iter); + allocations.erase(iter); free(ma); return 0; @@ -156,12 +165,4 @@ struct memory_allocation * memory_get_allocation(void *ptr) return allocations[ptr]; } -struct memory_type * memory_type_lookup(enum MemoryFlags flags) -{ - if ((int) flags & (int) MemoryFlags::HUGEPAGE) - return &memory_hugepage; - else if ((int) flags & (int) MemoryFlags::HEAP) - return &memory_heap; - else - return nullptr; -} +struct memory_type *memory_default = nullptr; diff --git a/lib/memory/heap.cpp b/lib/memory/heap.cpp index c376a8cde..75c249f9c 100644 --- a/lib/memory/heap.cpp +++ b/lib/memory/heap.cpp @@ -27,7 +27,7 @@ using namespace villas::utils; -static struct memory_allocation * memory_heap_alloc(struct memory_type *m, size_t len, size_t alignment) +static struct memory_allocation * memory_heap_alloc(size_t len, size_t alignment, struct memory_type *m) { int ret; @@ -51,7 +51,7 @@ static struct memory_allocation * memory_heap_alloc(struct memory_type *m, size_ return ma; } -static int memory_heap_free(struct memory_type *m, struct memory_allocation *ma) +static int memory_heap_free(struct memory_allocation *ma, struct memory_type *m) { free(ma->address); diff --git a/lib/memory/ib.cpp b/lib/memory/ib.cpp index ddeaf4b09..add545d1c 100644 --- a/lib/memory/ib.cpp +++ b/lib/memory/ib.cpp @@ -40,7 +40,7 @@ struct ibv_mr * memory_ib_get_mr(void *ptr) return mr; } -static struct memory_allocation * memory_ib_alloc(struct memory_type *m, size_t len, size_t alignment) +static struct memory_allocation * memory_ib_alloc(size_t len, size_t alignment, struct memory_type *m) { struct memory_ib *mi = (struct memory_ib *) m->_vd; @@ -52,7 +52,7 @@ static struct memory_allocation * memory_ib_alloc(struct memory_type *m, size_t ma->length = len; ma->alignment = alignment; - ma->parent = mi->parent->alloc(mi->parent, len + sizeof(struct ibv_mr *), alignment); + ma->parent = mi->parent->alloc(len + sizeof(struct ibv_mr *), alignment, mi->parent); ma->address = ma->parent->address; if (!mi->pd) @@ -60,7 +60,7 @@ static struct memory_allocation * memory_ib_alloc(struct memory_type *m, size_t ma->ib.mr = ibv_reg_mr(mi->pd, ma->address, ma->length, IBV_ACCESS_LOCAL_WRITE | IBV_ACCESS_REMOTE_WRITE); if (!ma->ib.mr) { - mi->parent->free(mi->parent, ma->parent); + mi->parent->free(ma->parent, mi->parent); free(ma); return nullptr; } @@ -68,14 +68,14 @@ static struct memory_allocation * memory_ib_alloc(struct memory_type *m, size_t return ma; } -static int memory_ib_free(struct memory_type *m, struct memory_allocation *ma) +static int memory_ib_free(struct memory_allocation *ma, struct memory_type *m) { int ret; struct memory_ib *mi = (struct memory_ib *) m->_vd; ibv_dereg_mr(ma->ib.mr); - ret = mi->parent->free(mi->parent, ma->parent); + ret = mi->parent->free(ma->parent, mi->parent); if (ret) return ret; diff --git a/lib/memory/managed.cpp b/lib/memory/managed.cpp index def48ca27..42e17409d 100644 --- a/lib/memory/managed.cpp +++ b/lib/memory/managed.cpp @@ -36,7 +36,7 @@ using namespace villas::utils; -static struct memory_allocation * memory_managed_alloc(struct memory_type *m, size_t len, size_t alignment) +static struct memory_allocation * memory_managed_alloc(size_t len, size_t alignment, struct memory_type *m) { /* Simple first-fit allocation */ struct memory_block *first = (struct memory_block *) m->_vd; @@ -124,7 +124,7 @@ static struct memory_allocation * memory_managed_alloc(struct memory_type *m, si return nullptr; } -static int memory_managed_free(struct memory_type *m, struct memory_allocation *ma) +static int memory_managed_free(struct memory_allocation *ma, struct memory_type *m) { struct memory_block *block = ma->managed.block; diff --git a/lib/memory/hugepage.cpp b/lib/memory/mmap.cpp similarity index 78% rename from lib/memory/hugepage.cpp rename to lib/memory/mmap.cpp index 091e9383b..aad72f196 100644 --- a/lib/memory/hugepage.cpp +++ b/lib/memory/mmap.cpp @@ -1,4 +1,4 @@ -/** Hugepage memory allocator. +/** mmap memory allocator. * * @author Steffen Vogel * @copyright 2014-2019, Institute for Automation of Complex Power Systems, EONERC @@ -74,11 +74,9 @@ int memory_hugepage_init(int hugepages) return 0; } -/** Allocate memory backed by hugepages with malloc() like interface */ -static struct memory_allocation * memory_hugepage_alloc(struct memory_type *m, size_t len, size_t alignment) +/** Allocate memory backed by mmaps with malloc() like interface */ +static struct memory_allocation * memory_mmap_alloc(size_t len, size_t alignment, struct memory_type *m) { - static bool use_huge = true; - int flags, fd; size_t sz; @@ -86,7 +84,7 @@ static struct memory_allocation * memory_hugepage_alloc(struct memory_type *m, s if (!ma) return nullptr; -retry: if (use_huge) { + if (m->flags & (int) MemoryFlags::HUGEPAGE) { #ifdef __linux__ flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB; #else @@ -99,15 +97,19 @@ retry: if (use_huge) { fd = -1; #endif sz = hugepgsz; + + info("allocate %#zx bytes mmap_hugetlb memory", len); } else { flags = MAP_PRIVATE | MAP_ANONYMOUS; fd = -1; sz = pgsz; + + info("allocate %#zx bytes mmap memory", len); } - /** We must make sure that len is a multiple of the (huge)page size + /** We must make sure that len is a multiple of the page size * * See: https://lkml.org/lkml/2014/10/22/925 */ @@ -117,21 +119,14 @@ retry: if (use_huge) { ma->address = mmap(nullptr, ma->length, PROT_READ | PROT_WRITE, flags, fd, 0); if (ma->address == MAP_FAILED) { - if (use_huge) { - warning("Failed to map hugepages, try with normal pages instead!"); - use_huge = false; - goto retry; - } - else { - free(ma); - return nullptr; - } + free(ma); + return nullptr; } return ma; } -static int memory_hugepage_free(struct memory_type *m, struct memory_allocation *ma) +static int memory_mmap_free(struct memory_allocation *ma, struct memory_type *m) { int ret; @@ -142,10 +137,18 @@ static int memory_hugepage_free(struct memory_type *m, struct memory_allocation return 0; } -struct memory_type memory_hugepage = { - .name = "mmap_hugepages", +struct memory_type memory_mmap = { + .name = "mmap", + .flags = (int) MemoryFlags::MMAP, + .alignment = 12, /* 4k page */ + .alloc = memory_mmap_alloc, + .free = memory_mmap_free +}; + +struct memory_type memory_mmap_hugetlb = { + .name = "mmap", .flags = (int) MemoryFlags::MMAP | (int) MemoryFlags::HUGEPAGE, .alignment = 21, /* 2 MiB hugepage */ - .alloc = memory_hugepage_alloc, - .free = memory_hugepage_free + .alloc = memory_mmap_alloc, + .free = memory_mmap_free }; diff --git a/lib/node.cpp b/lib/node.cpp index 186533bc8..b551419d5 100644 --- a/lib/node.cpp +++ b/lib/node.cpp @@ -542,9 +542,9 @@ int node_netem_fds(struct node *n, int fds[]) return node_type(n)->netem_fds ? node_type(n)->netem_fds(n, fds) : -1; } -struct memory_type * node_memory_type(struct node *n, struct memory_type *parent) +struct memory_type * node_memory_type(struct node *n) { - return node_type(n)->memory_type ? node_type(n)->memory_type(n, parent) : &memory_hugepage; + return node_type(n)->memory_type ? node_type(n)->memory_type(n, memory_default) : memory_default; } int node_list_parse(struct vlist *list, json_t *cfg, struct vlist *all) diff --git a/lib/nodes/iec61850_sv.cpp b/lib/nodes/iec61850_sv.cpp index 9bada0d21..8be64c3e5 100644 --- a/lib/nodes/iec61850_sv.cpp +++ b/lib/nodes/iec61850_sv.cpp @@ -328,11 +328,11 @@ int iec61850_sv_start(struct node *n) SVReceiver_addSubscriber(i->in.receiver, i->in.subscriber); /* Initialize pool and queue to pass samples between threads */ - ret = pool_init(&i->in.pool, 1024, SAMPLE_LENGTH(vlist_length(&n->in.signals)), &memory_hugepage); + ret = pool_init(&i->in.pool, 1024, SAMPLE_LENGTH(vlist_length(&n->in.signals))); if (ret) return ret; - ret = queue_signalled_init(&i->in.queue, 1024, &memory_hugepage); + ret = queue_signalled_init(&i->in.queue, 1024); if (ret) return ret; diff --git a/lib/nodes/loopback.cpp b/lib/nodes/loopback.cpp index c90cd3a8e..1aba21327 100644 --- a/lib/nodes/loopback.cpp +++ b/lib/nodes/loopback.cpp @@ -81,11 +81,11 @@ int loopback_start(struct node *n) vlist_length(&n->out.signals) ); - ret = pool_init(&l->pool, l->queuelen, SAMPLE_LENGTH(len), &memory_hugepage); + ret = pool_init(&l->pool, l->queuelen, SAMPLE_LENGTH(len)); if (ret) return ret; - return queue_signalled_init(&l->queue, l->queuelen, &memory_hugepage, l->mode); + return queue_signalled_init(&l->queue, l->queuelen, memory_default, l->mode); } int loopback_stop(struct node *n) diff --git a/lib/nodes/mqtt.cpp b/lib/nodes/mqtt.cpp index 1e69d7ab4..50cb90e64 100644 --- a/lib/nodes/mqtt.cpp +++ b/lib/nodes/mqtt.cpp @@ -361,11 +361,11 @@ int mqtt_start(struct node *n) if (ret) return ret; - ret = pool_init(&m->pool, 1024, SAMPLE_LENGTH(vlist_length(&n->in.signals)), &memory_hugepage); + ret = pool_init(&m->pool, 1024, SAMPLE_LENGTH(vlist_length(&n->in.signals))); if (ret) return ret; - ret = queue_signalled_init(&m->queue, 1024, &memory_hugepage); + ret = queue_signalled_init(&m->queue, 1024); if (ret) return ret; diff --git a/lib/nodes/websocket.cpp b/lib/nodes/websocket.cpp index 6228144db..a9ec5f6b7 100644 --- a/lib/nodes/websocket.cpp +++ b/lib/nodes/websocket.cpp @@ -86,7 +86,7 @@ static int websocket_connection_init(struct websocket_connection *c) c->_name = nullptr; - ret = queue_init(&c->queue, DEFAULT_QUEUE_LENGTH, &memory_hugepage); + ret = queue_init(&c->queue, DEFAULT_QUEUE_LENGTH); if (ret) return ret; @@ -391,11 +391,11 @@ int websocket_start(struct node *n) int ret; struct websocket *w = (struct websocket *) n->_vd; - ret = pool_init(&w->pool, DEFAULT_WEBSOCKET_QUEUE_LENGTH, SAMPLE_LENGTH(DEFAULT_WEBSOCKET_SAMPLE_LENGTH), &memory_hugepage); + ret = pool_init(&w->pool, DEFAULT_WEBSOCKET_QUEUE_LENGTH, SAMPLE_LENGTH(DEFAULT_WEBSOCKET_SAMPLE_LENGTH)); if (ret) return ret; - ret = queue_signalled_init(&w->queue, DEFAULT_WEBSOCKET_QUEUE_LENGTH, &memory_hugepage); + ret = queue_signalled_init(&w->queue, DEFAULT_WEBSOCKET_QUEUE_LENGTH); if (ret) return ret; diff --git a/lib/path.cpp b/lib/path.cpp index dd3960b5a..2eb915ebf 100644 --- a/lib/path.cpp +++ b/lib/path.cpp @@ -226,7 +226,7 @@ int path_prepare(struct path *p) assert(p->state == State::CHECKED); /* Initialize destinations */ - struct memory_type *pool_mt = &memory_hugepage; + struct memory_type *pool_mt = memory_default; unsigned pool_size = MAX(1UL, vlist_length(&p->destinations)) * p->queuelen; for (size_t i = 0; i < vlist_length(&p->destinations); i++) { @@ -236,7 +236,7 @@ int path_prepare(struct path *p) pool_size = node_type(pd->node)->pool_size; if (node_type(pd->node)->memory_type) - pool_mt = node_memory_type(pd->node, &memory_hugepage); + pool_mt = node_memory_type(pd->node); ret = path_destination_init(pd, p->queuelen); if (ret) diff --git a/lib/path_destination.cpp b/lib/path_destination.cpp index 3dd9e18f4..3324c50d9 100644 --- a/lib/path_destination.cpp +++ b/lib/path_destination.cpp @@ -31,7 +31,7 @@ int path_destination_init(struct path_destination *pd, int queuelen) { int ret; - ret = queue_init(&pd->queue, queuelen, &memory_hugepage); + ret = queue_init(&pd->queue, queuelen); if (ret) return ret; diff --git a/lib/path_source.cpp b/lib/path_source.cpp index bb63b953d..becee51ae 100644 --- a/lib/path_source.cpp +++ b/lib/path_source.cpp @@ -37,7 +37,7 @@ int path_source_init(struct path_source *ps) if (ps->node->_vt->pool_size) pool_size = ps->node->_vt->pool_size; - ret = pool_init(&ps->pool, pool_size, SAMPLE_LENGTH(vlist_length(&ps->node->in.signals)), node_memory_type(ps->node, &memory_hugepage)); + ret = pool_init(&ps->pool, pool_size, SAMPLE_LENGTH(vlist_length(&ps->node->in.signals)), node_memory_type(ps->node)); if (ret) return ret; diff --git a/lib/pool.cpp b/lib/pool.cpp index cb10128a0..eb854530a 100644 --- a/lib/pool.cpp +++ b/lib/pool.cpp @@ -36,7 +36,7 @@ int pool_init(struct pool *p, size_t cnt, size_t blocksz, struct memory_type *m) p->blocksz = p->alignment * CEIL(blocksz, p->alignment); p->len = cnt * p->blocksz; - void *buffer = memory_alloc_aligned(m, p->len, p->alignment); + void *buffer = memory_alloc_aligned(p->len, p->alignment, m); if (!buffer) serror("Failed to allocate memory for memory pool"); else diff --git a/lib/queue.cpp b/lib/queue.cpp index 2647acc3f..4d9539f77 100644 --- a/lib/queue.cpp +++ b/lib/queue.cpp @@ -48,7 +48,7 @@ int queue_init(struct queue *q, size_t size, struct memory_type *m) } q->buffer_mask = size - 1; - struct queue_cell *buffer = (struct queue_cell *) memory_alloc(m, sizeof(struct queue_cell) * size); + struct queue_cell *buffer = (struct queue_cell *) memory_alloc(sizeof(struct queue_cell) * size, m); if (!buffer) return -2; diff --git a/lib/shmem.cpp b/lib/shmem.cpp index cba1e4d90..4f45c7ad2 100644 --- a/lib/shmem.cpp +++ b/lib/shmem.cpp @@ -94,7 +94,7 @@ retry: fd = shm_open(wname, O_RDWR|O_CREAT|O_EXCL, 0600); close(fd); manager = memory_managed(base, len); - shared = (struct shmem_shared *) memory_alloc(manager, sizeof(struct shmem_shared)); + shared = (struct shmem_shared *) memory_alloc(sizeof(struct shmem_shared), manager); if (!shared) { errno = ENOMEM; return -5; diff --git a/src/villas-hook.cpp b/src/villas-hook.cpp index 95f29c207..6b2f2b4b8 100644 --- a/src/villas-hook.cpp +++ b/src/villas-hook.cpp @@ -201,7 +201,7 @@ check: if (optarg == endptr) smps = new struct sample*[cnt]; - ret = pool_init(&p, 10 * cnt, SAMPLE_LENGTH(DEFAULT_SAMPLE_LENGTH), &memory_hugepage); + ret = pool_init(&p, 10 * cnt, SAMPLE_LENGTH(DEFAULT_SAMPLE_LENGTH)); if (ret) throw RuntimeError("Failed to initilize memory pool"); diff --git a/src/villas-node.cpp b/src/villas-node.cpp index 165f0fc28..342c2d96a 100644 --- a/src/villas-node.cpp +++ b/src/villas-node.cpp @@ -64,13 +64,7 @@ class Node : public Tool { public: Node(int argc, char *argv[]) : Tool(argc, argv, "node") - { - int ret; - - ret = memory_init(DEFAULT_NR_HUGEPAGES); - if (ret) - throw RuntimeError("Failed to initialize memory"); - } + { } protected: SuperNode sn; diff --git a/src/villas-pipe.cpp b/src/villas-pipe.cpp index f2d1c0dea..5b84363d0 100644 --- a/src/villas-pipe.cpp +++ b/src/villas-pipe.cpp @@ -81,7 +81,7 @@ public: unsigned vec = LOG2_CEIL(MAX(node->out.vectorize, node->in.vectorize)); unsigned pool_size = node_type(node)->pool_size ? node_type(node)->pool_size : vec; - int ret = pool_init(&pool, pool_size, SAMPLE_LENGTH(DEFAULT_SAMPLE_LENGTH), node_memory_type(node, &memory_hugepage)); + int ret = pool_init(&pool, pool_size, SAMPLE_LENGTH(DEFAULT_SAMPLE_LENGTH), node_memory_type(node)); if (ret < 0) throw RuntimeError("Failed to allocate memory for pool."); } diff --git a/tests/unit/io.cpp b/tests/unit/io.cpp index 4cf4ab85a..43d9f059f 100644 --- a/tests/unit/io.cpp +++ b/tests/unit/io.cpp @@ -227,7 +227,7 @@ ParameterizedTest(struct param *p, io, lowlevel, .init = init_memory) struct sample *smps[p->cnt]; struct sample *smpt[p->cnt]; - ret = pool_init(&pool, 2 * p->cnt, SAMPLE_LENGTH(NUM_VALUES), &memory_hugepage); + ret = pool_init(&pool, 2 * p->cnt, SAMPLE_LENGTH(NUM_VALUES)); cr_assert_eq(ret, 0); vlist_init(&signals); @@ -297,7 +297,7 @@ ParameterizedTest(struct param *p, io, highlevel, .init = init_memory) struct sample *smps[p->cnt]; struct sample *smpt[p->cnt]; - ret = pool_init(&pool, 2 * p->cnt, SAMPLE_LENGTH(NUM_VALUES), &memory_hugepage); + ret = pool_init(&pool, 2 * p->cnt, SAMPLE_LENGTH(NUM_VALUES)); cr_assert_eq(ret, 0); ret = sample_alloc_many(&pool, smps, p->cnt); diff --git a/tests/unit/memory.cpp b/tests/unit/memory.cpp index ca03dc409..65d5eaef8 100644 --- a/tests/unit/memory.cpp +++ b/tests/unit/memory.cpp @@ -37,22 +37,20 @@ extern void init_memory(); TheoryDataPoints(memory, aligned) = { DataPoints(size_t, 1, 32, 55, 1 << 10, PAGESIZE, HUGEPAGESIZE), DataPoints(size_t, 1, 8, PAGESIZE, PAGESIZE), - DataPoints(enum MemoryFlags, MemoryFlags::HEAP, MemoryFlags::HUGEPAGE, MemoryFlags::HUGEPAGE) + DataPoints(struct memory_type *, &memory_heap, &memory_mmap_hugetlb, &memory_mmap_hugetlb) }; -Theory((size_t len, size_t align, enum MemoryFlags memory_type), memory, aligned, .init = init_memory) { +Theory((size_t len, size_t align, struct memory_type *mt), memory, aligned, .init = init_memory) { int ret; void *ptr; - struct memory_type *mt = memory_type_lookup(memory_type); - - ptr = memory_alloc_aligned(mt, len, align); + ptr = memory_alloc_aligned(len, align, mt); cr_assert_not_null(ptr, "Failed to allocate memory"); cr_assert(IS_ALIGNED(ptr, align), "Memory at %p is not alligned to %#zx byte bounary", ptr, align); #ifndef __APPLE__ - if (mt == &memory_hugepage) { + if (mt == &memory_mmap_hugetlb) { cr_assert(IS_ALIGNED(ptr, HUGEPAGESIZE), "Memory at %p is not alligned to %#x byte bounary", ptr, HUGEPAGESIZE); } #endif @@ -72,26 +70,26 @@ Test(memory, manager, .init = init_memory) { total_size = 1 << 10; max_block = total_size - sizeof(struct memory_type) - sizeof(struct memory_block); - p = memory_alloc(&memory_heap, total_size); + p = memory_alloc(total_size, &memory_heap); cr_assert_not_null(p); m = memory_managed(p, total_size); cr_assert_not_null(m); - p1 = memory_alloc(m, 16); + p1 = memory_alloc(16, m); cr_assert_not_null(p1); - p2 = memory_alloc(m, 32); + p2 = memory_alloc(32, m); cr_assert_not_null(p2); ret = memory_free(p1); cr_assert(ret == 0); - p1 = memory_alloc_aligned(m, 128, 128); + p1 = memory_alloc_aligned(128, 128, m); cr_assert_not_null(p1); cr_assert(IS_ALIGNED(p1, 128)); - p3 = memory_alloc_aligned(m, 128, 256); + p3 = memory_alloc_aligned(128, 256, m); cr_assert(p3); cr_assert(IS_ALIGNED(p3, 256)); @@ -104,7 +102,7 @@ Test(memory, manager, .init = init_memory) { ret = memory_free(p3); cr_assert(ret == 0); - p1 = memory_alloc(m, max_block); + p1 = memory_alloc(max_block, m); cr_assert_not_null(p1); ret = memory_free(p1); diff --git a/tests/unit/pool.cpp b/tests/unit/pool.cpp index 1edf50933..1b3d5b538 100644 --- a/tests/unit/pool.cpp +++ b/tests/unit/pool.cpp @@ -34,16 +34,16 @@ struct param { int thread_count; int pool_size; size_t block_size; - enum MemoryFlags memory_type; + struct memory_type *mt; }; ParameterizedTestParameters(pool, basic) { static struct param params[] = { - { 1, 4096, 150, MemoryFlags::HEAP }, - { 1, 128, 8, MemoryFlags::HUGEPAGE }, - { 1, 4, 8192, MemoryFlags::HUGEPAGE }, - { 1, 1 << 13, 4, MemoryFlags::HUGEPAGE } + { 1, 4096, 150, &memory_heap }, + { 1, 128, 8, &memory_mmap_hugetlb }, + { 1, 4, 8192, &memory_mmap_hugetlb }, + { 1, 1 << 13, 4, &memory_mmap_hugetlb } }; return cr_make_param_array(struct param, params, ARRAY_LEN(params)); @@ -56,9 +56,7 @@ ParameterizedTest(struct param *p, pool, basic, .init = init_memory) void *ptr, *ptrs[p->pool_size]; - struct memory_type *mt = memory_type_lookup(p->memory_type); - - ret = pool_init(&pool, p->pool_size, p->block_size, mt); + ret = pool_init(&pool, p->pool_size, p->block_size, p->mt); cr_assert_eq(ret, 0, "Failed to create pool"); ptr = pool_get(&pool); diff --git a/tests/unit/queue.cpp b/tests/unit/queue.cpp index 714e8b357..652d42431 100644 --- a/tests/unit/queue.cpp +++ b/tests/unit/queue.cpp @@ -54,7 +54,7 @@ struct param { int thread_count; bool many; int batch_size; - enum MemoryFlags memory_type; + struct memory_type *mt; volatile int start; struct queue queue; }; @@ -274,35 +274,35 @@ ParameterizedTestParameters(queue, multi_threaded) .thread_count = 32, .many = true, .batch_size = 10, - .memory_type = MemoryFlags::HEAP + .mt = &memory_heap }, { .iter_count = 1 << 8, .queue_size = 1 << 9, .thread_count = 4, .many = true, .batch_size = 100, - .memory_type = MemoryFlags::HEAP + .mt = &memory_heap }, { .iter_count = 1 << 16, .queue_size = 1 << 14, .thread_count = 16, .many = true, .batch_size = 100, - .memory_type = MemoryFlags::HEAP + .mt = &memory_heap }, { .iter_count = 1 << 8, .queue_size = 1 << 9, .thread_count = 4, .many = true, .batch_size = 10, - .memory_type = MemoryFlags::HEAP + .mt = &memory_heap }, { .iter_count = 1 << 16, .queue_size = 1 << 9, .thread_count = 16, .many = false, .batch_size = 10, - .memory_type = MemoryFlags::HUGEPAGE + .mt = &memory_mmap_hugetlb } }; @@ -321,9 +321,7 @@ ParameterizedTest(struct param *p, queue, multi_threaded, .timeout = 20, .init = p->start = 0; p->queue.state = ATOMIC_VAR_INIT(State::DESTROYED); - struct memory_type *mt = memory_type_lookup(p->memory_type); - - ret = queue_init(&p->queue, p->queue_size, mt); + ret = queue_init(&p->queue, p->queue_size, p->mt); cr_assert_eq(ret, 0, "Failed to create queue"); uint64_t start_tsc_time, end_tsc_time;