summaryrefslogtreecommitdiffstats
path: root/src/svm/ssvm.c
diff options
context:
space:
mode:
authorDave Barach <dave@barachs.net>2018-07-04 10:56:23 -0400
committerDamjan Marion <dmarion@me.com>2018-07-18 12:09:42 +0000
commit6a5adc369591fcac2447e9809deaa22f56b53911 (patch)
treec9a56b1ed0d5e8eb2f21a843552c6c0bc6df5597 /src/svm/ssvm.c
parent2a3fb1a28b170ac1d37815983611e83d148811d4 (diff)
Add config option to use dlmalloc instead of mheap
Configure w/ --enable-dlmalloc, see .../build-data/platforms/vpp.mk src/vppinfra/dlmalloc.[ch] are slightly modified versions of the well-known Doug Lea malloc. Main advantage: dlmalloc mspaces have no inherent size limit. Change-Id: I19b3f43f3c65bcfb82c1a265a97922d01912446e Signed-off-by: Dave Barach <dave@barachs.net>
Diffstat (limited to 'src/svm/ssvm.c')
-rw-r--r--src/svm/ssvm.c59
1 files changed, 45 insertions, 14 deletions
diff --git a/src/svm/ssvm.c b/src/svm/ssvm.c
index c005b61144b..03451e66d15 100644
--- a/src/svm/ssvm.c
+++ b/src/svm/ssvm.c
@@ -28,7 +28,10 @@ static delete_fn delete_fns[SSVM_N_SEGMENT_TYPES] =
int
ssvm_master_init_shm (ssvm_private_t * ssvm)
{
- int ssvm_fd, mh_flags = MHEAP_FLAG_DISABLE_VM | MHEAP_FLAG_THREAD_SAFE;
+ int ssvm_fd;
+#if USE_DLMALLOC == 0
+ int mh_flags = MHEAP_FLAG_DISABLE_VM | MHEAP_FLAG_THREAD_SAFE;
+#endif
clib_mem_vm_map_t mapa = { 0 };
u8 junk = 0, *ssvm_filename;
ssvm_shared_header_t *sh;
@@ -100,8 +103,15 @@ ssvm_master_init_shm (ssvm_private_t * ssvm)
sh->ssvm_size = ssvm->ssvm_size;
sh->ssvm_va = pointer_to_uword (sh);
sh->type = SSVM_SEGMENT_SHM;
+#if USE_DLMALLOC == 0
sh->heap = mheap_alloc_with_flags (((u8 *) sh) + page_size,
ssvm->ssvm_size - page_size, mh_flags);
+#else
+ sh->heap = create_mspace_with_base (((u8 *) sh) + page_size,
+ ssvm->ssvm_size - page_size,
+ 1 /* locked */ );
+ mspace_disable_expand (sh->heap);
+#endif
oldheap = ssvm_push_heap (sh);
sh->name = format (0, "%s", ssvm->name, 0);
@@ -212,7 +222,7 @@ ssvm_delete_shm (ssvm_private_t * ssvm)
int
ssvm_master_init_memfd (ssvm_private_t * memfd)
{
- uword page_size, flags = MHEAP_FLAG_DISABLE_VM | MHEAP_FLAG_THREAD_SAFE;
+ uword page_size;
ssvm_shared_header_t *sh;
void *oldheap;
clib_mem_vm_alloc_t alloc = { 0 };
@@ -244,9 +254,18 @@ ssvm_master_init_memfd (ssvm_private_t * memfd)
sh->ssvm_size = memfd->ssvm_size;
sh->ssvm_va = pointer_to_uword (sh);
sh->type = SSVM_SEGMENT_MEMFD;
+
+#if USE_DLMALLOC == 0
+ uword flags = MHEAP_FLAG_DISABLE_VM | MHEAP_FLAG_THREAD_SAFE;
+
sh->heap = mheap_alloc_with_flags (((u8 *) sh) + page_size,
memfd->ssvm_size - page_size, flags);
-
+#else
+ sh->heap = create_mspace_with_base (((u8 *) sh) + page_size,
+ memfd->ssvm_size - page_size,
+ 1 /* locked */ );
+ mspace_disable_expand (sh->heap);
+#endif
oldheap = ssvm_push_heap (sh);
sh->name = format (0, "%s", memfd->name, 0);
ssvm_pop_heap (oldheap);
@@ -328,22 +347,30 @@ ssvm_delete_memfd (ssvm_private_t * memfd)
int
ssvm_master_init_private (ssvm_private_t * ssvm)
{
- u32 pagesize = clib_mem_get_page_size ();
ssvm_shared_header_t *sh;
- mheap_t *heap_header;
- u64 rnd_size = 0;
+ u32 pagesize = clib_mem_get_page_size ();
+ u32 rnd_size = 0;
u8 *heap;
rnd_size = (ssvm->ssvm_size + (pagesize - 1)) & ~(pagesize - 1);
rnd_size = clib_min (rnd_size, ((u64) 1 << 32) - pagesize);
- 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;
+
+#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 */ );
+#endif
ssvm->ssvm_size = rnd_size;
ssvm->i_am_master = 1;
@@ -372,7 +399,11 @@ 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);
}