aboutsummaryrefslogtreecommitdiffstats
path: root/src/svm
diff options
context:
space:
mode:
Diffstat (limited to 'src/svm')
-rw-r--r--src/svm/ssvm.c59
-rw-r--r--src/svm/svm.c18
-rw-r--r--src/svm/svm_fifo_segment.c29
3 files changed, 87 insertions, 19 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);
}
diff --git a/src/svm/svm.c b/src/svm/svm.c
index d958c8378e5..aa84a2fe3b4 100644
--- a/src/svm/svm.c
+++ b/src/svm/svm.c
@@ -236,6 +236,7 @@ format_svm_region (u8 * s, va_list * args)
}
}
}
+#if USE_DLMALLOC == 0
s = format (s, " rgn heap stats: %U", format_mheap,
rp->region_heap, 0);
if ((rp->flags & SVM_FLAGS_MHEAP) && rp->data_heap)
@@ -244,6 +245,7 @@ format_svm_region (u8 * s, va_list * args)
rp->data_heap, 1);
}
s = format (s, "\n");
+#endif
}
return (s);
@@ -339,12 +341,18 @@ svm_data_region_create (svm_map_region_args_t * a, svm_region_t * rp)
if (a->flags & SVM_FLAGS_MHEAP)
{
+#if USE_DLMALLOC == 0
mheap_t *heap_header;
rp->data_heap =
mheap_alloc_with_flags ((void *) (rp->data_base), map_size,
MHEAP_FLAG_DISABLE_VM);
heap_header = mheap_header (rp->data_heap);
heap_header->flags |= MHEAP_FLAG_THREAD_SAFE;
+#else
+ rp->data_heap = create_mspace_with_base (rp->data_base,
+ map_size, 1 /* locked */ );
+ mspace_disable_expand (rp->data_heap);
+#endif
rp->flags |= SVM_FLAGS_MHEAP;
}
@@ -518,12 +526,22 @@ svm_region_init_mapped_region (svm_map_region_args_t * a, svm_region_t * rp)
rp->virtual_base = a->baseva;
rp->virtual_size = a->size;
+#if USE_DLMALLOC == 0
rp->region_heap =
mheap_alloc_with_flags (uword_to_pointer
(a->baseva + MMAP_PAGESIZE, void *),
(a->pvt_heap_size !=
0) ? a->pvt_heap_size : SVM_PVT_MHEAP_SIZE,
MHEAP_FLAG_DISABLE_VM);
+#else
+ rp->region_heap = create_mspace_with_base
+ (uword_to_pointer (a->baseva + MMAP_PAGESIZE, void *),
+ (a->pvt_heap_size !=
+ 0) ? a->pvt_heap_size : SVM_PVT_MHEAP_SIZE, 1 /* locked */ );
+
+ mspace_disable_expand (rp->region_heap);
+#endif
+
oldheap = svm_push_pvt_heap (rp);
rp->region_name = (char *) format (0, "%s%c", a->name, 0);
diff --git a/src/svm/svm_fifo_segment.c b/src/svm/svm_fifo_segment.c
index 7c6d80229ad..ce1d5a0eab1 100644
--- a/src/svm/svm_fifo_segment.c
+++ b/src/svm/svm_fifo_segment.c
@@ -107,7 +107,12 @@ svm_fifo_segment_preallocate_fifo_pairs (svm_fifo_segment_private_t * s,
/* Calculate space requirements */
pair_size = 2 * sizeof (*f) + rx_rounded_data_size + tx_rounded_data_size;
+#if USE_DLMALLOC == 0
space_available = s->ssvm.ssvm_size - mheap_bytes (sh->heap);
+#else
+ space_available = s->ssvm.ssvm_size - mspace_usable_size (sh->heap);
+#endif
+
pairs_to_allocate = clib_min (space_available / pair_size, *n_fifo_pairs);
rx_fifos_size = (sizeof (*f) + rx_rounded_data_size) * pairs_to_allocate;
tx_fifos_size = (sizeof (*f) + tx_rounded_data_size) * pairs_to_allocate;
@@ -237,7 +242,6 @@ svm_fifo_segment_create_process_private (svm_fifo_segment_create_args_t * a)
svm_fifo_segment_main_t *sm = &svm_fifo_segment_main;
svm_fifo_segment_private_t *s;
ssvm_shared_header_t *sh;
- mheap_t *heap_header;
u32 rnd_size = 0;
u8 *heap;
u32 pagesize = clib_mem_get_page_size ();
@@ -247,6 +251,7 @@ svm_fifo_segment_create_process_private (svm_fifo_segment_create_args_t * a)
rnd_size = (a->segment_size + (pagesize - 1)) & ~pagesize;
+#if USE_DLMALLOC == 0
heap = mheap_alloc (0, rnd_size);
if (heap == 0)
{
@@ -254,8 +259,14 @@ svm_fifo_segment_create_process_private (svm_fifo_segment_create_args_t * a)
pool_put (sm->segments, s);
return -1;
}
- heap_header = mheap_header (heap);
- heap_header->flags |= MHEAP_FLAG_THREAD_SAFE;
+ {
+ mheap_t *heap_header;
+ heap_header = mheap_header (heap);
+ heap_header->flags |= MHEAP_FLAG_THREAD_SAFE;
+ }
+#else
+ heap = create_mspace (rnd_size, 1 /* locked */ );
+#endif
s->ssvm.ssvm_size = rnd_size;
s->ssvm.i_am_master = 1;
@@ -572,11 +583,17 @@ svm_fifo_segment_info (svm_fifo_segment_private_t * seg, uword * address,
{
if (ssvm_type (&seg->ssvm) == SSVM_SEGMENT_PRIVATE)
{
+#if USE_DLMALLOC == 0
mheap_t *heap_header;
*address = pointer_to_uword (seg->ssvm.sh->heap);
heap_header = mheap_header (seg->ssvm.sh->heap);
*size = heap_header->max_size;
+#else
+ mspace_get_address_and_size (seg->ssvm.sh->heap,
+ (unsigned long long *) address,
+ (unsigned long long *) size);
+#endif
}
else
{
@@ -585,7 +602,7 @@ svm_fifo_segment_info (svm_fifo_segment_private_t * seg, uword * address,
}
}
-mheap_t *
+void *
svm_fifo_segment_heap (svm_fifo_segment_private_t * seg)
{
return seg->ssvm.sh->heap;
@@ -617,17 +634,19 @@ format_svm_fifo_segment (u8 * s, va_list * args)
{
svm_fifo_segment_private_t *sp
= va_arg (*args, svm_fifo_segment_private_t *);
- int verbose = va_arg (*args, int);
+ int verbose __attribute__ ((unused)) = va_arg (*args, int);
svm_fifo_segment_header_t *fsh = sp->h;
u32 count, indent;
svm_fifo_t *f;
int i;
indent = format_get_indent (s) + 2;
+#if USE_DLMALLOC == 0
s = format (s, "%U segment heap: %U\n", format_white_space, indent,
format_mheap, svm_fifo_segment_heap (sp), verbose);
s = format (s, "%U segment has %u active fifos\n",
format_white_space, indent, svm_fifo_segment_num_fifos (sp));
+#endif
for (i = 0; i < vec_len (fsh->free_fifos); i++)
{