aboutsummaryrefslogtreecommitdiffstats
path: root/src/vlib/linux
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/vlib/linux
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/vlib/linux')
-rwxr-xr-xsrc/vlib/linux/physmem.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/vlib/linux/physmem.c b/src/vlib/linux/physmem.c
index a708aaec778..6c6b072f70a 100755
--- a/src/vlib/linux/physmem.c
+++ b/src/vlib/linux/physmem.c
@@ -69,10 +69,18 @@ unix_physmem_alloc_aligned (vlib_main_t * vm, vlib_physmem_region_index_t idx,
while (1)
{
+#if USE_DLMALLOC == 0
+
mheap_get_aligned (pr->heap, n_bytes,
/* align */ alignment,
/* align offset */ 0,
&lo_offset);
+#else
+ lo_offset = (uword) mspace_get_aligned (pr->heap, n_bytes,
+ alignment, ~0ULL /* offset */ );
+ if (lo_offset == 0)
+ lo_offset = ~0ULL;
+#endif
/* Allocation failed? */
if (lo_offset == ~0)
@@ -94,7 +102,13 @@ unix_physmem_alloc_aligned (vlib_main_t * vm, vlib_physmem_region_index_t idx,
{
uword i;
for (i = 0; i < vec_len (to_free); i++)
- mheap_put (pr->heap, to_free[i]);
+ {
+#if USE_DLMALLOC == 0
+ mheap_put (pr->heap, to_free[i]);
+#else
+ mspace_put_no_offset (pr->heap, (void *) to_free[i]);
+#endif
+ }
vec_free (to_free);
}
@@ -106,7 +120,11 @@ unix_physmem_free (vlib_main_t * vm, vlib_physmem_region_index_t idx, void *x)
{
vlib_physmem_region_t *pr = vlib_physmem_get_region (vm, idx);
/* Return object to region's heap. */
+#if USE_DLMALLOC == 0
mheap_put (pr->heap, x - pr->heap);
+#else
+ mspace_put_no_offset (pr->heap, x);
+#endif
}
static clib_error_t *
@@ -181,10 +199,15 @@ unix_physmem_region_alloc (vlib_main_t * vm, char *name, u32 size,
if (flags & VLIB_PHYSMEM_F_INIT_MHEAP)
{
+#if USE_DLMALLOC == 0
pr->heap = mheap_alloc_with_flags (pr->mem, pr->size,
/* Don't want mheap mmap/munmap with IO memory. */
MHEAP_FLAG_DISABLE_VM |
MHEAP_FLAG_THREAD_SAFE);
+#else
+ pr->heap = create_mspace_with_base (pr->mem, pr->size, 1 /* locked */ );
+ mspace_disable_expand (pr->heap);
+#endif
}
*idx = pr->index;