X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvppinfra%2Fmem_dlmalloc.c;h=9b089aee8ec86a1e017a6398bd13e94255817baa;hb=2de9c0f92;hp=5628e2714c73ea2c43950bdd8c6208b53d98b862;hpb=9fb6d40eb3d4a2da8f45187de773498b784596e6;p=vpp.git diff --git a/src/vppinfra/mem_dlmalloc.c b/src/vppinfra/mem_dlmalloc.c index 5628e2714c7..9b089aee8ec 100644 --- a/src/vppinfra/mem_dlmalloc.c +++ b/src/vppinfra/mem_dlmalloc.c @@ -20,8 +20,10 @@ #include #include #include +#include void *clib_per_cpu_mheaps[CLIB_MAX_MHEAPS]; +void *clib_per_numa_mheaps[CLIB_MAX_NUMAS]; typedef struct { @@ -29,11 +31,7 @@ typedef struct uword callers[12]; /* Count of allocations with this traceback. */ -#if CLIB_VEC64 > 0 - u64 n_allocations; -#else u32 n_allocations; -#endif /* Count of bytes allocated with this traceback. */ u32 n_bytes; @@ -202,8 +200,8 @@ mheap_trace_main_free (mheap_trace_main_t * tm) /* Initialize CLIB heap based on memory/size given by user. Set memory to 0 and CLIB will try to allocate its own heap. */ -void * -clib_mem_init (void *memory, uword memory_size) +static void * +clib_mem_init_internal (void *memory, uword memory_size, int set_heap) { u8 *heap; @@ -215,19 +213,53 @@ clib_mem_init (void *memory, uword memory_size) else heap = create_mspace (memory_size, 1 /* locked */ ); - clib_mem_set_heap (heap); + CLIB_MEM_POISON (mspace_least_addr (heap), mspace_footprint (heap)); + + if (set_heap) + clib_mem_set_heap (heap); if (mheap_trace_main.lock == 0) clib_spinlock_init (&mheap_trace_main.lock); - CLIB_MEM_POISON (mspace_least_addr (heap), mspace_footprint (heap)); return heap; } +void * +clib_mem_init (void *memory, uword memory_size) +{ + return clib_mem_init_internal (memory, memory_size, + 1 /* do clib_mem_set_heap */ ); +} + void * clib_mem_init_thread_safe (void *memory, uword memory_size) { - return clib_mem_init (memory, memory_size); + return clib_mem_init_internal (memory, memory_size, + 1 /* do clib_mem_set_heap */ ); +} + +void * +clib_mem_init_thread_safe_numa (void *memory, uword memory_size, u8 numa) +{ + clib_mem_vm_alloc_t alloc = { 0 }; + clib_error_t *err; + void *heap; + + alloc.size = memory_size; + alloc.flags = CLIB_MEM_VM_F_NUMA_FORCE; + alloc.numa_node = numa; + if ((err = clib_mem_vm_ext_alloc (&alloc))) + { + clib_error_report (err); + return 0; + } + + heap = clib_mem_init_internal (memory, memory_size, + 0 /* do NOT clib_mem_set_heap */ ); + + ASSERT (heap); + + return heap; } u8 *