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>
This commit is contained in:
Dave Barach
2018-07-04 10:56:23 -04:00
committed by Damjan Marion
parent 2a3fb1a28b
commit 6a5adc3695
47 changed files with 7454 additions and 106 deletions
+3 -1
View File
@@ -37,7 +37,9 @@ vpp_root_packages = vpp vom
# vpp_dpdk_shared_lib = yes
# Use '--without-libnuma' for non-numa aware architecture
vpp_configure_args_vpp =
# Use '--enable-dlmalloc' to use dlmalloc instead of mheap
vpp_configure_args_vpp = --enable-dlmalloc
sample-plugin_configure_args_vpp = --enable-dlmalloc
# load balancer plugin is not portable on 32 bit platform
ifeq ($(MACHINE),i686)
+1 -1
View File
@@ -19,7 +19,7 @@ AUTOMAKE_OPTIONS = foreign subdir-objects
ACLOCAL_AMFLAGS = -I m4
AM_LIBTOOLFLAGS = --quiet
AM_CFLAGS = @CPU_FLAGS@ -Wall
AM_CFLAGS = @CPU_FLAGS@ @DLMALLOC@ -Wall
AM_CXXFLAGS = -Wall -std=gnu++11
SUBDIRS = .
+5
View File
@@ -190,6 +190,7 @@ ENABLE_ARG(tests, [Enable unit tests])
ENABLE_ARG(dpdk_shared, [Enable unit tests])
ENABLE_ARG(perftool, [Enable perftool])
ENABLE_ARG(g2, [Enable g2])
ENABLE_ARG(dlmalloc, [Enable dlmalloc])
# --disable-X
DISABLE_ARG(vlib, [Disable vlib and dependant libs and binaries])
@@ -232,6 +233,8 @@ AC_ARG_WITH(pre-data,
*) with_pre_data="pre-data-not-set" ;;
esac], [with_pre_data=128])
AM_CONDITIONAL(ENABLE_DLMALLOC, test "$enable_dlmalloc" = "yes")
###############################################################################
# Target CPU flags
###############################################################################
@@ -278,6 +281,7 @@ AS_IF([test "$cc_flag_check" = yes],
AC_SUBST(PRE_DATA_SIZE, [$with_pre_data])
AC_SUBST(LOG2_CACHE_LINE_BYTES, [$with_log2_cache_line_bytes])
AC_SUBST(APICLI, [-DVPP_API_TEST_BUILTIN=${n_with_apicli}])
AC_SUBST(DLMALLOC, [-DUSE_DLMALLOC=${n_enable_dlmalloc}])
AC_DEFINE_UNQUOTED(DPDK_SHARED_LIB, [${n_enable_dpdk_shared}])
AC_DEFINE_UNQUOTED(WITH_LIBSSL, [${n_with_libssl}])
@@ -447,6 +451,7 @@ PRINT_VAL([CFLAGS], ${CFLAGS})
PRINT_VAL([CPPFLAGS], ${CPPFLAGS})
PRINT_VAL([LDFLAGS], ${LDFLAGS})
PRINT_VAL([LOG2_CACHE_LINE_BYTES], ${with_log2_cache_line_bytes})
PRINT_VAL([DLMALLOC], ${enable_dlmalloc})
AM_COND_IF([ENABLE_JAPI],
[
PRINT_VAL([JAVA_VERSION], ${JAVA_VERSION})
+1 -1
View File
@@ -13,7 +13,7 @@
AUTOMAKE_OPTIONS = foreign subdir-objects
AM_CFLAGS = -Wall -I${top_srcdir} -I${top_builddir}
AM_CFLAGS = -Wall -I${top_srcdir} -I${top_builddir} @DLMALLOC@
AM_LDFLAGS = -module -shared -avoid-version
AM_LIBTOOLFLAGS = --quiet
SUFFIXES = .api.h .api .api.json
+13
View File
@@ -22,6 +22,19 @@ AC_DEFUN([CC_CHECK_FLAG],
AC_LANG_POP([C])
])
AC_DEFUN([ENABLE_ARG],
[
AC_ARG_ENABLE($1,
AC_HELP_STRING(patsubst([--enable-$1],[_],[-]), $2),
[enable_$1=yes n_enable_$1=1],
[enable_$1=no n_enable_$1=0])
AM_CONDITIONAL(m4_toupper(ENABLE_$1), test "$enable_$1" = "yes")
m4_append([list_of_enabled], [$1], [, ])
])
ENABLE_ARG(dlmalloc, [Enable dlmalloc])
AC_SUBST(DLMALLOC, [-DUSE_DLMALLOC=${n_enable_dlmalloc}])
CC_CHECK_FLAG("-Wno-address-of-packed-member")
AS_IF([test "$cc_flag_check" = yes],
[CFLAGS="${CFLAGS} -Wno-address-of-packed-member"], [])
+1 -1
View File
@@ -14,7 +14,7 @@
AUTOMAKE_OPTIONS = foreign subdir-objects
AM_CFLAGS = @CPU_FLAGS@ -Wall -I${top_srcdir} -I${top_builddir}
AM_CFLAGS = @CPU_FLAGS@ @DLMALLOC@ -Wall -I${top_srcdir} -I${top_builddir}
AM_LDFLAGS = -module -shared -avoid-version
AM_LIBTOOLFLAGS = --quiet
SUFFIXES = .api.h .api .api.json
+8 -3
View File
@@ -139,15 +139,16 @@ acl_set_heap (acl_main_t * am)
clib_warning ("ACL heap size requested: %lld, max possible %lld",
am->acl_mheap_size, max_possible);
}
am->acl_mheap = mheap_alloc (0 /* use VM */ , am->acl_mheap_size);
am->acl_mheap = mheap_alloc_with_lock (0 /* use VM */ ,
am->acl_mheap_size,
1 /* locked */ );
if (0 == am->acl_mheap)
{
clib_error
("ACL plugin failed to allocate main heap of %U bytes, abort",
format_memory_size, am->acl_mheap_size);
}
mheap_t *h = mheap_header (am->acl_mheap);
h->flags |= MHEAP_FLAG_THREAD_SAFE;
}
void *oldheap = clib_mem_set_heap (am->acl_mheap);
return oldheap;
@@ -164,6 +165,7 @@ void
acl_plugin_acl_set_validate_heap (acl_main_t * am, int on)
{
clib_mem_set_heap (acl_set_heap (am));
#if USE_DLMALLOC == 0
mheap_t *h = mheap_header (am->acl_mheap);
if (on)
{
@@ -176,12 +178,14 @@ acl_plugin_acl_set_validate_heap (acl_main_t * am, int on)
h->flags &= ~MHEAP_FLAG_VALIDATE;
h->flags |= MHEAP_FLAG_SMALL_OBJECT_CACHE;
}
#endif
}
void
acl_plugin_acl_set_trace_heap (acl_main_t * am, int on)
{
clib_mem_set_heap (acl_set_heap (am));
#if USE_DLMALLOC == 0
mheap_t *h = mheap_header (am->acl_mheap);
if (on)
{
@@ -191,6 +195,7 @@ acl_plugin_acl_set_trace_heap (acl_main_t * am, int on)
{
h->flags &= ~MHEAP_FLAG_TRACE;
}
#endif
}
static void
+9 -4
View File
@@ -558,12 +558,13 @@ static void *
hash_acl_set_heap(acl_main_t *am)
{
if (0 == am->hash_lookup_mheap) {
am->hash_lookup_mheap = mheap_alloc (0 /* use VM */ , am->hash_lookup_mheap_size);
am->hash_lookup_mheap = mheap_alloc_with_lock (0 /* use VM */ ,
am->hash_lookup_mheap_size,
1 /* locked */);
if (0 == am->hash_lookup_mheap) {
clib_error("ACL plugin failed to allocate hash lookup heap of %U bytes, abort", format_memory_size, am->hash_lookup_mheap_size);
clib_error("ACL plugin failed to allocate lookup heap of %U bytes",
format_memory_size, am->hash_lookup_mheap_size);
}
mheap_t *h = mheap_header (am->hash_lookup_mheap);
h->flags |= MHEAP_FLAG_THREAD_SAFE;
}
void *oldheap = clib_mem_set_heap(am->hash_lookup_mheap);
return oldheap;
@@ -574,6 +575,7 @@ acl_plugin_hash_acl_set_validate_heap(int on)
{
acl_main_t *am = &acl_main;
clib_mem_set_heap(hash_acl_set_heap(am));
#if USE_DLMALLOC == 0
mheap_t *h = mheap_header (am->hash_lookup_mheap);
if (on) {
h->flags |= MHEAP_FLAG_VALIDATE;
@@ -583,6 +585,7 @@ acl_plugin_hash_acl_set_validate_heap(int on)
h->flags &= ~MHEAP_FLAG_VALIDATE;
h->flags |= MHEAP_FLAG_SMALL_OBJECT_CACHE;
}
#endif
}
void
@@ -590,12 +593,14 @@ acl_plugin_hash_acl_set_trace_heap(int on)
{
acl_main_t *am = &acl_main;
clib_mem_set_heap(hash_acl_set_heap(am));
#if USE_DLMALLOC == 0
mheap_t *h = mheap_header (am->hash_lookup_mheap);
if (on) {
h->flags |= MHEAP_FLAG_TRACE;
} else {
h->flags &= ~MHEAP_FLAG_TRACE;
}
#endif
}
static void
+2 -2
View File
@@ -611,8 +611,8 @@ buffer_state_validation_init (vlib_main_t * vm)
{
void *oldheap;
vlib_buffer_state_heap = mheap_alloc (0, 10 << 20);
vlib_buffer_state_heap =
mheap_alloc_with_lock (0, 10 << 20, 0 /* locked */ );
oldheap = clib_mem_set_heap (vlib_buffer_state_heap);
vlib_buffer_state_validation_hash = hash_create (0, sizeof (uword));
+45 -14
View File
@@ -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);
}
+18
View File
@@ -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);
+24 -5
View File
@@ -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++)
{
+2 -9
View File
@@ -1409,21 +1409,14 @@ main (int argc, char **argv)
echo_main_t *em = &echo_main;
unformat_input_t _argv, *a = &_argv;
u8 *chroot_prefix;
u8 *heap, *uri = 0;
u8 *uri = 0;
u8 *bind_uri = (u8 *) "tcp://0.0.0.0/1234";
u8 *connect_uri = (u8 *) "tcp://6.0.1.1/1234";
u64 bytes_to_send = 64 << 10, mbytes;
char *app_name;
u32 tmp;
mheap_t *h;
clib_mem_init (0, 256 << 20);
heap = clib_mem_get_per_cpu_heap ();
h = mheap_header (heap);
/* make the main heap thread-safe */
h->flags |= MHEAP_FLAG_THREAD_SAFE;
clib_mem_init_thread_safe (0, 256 << 20);
memset (em, 0, sizeof (*em));
em->session_index_by_vpp_handles = hash_create (0, sizeof (uword));
+2 -7
View File
@@ -1207,16 +1207,11 @@ main (int argc, char **argv)
app_session_t *session;
u8 *chroot_prefix;
char *app_name;
mheap_t *h;
u8 *heap;
u32 tmp;
int i;
clib_mem_init (0, 256 << 20);
heap = clib_mem_get_per_cpu_heap ();
h = mheap_header (heap);
/* make the main heap thread-safe */
h->flags |= MHEAP_FLAG_THREAD_SAFE;
clib_mem_init_thread_safe (0, 256 << 20);
svm_fifo_segment_main_init (0x200000000ULL, 20);
vec_validate (utm->rx_buf, 8192);
+1 -9
View File
@@ -305,18 +305,10 @@ main (int argc, char **argv)
u8 *this_input_file;
u8 interactive = 1;
u8 json_output = 0;
u8 *heap;
mheap_t *h;
int i;
f64 timeout;
clib_mem_init (0, 128 << 20);
heap = clib_mem_get_per_cpu_heap ();
h = mheap_header (heap);
/* make the main heap thread-safe */
h->flags |= MHEAP_FLAG_THREAD_SAFE;
clib_mem_init_thread_safe (0, 128 << 20);
clib_macro_init (&vam->macro_main);
clib_macro_add_builtin (&vam->macro_main, "current_file",
+2
View File
@@ -62,6 +62,8 @@ main (int argc, char **argv)
uint32_t listen_fd;
vppcom_endpt_t endpt;
clib_mem_init_thread_safe (0, 64<<20);
//Address stuff
memset (&sin, 0, sizeof (sin));
sin.sin_family = AF_INET;
+1 -1
View File
@@ -200,7 +200,7 @@ defaulted:
ASSERT (vcl_mem != MAP_FAILED);
return;
}
heap = clib_mem_init (vcl_mem, vcl_cfg->heapsize);
heap = clib_mem_init_thread_safe (vcl_mem, vcl_cfg->heapsize);
if (!heap)
{
clib_warning ("VCL<%d>: ERROR: clib_mem_init() failed!", getpid ());
+3
View File
@@ -25,6 +25,7 @@
#include <fcntl.h>
#include <vcl/vcl_test.h>
#include <sys/epoll.h>
#include <vppinfra/mem.h>
typedef struct
{
@@ -310,6 +311,8 @@ main (int argc, char **argv)
uint16_t port = SOCK_TEST_SERVER_PORT;
vppcom_endpt_t endpt;
clib_mem_init_thread_safe (0, 64 << 20);
opterr = 0;
while ((c = getopt (argc, argv, "6D")) != -1)
switch (c)
+2 -7
View File
@@ -367,25 +367,20 @@ int
vppcom_app_create (char *app_name)
{
vppcom_cfg_t *vcl_cfg = &vcm->cfg;
u8 *heap;
mheap_t *h;
int rv;
if (!vcm->init)
{
vcm->init = 1;
vppcom_cfg (&vcm->cfg);
clib_spinlock_init (&vcm->session_fifo_lockp);
clib_fifo_validate (vcm->client_session_index_fifo,
vcm->cfg.listen_queue_size);
clib_spinlock_init (&vcm->sessions_lockp);
vppcom_cfg (&vcm->cfg);
vcm->main_cpu = os_get_thread_index ();
heap = clib_mem_get_per_cpu_heap ();
h = mheap_header (heap);
/* make the main heap thread-safe */
h->flags |= MHEAP_FLAG_THREAD_SAFE;
vcm->session_index_by_vpp_handles = hash_create (0, sizeof (uword));
+43 -3
View File
@@ -707,7 +707,7 @@ static clib_error_t *
show_memory_usage (vlib_main_t * vm,
unformat_input_t * input, vlib_cli_command_t * cmd)
{
int verbose = 0, api_segment = 0;
int verbose __attribute__ ((unused)) = 0, api_segment = 0;
clib_error_t *error;
u32 index = 0;
@@ -742,19 +742,55 @@ show_memory_usage (vlib_main_t * vm,
vec_free (s);
}
#if USE_DLMALLOC == 0
/* *INDENT-OFF* */
foreach_vlib_main (
({
mheap_t *h = mheap_header (clib_per_cpu_mheaps[index]);
vlib_cli_output (vm, "%sThread %d %v\n", index ? "\n":"", index,
vlib_cli_output (vm, "%sThread %d %s\n", index ? "\n":"", index,
vlib_worker_threads[index].name);
vlib_cli_output (vm, " %U\n", format_page_map, pointer_to_uword (h) -
h->vm_alloc_offset_from_header,
h->vm_alloc_size);
vlib_cli_output (vm, " %U\n", format_mheap, clib_per_cpu_mheaps[index], verbose);
vlib_cli_output (vm, " %U\n", format_mheap, clib_per_cpu_mheaps[index],
verbose);
index++;
}));
/* *INDENT-ON* */
#else
{
uword clib_mem_trace_enable_disable (uword enable);
uword was_enabled;
/*
* Note: the foreach_vlib_main cause allocator traffic,
* so shut off tracing before we go there...
*/
was_enabled = clib_mem_trace_enable_disable (0);
/* *INDENT-OFF* */
foreach_vlib_main (
({
struct mallinfo mi;
void *mspace;
mspace = clib_per_cpu_mheaps[index];
mi = mspace_mallinfo (mspace);
vlib_cli_output (vm, "%sThread %d %s\n", index ? "\n":"", index,
vlib_worker_threads[index].name);
vlib_cli_output (vm, " %U\n", format_page_map,
pointer_to_uword (mspace_least_addr(mspace)),
mi.arena);
vlib_cli_output (vm, " %U\n", format_mheap, clib_per_cpu_mheaps[index],
verbose);
index++;
}));
/* *INDENT-ON* */
/* Restore the trace flag */
clib_mem_trace_enable_disable (was_enabled);
}
#endif /* USE_DLMALLOC */
return 0;
}
@@ -850,6 +886,7 @@ static clib_error_t *
test_heap_validate (vlib_main_t * vm, unformat_input_t * input,
vlib_cli_command_t * cmd)
{
#if USE_DLMALLOC == 0
clib_error_t *error = 0;
void *heap;
mheap_t *mheap;
@@ -897,6 +934,9 @@ test_heap_validate (vlib_main_t * vm, unformat_input_t * input,
}
return error;
#else
return clib_error_return (0, "unimplemented...");
#endif /* USE_DLMALLOC */
}
/* *INDENT-OFF* */
+24 -1
View File
@@ -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;
+6 -1
View File
@@ -100,8 +100,13 @@ typedef struct vlib_main_t
/* Name for e.g. syslog. */
char *name;
/* Start and size of CLIB heap. */
/* Start of the heap. */
void *heap_base;
/* Truncated version, to create frame indices */
void *heap_aligned_base;
/* Size of the heap */
uword heap_size;
/* Pool of buffer free lists. */
+2 -2
View File
@@ -216,7 +216,7 @@ always_inline vlib_frame_t *
vlib_get_frame_no_check (vlib_main_t * vm, uword frame_index)
{
vlib_frame_t *f;
f = vm->heap_base + (frame_index * VLIB_FRAME_ALIGN);
f = vm->heap_aligned_base + (frame_index * VLIB_FRAME_ALIGN);
return f;
}
@@ -227,7 +227,7 @@ vlib_frame_index_no_check (vlib_main_t * vm, vlib_frame_t * f)
ASSERT (((uword) f & (VLIB_FRAME_ALIGN - 1)) == 0);
i = ((u8 *) f - (u8 *) vm->heap_base);
i = ((u8 *) f - (u8 *) vm->heap_aligned_base);
ASSERT ((i / VLIB_FRAME_ALIGN) <= 0xFFFFFFFFULL);
return i / VLIB_FRAME_ALIGN;
+21 -11
View File
@@ -727,7 +727,6 @@ start_workers (vlib_main_t * vm)
u32 n_vlib_mains = tm->n_vlib_mains;
u32 worker_thread_index;
u8 *main_heap = clib_mem_get_per_cpu_heap ();
mheap_t *main_heap_header = mheap_header (main_heap);
vec_reset_length (vlib_worker_threads);
@@ -742,12 +741,6 @@ start_workers (vlib_main_t * vm)
vlib_set_thread_name ((char *) w->name);
}
/*
* Truth of the matter: we always use at least two
* threads. So, make the main heap thread-safe
* and make the event log thread-safe.
*/
main_heap_header->flags |= MHEAP_FLAG_THREAD_SAFE;
vm->elog_main.lock =
clib_mem_alloc_aligned (CLIB_CACHE_LINE_BYTES, CLIB_CACHE_LINE_BYTES);
vm->elog_main.lock[0] = 0;
@@ -801,9 +794,17 @@ start_workers (vlib_main_t * vm)
vlib_node_t *n;
vec_add2 (vlib_worker_threads, w, 1);
/* Currently unused, may not really work */
if (tr->mheap_size)
w->thread_mheap =
mheap_alloc (0 /* use VM */ , tr->mheap_size);
{
#if USE_DLMALLOC == 0
w->thread_mheap =
mheap_alloc (0 /* use VM */ , tr->mheap_size);
#else
w->thread_mheap = create_mspace (tr->mheap_size,
0 /* unlocked */ );
#endif
}
else
w->thread_mheap = main_heap;
@@ -831,6 +832,8 @@ start_workers (vlib_main_t * vm)
vm_clone->thread_index = worker_thread_index;
vm_clone->heap_base = w->thread_mheap;
vm_clone->heap_aligned_base = (void *)
(((uword) w->thread_mheap) & ~(VLIB_FRAME_ALIGN - 1));
vm_clone->init_functions_called =
hash_create (0, /* value bytes */ 0);
vm_clone->pending_rpc_requests = 0;
@@ -959,8 +962,15 @@ start_workers (vlib_main_t * vm)
{
vec_add2 (vlib_worker_threads, w, 1);
if (tr->mheap_size)
w->thread_mheap =
mheap_alloc (0 /* use VM */ , tr->mheap_size);
{
#if USE_DLMALLOC == 0
w->thread_mheap =
mheap_alloc (0 /* use VM */ , tr->mheap_size);
#else
w->thread_mheap =
create_mspace (tr->mheap_size, 0 /* locked */ );
#endif
}
else
w->thread_mheap = main_heap;
w->thread_stack =
+2
View File
@@ -638,6 +638,8 @@ vlib_unix_main (int argc, char *argv[])
vm->argv = (u8 **) argv;
vm->name = argv[0];
vm->heap_base = clib_mem_get_heap ();
vm->heap_aligned_base = (void *)
(((uword) vm->heap_base) & ~(VLIB_FRAME_ALIGN - 1));
ASSERT (vm->heap_base);
unformat_init_command_line (&input, (char **) vm->argv);
+8
View File
@@ -140,7 +140,11 @@ vnet_classify_new_table (vnet_classify_main_t * cm,
t->skip_n_vectors = skip_n_vectors;
t->entries_per_page = 2;
#if USE_DLMALLOC == 0
t->mheap = mheap_alloc (0 /* use VM */ , memory_size);
#else
t->mheap = create_mspace (memory_size, 1 /* locked */ );
#endif
vec_validate_aligned (t->buckets, nbuckets - 1, CLIB_CACHE_LINE_BYTES);
oldheap = clib_mem_set_heap (t->mheap);
@@ -170,7 +174,11 @@ vnet_classify_delete_table_index (vnet_classify_main_t * cm,
vec_free (t->mask);
vec_free (t->buckets);
#if USE_DLMALLOC == 0
mheap_free (t->mheap);
#else
destroy_mspace (t->mheap);
#endif
pool_put (cm->tables, t);
}
+8
View File
@@ -567,10 +567,18 @@ ip4_fib_table_show_one (ip4_fib_t *fib,
u8 *
format_ip4_fib_table_memory (u8 * s, va_list * args)
{
#if USE_DLMALLOC == 0
s = format(s, "%=30s %=6d %=8ld\n",
"IPv4 unicast",
pool_elts(ip4_main.fibs),
mheap_bytes(ip4_main.mtrie_mheap));
#else
s = format(s, "%=30s %=6d %=8ld\n",
"IPv4 unicast",
pool_elts(ip4_main.fibs),
mspace_footprint(ip4_main.mtrie_mheap));
#endif
return (s);
}
+4
View File
@@ -812,7 +812,11 @@ ip4_mtrie_module_init (vlib_main_t * vm)
if (0 == im->mtrie_heap_size)
im->mtrie_heap_size = IP4_FIB_DEFAULT_MTRIE_HEAP_SIZE;
#if USE_DLMALLOC == 0
im->mtrie_mheap = mheap_alloc (0, im->mtrie_heap_size);
#else
im->mtrie_mheap = create_mspace (im->mtrie_heap_size, 1 /* locked */ );
#endif
/* Burn one ply so index 0 is taken */
old_heap = clib_mem_set_heap (ip4_main.mtrie_mheap);
+11 -6
View File
@@ -79,13 +79,18 @@ __attribute__((constructor))
static void
vac_client_constructor (void)
{
u8 *heap;
mheap_t *h;
clib_mem_init (0, 1 << 30);
heap = clib_mem_get_per_cpu_heap ();
h = mheap_header (heap);
/* make the main heap thread-safe */
h->flags |= MHEAP_FLAG_THREAD_SAFE;
#if USE_DLMALLOC == 0
{
u8 *heap;
mheap_t *h;
heap = clib_mem_get_per_cpu_heap ();
h = mheap_header (heap);
/* make the main heap thread-safe */
h->flags |= MHEAP_FLAG_THREAD_SAFE;
}
#endif
if (mem_trace)
clib_mem_trace (1);
}
+1 -1
View File
@@ -15,7 +15,7 @@ AUTOMAKE_OPTIONS = foreign
ACLOCAL_AMFLAGS = -I m4
AM_LIBTOOLFLAGS = --quiet
AM_CFLAGS = @CPU_FLAGS@ -Wall -I${top_srcdir} -I${top_builddir} \
AM_CFLAGS = @CPU_FLAGS@ @DLMALLOC@ -Wall -I${top_srcdir} -I${top_builddir} \
-I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux \
-I@top_srcdir@/plugins -I@top_builddir@/plugins

Some files were not shown because too many files have changed in this diff Show More