summaryrefslogtreecommitdiffstats
path: root/src/svm
diff options
context:
space:
mode:
authorFlorin Coras <fcoras@cisco.com>2020-02-07 23:28:41 +0000
committerDave Barach <openvpp@barachs.net>2020-02-11 15:53:13 +0000
commit6fe8998fefdc900af714a23d4152ffef9edbd3b4 (patch)
treee47f62a10b8d2d5f5c1316b091f6809b46f3f893 /src/svm
parentfa2a316663e622a2feeecf8ad7d32b242370a70a (diff)
svm: numa awareness for ssvm segments
Type: feature Signed-off-by: Florin Coras <fcoras@cisco.com> Change-Id: I999836a7893a89aac5243b111eac35fddd03e2a6
Diffstat (limited to 'src/svm')
-rw-r--r--src/svm/ssvm.c52
-rw-r--r--src/svm/ssvm.h3
2 files changed, 30 insertions, 25 deletions
diff --git a/src/svm/ssvm.c b/src/svm/ssvm.c
index 69463b1f192..66e38ebf864 100644
--- a/src/svm/ssvm.c
+++ b/src/svm/ssvm.c
@@ -90,6 +90,7 @@ ssvm_master_init_shm (ssvm_private_t * ssvm)
mapa.requested_va = requested_va;
mapa.size = ssvm->ssvm_size;
mapa.fd = ssvm_fd;
+ mapa.numa_node = ssvm->numa;
if (clib_mem_vm_ext_map (&mapa))
{
clib_unix_warning ("mmap");
@@ -237,6 +238,11 @@ ssvm_master_init_memfd (ssvm_private_t * memfd)
alloc.size = memfd->ssvm_size;
alloc.flags = CLIB_MEM_VM_F_SHARED;
alloc.requested_va = memfd->requested_va;
+ if (memfd->numa)
+ {
+ alloc.numa_node = memfd->numa;
+ alloc.flags |= CLIB_MEM_VM_F_NUMA_PREFER;
+ }
if ((err = clib_mem_vm_ext_alloc (&alloc)))
{
clib_error_report (err);
@@ -348,27 +354,31 @@ int
ssvm_master_init_private (ssvm_private_t * ssvm)
{
uword pagesize = clib_mem_get_page_size (), rnd_size = 0;
+ clib_mem_vm_alloc_t alloc = { 0 };
+ struct dlmallinfo dlminfo;
ssvm_shared_header_t *sh;
+ clib_error_t *err;
u8 *heap;
rnd_size = clib_max (ssvm->ssvm_size + (pagesize - 1), ssvm->ssvm_size);
rnd_size &= ~(pagesize - 1);
-#if USE_DLMALLOC == 0
- {
- mheap_t *heap_header;
-
- heap = mheap_alloc (0, rnd_size);
- if (heap == 0)
- {
- clib_unix_warning ("mheap alloc");
- return -1;
- }
- heap_header = mheap_header (heap);
- heap_header->flags |= MHEAP_FLAG_THREAD_SAFE;
- }
-#else
- heap = create_mspace (rnd_size, 1 /* locked */ );
+ alloc.name = (char *) ssvm->name;
+ alloc.size = rnd_size + pagesize;
+ if (ssvm->numa)
+ {
+ alloc.numa_node = ssvm->numa;
+ alloc.flags |= CLIB_MEM_VM_F_NUMA_PREFER;
+ }
+
+ if ((err = clib_mem_vm_ext_alloc (&alloc)))
+ {
+ clib_error_report (err);
+ return SSVM_API_ERROR_CREATE_FAILURE;
+ }
+
+ heap = create_mspace_with_base ((u8 *) alloc.addr + pagesize, rnd_size,
+ 1 /* locked */ );
if (heap == 0)
{
clib_unix_warning ("mheap alloc");
@@ -378,18 +388,16 @@ ssvm_master_init_private (ssvm_private_t * ssvm)
mspace_disable_expand (heap);
/* Find actual size because mspace size is rounded up by dlmalloc */
- struct dlmallinfo dlminfo;
dlminfo = mspace_mallinfo (heap);
rnd_size = dlminfo.fordblks;
-#endif
ssvm->ssvm_size = rnd_size;
ssvm->i_am_master = 1;
ssvm->my_pid = getpid ();
ssvm->requested_va = ~0;
- /* Allocate a [sic] shared memory header, in process memory... */
- sh = clib_mem_alloc_aligned (sizeof (*sh), CLIB_CACHE_LINE_BYTES);
+ /* First page in allocated memory is set aside for the shared header */
+ sh = alloc.addr;
ssvm->sh = sh;
clib_memset (sh, 0, sizeof (*sh));
@@ -413,12 +421,8 @@ void
ssvm_delete_private (ssvm_private_t * ssvm)
{
vec_free (ssvm->name);
-#if USE_DLMALLOC == 0
- mheap_free (ssvm->sh->heap);
-#else
destroy_mspace (ssvm->sh->heap);
-#endif
- clib_mem_free (ssvm->sh);
+ clib_mem_vm_free (ssvm->sh, ssvm->ssvm_size + clib_mem_get_page_size ());
}
int
diff --git a/src/svm/ssvm.h b/src/svm/ssvm.h
index 82951d614b0..6225a63cae4 100644
--- a/src/svm/ssvm.h
+++ b/src/svm/ssvm.h
@@ -83,9 +83,10 @@ typedef struct
{
ssvm_shared_header_t *sh;
uword ssvm_size;
+ uword requested_va;
u32 my_pid;
u8 *name;
- uword requested_va;
+ u8 numa; /**< Numa requested at alloc time */
int i_am_master;
union