aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2020-09-28 19:03:37 +0200
committerDamjan Marion <damarion@cisco.com>2020-09-28 20:34:07 +0200
commit4537c30925050ffa34c33e6a481f07f1ec0a01ff (patch)
tree0516dba983516dd12027cd59d18e514dcebe24de
parenta8af7cf253c4e8ab9ba1a2cfed50f6236fea3a62 (diff)
vppinfra: don't call dlmalloc API directly from the code
- it is confusing from end consumer perspective that some thing is somewhere called heap and somewhere mspace - this is base for additional work where heap pointer is not the same thing like mspace Type: improvement Change-Id: I644d5a0de17690d65d164d8cec3c5654571629ef Signed-off-by: Damjan Marion <damarion@cisco.com>
-rw-r--r--src/svm/fifo_segment.c5
-rw-r--r--src/svm/persist.c1
-rw-r--r--src/svm/ssvm.c27
-rw-r--r--src/svm/ssvm.h1
-rw-r--r--src/svm/svm.c13
-rw-r--r--src/svm/svm_test.c1
-rw-r--r--src/svm/svmdb.c1
-rw-r--r--src/svm/svmdbtool.c1
-rw-r--r--src/svm/svmtool.c1
-rw-r--r--src/vcl/vppcom.c6
-rw-r--r--src/vlib/cli.c31
-rw-r--r--src/vlib/threads.c12
-rw-r--r--src/vnet/classify/vnet_classify.c10
-rw-r--r--src/vnet/classify/vnet_classify.h4
-rw-r--r--src/vpp-api/client/test.c2
-rw-r--r--src/vpp/api/api.c1
-rw-r--r--src/vpp/api/gmon.c1
-rw-r--r--src/vpp/api/test_client.c1
-rw-r--r--src/vpp/api/test_ha.c1
-rw-r--r--src/vpp/api/vpp_get_metrics.c1
-rw-r--r--src/vpp/stats/stat_segment.c14
-rw-r--r--src/vppinfra/CMakeLists.txt1
-rw-r--r--src/vppinfra/mem.h21
-rw-r--r--src/vppinfra/mem_dlmalloc.c59
-rw-r--r--src/vppinfra/mheap.h54
-rw-r--r--src/vppinfra/pool.h1
-rw-r--r--src/vppinfra/test_mheap.c1
27 files changed, 103 insertions, 169 deletions
diff --git a/src/svm/fifo_segment.c b/src/svm/fifo_segment.c
index 3fd7d9d6ede..5fb2758606e 100644
--- a/src/svm/fifo_segment.c
+++ b/src/svm/fifo_segment.c
@@ -40,10 +40,7 @@ static char *fifo_segment_mem_status_strings[] = {
static uword
fsh_free_space (fifo_segment_header_t * fsh)
{
- struct dlmallinfo dlminfo;
-
- dlminfo = mspace_mallinfo (fsh->ssvm_sh->heap);
- return dlminfo.fordblks;
+ return clib_mem_get_heap_free_space (fsh->ssvm_sh->heap);
}
static inline void
diff --git a/src/svm/persist.c b/src/svm/persist.c
index 023c596b9cf..d0cf172aea4 100644
--- a/src/svm/persist.c
+++ b/src/svm/persist.c
@@ -35,7 +35,6 @@
#include <vppinfra/bitmap.h>
#include <vppinfra/fifo.h>
#include <vppinfra/time.h>
-#include <vppinfra/mheap.h>
#include <vppinfra/heap.h>
#include <vppinfra/pool.h>
#include <vppinfra/format.h>
diff --git a/src/svm/ssvm.c b/src/svm/ssvm.c
index 073bc0b5403..d8831ec1c48 100644
--- a/src/svm/ssvm.c
+++ b/src/svm/ssvm.c
@@ -102,10 +102,9 @@ 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;
- sh->heap = create_mspace_with_base (((u8 *) sh) + page_size,
- ssvm->ssvm_size - page_size,
- 1 /* locked */ );
- mspace_disable_expand (sh->heap);
+ sh->heap = clib_mem_create_heap (((u8 *) sh) + page_size,
+ ssvm->ssvm_size - page_size,
+ 1 /* locked */ , "ssvm master shm");
oldheap = ssvm_push_heap (sh);
sh->name = format (0, "%s", ssvm->name, 0);
@@ -254,10 +253,9 @@ ssvm_master_init_memfd (ssvm_private_t * memfd)
sh->ssvm_va = pointer_to_uword (sh);
sh->type = SSVM_SEGMENT_MEMFD;
- sh->heap = create_mspace_with_base (((u8 *) sh) + page_size,
- memfd->ssvm_size - page_size,
- 1 /* locked */ );
- mspace_disable_expand (sh->heap);
+ sh->heap = clib_mem_create_heap (((u8 *) sh) + page_size,
+ memfd->ssvm_size - page_size,
+ 1 /* locked */ , "ssvm master memfd");
oldheap = ssvm_push_heap (sh);
sh->name = format (0, "%s", memfd->name, 0);
ssvm_pop_heap (oldheap);
@@ -341,7 +339,6 @@ ssvm_master_init_private (ssvm_private_t * ssvm)
{
uword pagesize = clib_mem_get_page_size (), rnd_size = 0;
clib_mem_vm_alloc_t alloc = { 0 };
- struct dlmallinfo dlminfo;
ssvm_shared_header_t *sh;
clib_error_t *err;
u8 *heap;
@@ -363,19 +360,15 @@ ssvm_master_init_private (ssvm_private_t * ssvm)
return SSVM_API_ERROR_CREATE_FAILURE;
}
- heap = create_mspace_with_base ((u8 *) alloc.addr + pagesize, rnd_size,
- 1 /* locked */ );
+ heap = clib_mem_create_heap ((u8 *) alloc.addr + pagesize, rnd_size,
+ 1 /* locked */ , "ssvm master private");
if (heap == 0)
{
clib_unix_warning ("mheap alloc");
return -1;
}
- mspace_disable_expand (heap);
-
- /* Find actual size because mspace size is rounded up by dlmalloc */
- dlminfo = mspace_mallinfo (heap);
- rnd_size = dlminfo.fordblks;
+ rnd_size = clib_mem_get_heap_free_space (heap);
ssvm->ssvm_size = rnd_size;
ssvm->i_am_master = 1;
@@ -407,7 +400,7 @@ void
ssvm_delete_private (ssvm_private_t * ssvm)
{
vec_free (ssvm->name);
- destroy_mspace (ssvm->sh->heap);
+ clib_mem_destroy_heap (ssvm->sh->heap);
clib_mem_vm_free (ssvm->sh, ssvm->ssvm_size + clib_mem_get_page_size ());
}
diff --git a/src/svm/ssvm.h b/src/svm/ssvm.h
index 6225a63cae4..2a9da3d2f32 100644
--- a/src/svm/ssvm.h
+++ b/src/svm/ssvm.h
@@ -33,7 +33,6 @@
#include <vppinfra/bitmap.h>
#include <vppinfra/fifo.h>
#include <vppinfra/time.h>
-#include <vppinfra/mheap.h>
#include <vppinfra/heap.h>
#include <vppinfra/pool.h>
#include <vppinfra/format.h>
diff --git a/src/svm/svm.c b/src/svm/svm.c
index fc917825be6..c08765541ed 100644
--- a/src/svm/svm.c
+++ b/src/svm/svm.c
@@ -36,7 +36,6 @@
#include <vppinfra/bitmap.h>
#include <vppinfra/fifo.h>
#include <vppinfra/time.h>
-#include <vppinfra/mheap.h>
#include <vppinfra/heap.h>
#include <vppinfra/pool.h>
#include <vppinfra/format.h>
@@ -336,9 +335,8 @@ svm_data_region_create (svm_map_region_args_t * a, svm_region_t * rp)
if (a->flags & SVM_FLAGS_MHEAP)
{
- rp->data_heap = create_mspace_with_base (rp->data_base,
- map_size, 1 /* locked */ );
- mspace_disable_expand (rp->data_heap);
+ rp->data_heap = clib_mem_create_heap (rp->data_base, map_size,
+ 1 /* locked */ , "svm data");
rp->flags |= SVM_FLAGS_MHEAP;
}
@@ -487,12 +485,11 @@ 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;
- rp->region_heap = create_mspace_with_base
+ rp->region_heap = clib_mem_create_heap
(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);
+ 0) ? a->pvt_heap_size : SVM_PVT_MHEAP_SIZE, 1 /* locked */ ,
+ "svm region");
oldheap = svm_push_pvt_heap (rp);
diff --git a/src/svm/svm_test.c b/src/svm/svm_test.c
index ab0b9e248e6..c55d631d3db 100644
--- a/src/svm/svm_test.c
+++ b/src/svm/svm_test.c
@@ -36,7 +36,6 @@
#include <vppinfra/bitmap.h>
#include <vppinfra/fifo.h>
#include <vppinfra/time.h>
-#include <vppinfra/mheap.h>
#include <vppinfra/heap.h>
#include <vppinfra/pool.h>
diff --git a/src/svm/svmdb.c b/src/svm/svmdb.c
index 15922ad68f4..2c3d351f0c7 100644
--- a/src/svm/svmdb.c
+++ b/src/svm/svmdb.c
@@ -35,7 +35,6 @@
#include <vppinfra/bitmap.h>
#include <vppinfra/fifo.h>
#include <vppinfra/time.h>
-#include <vppinfra/mheap.h>
#include <vppinfra/heap.h>
#include <vppinfra/pool.h>
#include <vppinfra/format.h>
diff --git a/src/svm/svmdbtool.c b/src/svm/svmdbtool.c
index ca8201bd22b..feb7eed07ef 100644
--- a/src/svm/svmdbtool.c
+++ b/src/svm/svmdbtool.c
@@ -33,7 +33,6 @@
#include <vppinfra/bitmap.h>
#include <vppinfra/fifo.h>
#include <vppinfra/time.h>
-#include <vppinfra/mheap.h>
#include <vppinfra/heap.h>
#include <vppinfra/pool.h>
#include <vppinfra/format.h>
diff --git a/src/svm/svmtool.c b/src/svm/svmtool.c
index 643b484bdf5..0f38d7fe0eb 100644
--- a/src/svm/svmtool.c
+++ b/src/svm/svmtool.c
@@ -35,7 +35,6 @@
#include <vppinfra/bitmap.h>
#include <vppinfra/fifo.h>
#include <vppinfra/time.h>
-#include <vppinfra/mheap.h>
#include <vppinfra/heap.h>
#include <vppinfra/pool.h>
#include <vppinfra/format.h>
diff --git a/src/vcl/vppcom.c b/src/vcl/vppcom.c
index 7286882adac..8a934c3686a 100644
--- a/src/vcl/vppcom.c
+++ b/src/vcl/vppcom.c
@@ -1254,8 +1254,7 @@ void
vppcom_app_destroy (void)
{
vcl_worker_t *wrk, *current_wrk;
- struct dlmallinfo mi;
- mspace heap;
+ void *heap;
if (!pool_elts (vcm->workers))
return;
@@ -1280,8 +1279,7 @@ vppcom_app_destroy (void)
* Free the heap and fix vcm
*/
heap = clib_mem_get_heap ();
- mi = mspace_mallinfo (heap);
- munmap (mspace_least_addr (heap), mi.arena);
+ munmap (clib_mem_get_heap_base (heap), clib_mem_get_heap_size (heap));
vcm = &_vppcom_main;
vcm->is_init = 0;
diff --git a/src/vlib/cli.c b/src/vlib/cli.c
index 6841a5b2996..c485f967bcd 100644
--- a/src/vlib/cli.c
+++ b/src/vlib/cli.c
@@ -507,7 +507,7 @@ vlib_cli_dispatch_sub_commands (vlib_main_t * vm,
}
(void) clib_mem_trace_enable_disable (0);
- leak_report = format (0, "%U", format_mheap, clib_mem_get_heap (),
+ leak_report = format (0, "%U", format_clib_mem_heap, 0,
1 /* verbose, i.e. print leaks */ );
clib_mem_trace (0);
vlib_cli_output (vm, "%v", leak_report);
@@ -781,8 +781,7 @@ show_memory_usage (vlib_main_t * vm,
{
void *oldheap = vl_msg_push_heap ();
was_enabled = clib_mem_trace_enable_disable (0);
- u8 *s_in_svm =
- format (0, "%U\n", format_mheap, clib_mem_get_heap (), 1);
+ u8 *s_in_svm = format (0, "%U\n", format_clib_mem_heap, 0, 1);
vl_msg_pop_heap (oldheap);
u8 *s = vec_dup (s_in_svm);
@@ -798,8 +797,7 @@ show_memory_usage (vlib_main_t * vm,
{
void *oldheap = vlib_stats_push_heap (0);
was_enabled = clib_mem_trace_enable_disable (0);
- u8 *s_in_svm =
- format (0, "%U\n", format_mheap, clib_mem_get_heap (), 1);
+ u8 *s_in_svm = format (0, "%U\n", format_clib_mem_heap, 0, 1);
if (oldheap)
clib_mem_set_heap (oldheap);
u8 *s = vec_dup (s_in_svm);
@@ -829,17 +827,14 @@ show_memory_usage (vlib_main_t * vm,
/* *INDENT-OFF* */
foreach_vlib_main (
({
- struct dlmallinfo mi;
- void *mspace;
- mspace = mm->per_cpu_mheaps[index];
+ void *heap = mm->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,
+ pointer_to_uword (clib_mem_get_heap_base(heap)),
+ clib_mem_get_heap_size (heap));
+ vlib_cli_output (vm, " %U\n", format_clib_mem_heap,
mm->per_cpu_mheaps[index],
verbose);
index++;
@@ -851,8 +846,7 @@ show_memory_usage (vlib_main_t * vm,
}
if (numa_heaps)
{
- struct dlmallinfo mi;
- void *mspace;
+ void *heap;
for (i = 0; i < ARRAY_LEN (mm->per_numa_mheaps); i++)
{
@@ -864,14 +858,13 @@ show_memory_usage (vlib_main_t * vm,
continue;
}
was_enabled = clib_mem_trace_enable_disable (0);
- mspace = mm->per_numa_mheaps[i];
+ heap = mm->per_numa_mheaps[i];
- mi = mspace_mallinfo (mspace);
vlib_cli_output (vm, "Numa %d:", i);
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,
+ pointer_to_uword (clib_mem_get_heap_base (heap)),
+ clib_mem_get_heap_size (heap));
+ vlib_cli_output (vm, " %U\n", format_clib_mem_heap,
mm->per_numa_mheaps[index], verbose);
}
}
diff --git a/src/vlib/threads.c b/src/vlib/threads.c
index c2ac4a1b389..0fc306db6f2 100644
--- a/src/vlib/threads.c
+++ b/src/vlib/threads.c
@@ -757,8 +757,10 @@ start_workers (vlib_main_t * vm)
vec_add2 (vlib_worker_threads, w, 1);
/* Currently unused, may not really work */
if (tr->mheap_size)
- w->thread_mheap = create_mspace (tr->mheap_size,
- 0 /* unlocked */ );
+ w->thread_mheap = clib_mem_create_heap (0, tr->mheap_size,
+ /* unlocked */ 0,
+ "%s%d heap",
+ tr->name, k);
else
w->thread_mheap = main_heap;
@@ -927,8 +929,10 @@ start_workers (vlib_main_t * vm)
vec_add2 (vlib_worker_threads, w, 1);
if (tr->mheap_size)
{
- w->thread_mheap =
- create_mspace (tr->mheap_size, 0 /* locked */ );
+ w->thread_mheap = clib_mem_create_heap (0, tr->mheap_size,
+ /* locked */ 0,
+ "%s%d heap",
+ tr->name, j);
}
else
w->thread_mheap = main_heap;
diff --git a/src/vnet/classify/vnet_classify.c b/src/vnet/classify/vnet_classify.c
index f4a63171170..8e77d25d736 100644
--- a/src/vnet/classify/vnet_classify.c
+++ b/src/vnet/classify/vnet_classify.c
@@ -147,9 +147,8 @@ vnet_classify_new_table (vnet_classify_main_t * cm,
t->skip_n_vectors = skip_n_vectors;
t->entries_per_page = 2;
- t->mheap = create_mspace (memory_size, 1 /* locked */ );
- /* classifier requires the memory to be contiguous, so can not expand. */
- mspace_disable_expand (t->mheap);
+ t->mheap = clib_mem_create_heap (0, memory_size, 1 /* locked */ ,
+ "classify");
vec_validate_aligned (t->buckets, nbuckets - 1, CLIB_CACHE_LINE_BYTES);
oldheap = clib_mem_set_heap (t->mheap);
@@ -176,7 +175,7 @@ vnet_classify_delete_table_index (vnet_classify_main_t * cm,
vec_free (t->mask);
vec_free (t->buckets);
- destroy_mspace (t->mheap);
+ clib_mem_destroy_heap (t->mheap);
pool_put (cm->tables, t);
}
@@ -2134,7 +2133,8 @@ format_vnet_classify_table (u8 * s, va_list * args)
s = format (s, "%10u%10d%10d%10d", index, t->active_elements,
t->next_table_index, t->miss_next_index);
- s = format (s, "\n Heap: %U", format_mheap, t->mheap, 0 /*verbose */ );
+ s = format (s, "\n Heap: %U", format_clib_mem_heap, t->mheap,
+ 0 /*verbose */ );
s = format (s, "\n nbuckets %d, skip %d match %d flag %d offset %d",
t->nbuckets, t->skip_n_vectors, t->match_n_vectors,
diff --git a/src/vnet/classify/vnet_classify.h b/src/vnet/classify/vnet_classify.h
index db3821b7c77..f0c81241584 100644
--- a/src/vnet/classify/vnet_classify.h
+++ b/src/vnet/classify/vnet_classify.h
@@ -303,7 +303,7 @@ vnet_classify_prefetch_bucket (vnet_classify_table_t * t, u64 hash)
static inline vnet_classify_entry_t *
vnet_classify_get_entry (vnet_classify_table_t * t, uword offset)
{
- u8 *hp = t->mheap;
+ u8 *hp = clib_mem_get_heap_base (t->mheap);
u8 *vp = hp + offset;
return (void *) vp;
@@ -315,7 +315,7 @@ vnet_classify_get_offset (vnet_classify_table_t * t,
{
u8 *hp, *vp;
- hp = (u8 *) t->mheap;
+ hp = (u8 *) clib_mem_get_heap_base (t->mheap);
vp = (u8 *) v;
ASSERT ((vp - hp) < 0x100000000ULL);
diff --git a/src/vpp-api/client/test.c b/src/vpp-api/client/test.c
index 6e74761fe24..67c3b68e48f 100644
--- a/src/vpp-api/client/test.c
+++ b/src/vpp-api/client/test.c
@@ -178,7 +178,7 @@ test_stats (void)
vec_free(dir);
(void) clib_mem_trace_enable_disable (0);
- u8 *leak_report = format (0, "%U", format_mheap, clib_mem_get_heap (),
+ u8 *leak_report = format (0, "%U", format_clib_mem_heap, 0,
1 /* verbose, i.e. print leaks */ );
printf("%s", leak_report);
vec_free (leak_report);
diff --git a/src/vpp/api/api.c b/src/vpp/api/api.c
index 99e9eb5df56..25dcc03c39d 100644
--- a/src/vpp/api/api.c
+++ b/src/vpp/api/api.c
@@ -39,7 +39,6 @@
#include <vppinfra/bitmap.h>
#include <vppinfra/fifo.h>
#include <vppinfra/time.h>
-#include <vppinfra/mheap.h>
#include <vppinfra/heap.h>
#include <vppinfra/pool.h>
#include <vppinfra/format.h>
diff --git a/src/vpp/api/gmon.c b/src/vpp/api/gmon.c
index 044410f734b..a8eecbbde19 100644
--- a/src/vpp/api/gmon.c
+++ b/src/vpp/api/gmon.c
@@ -31,7 +31,6 @@
#include <vppinfra/bitmap.h>
#include <vppinfra/fifo.h>
#include <vppinfra/time.h>
-#include <vppinfra/mheap.h>
#include <vppinfra/heap.h>
#include <vppinfra/pool.h>
#include <vppinfra/format.h>
diff --git a/src/vpp/api/test_client.c b/src/vpp/api/test_client.c
index 3c545945c3c..2d89d5c53c9 100644
--- a/src/vpp/api/test_client.c
+++ b/src/vpp/api/test_client.c
@@ -35,7 +35,6 @@
#include <vppinfra/bitmap.h>
#include <vppinfra/fifo.h>
#include <vppinfra/time.h>
-#include <vppinfra/mheap.h>
#include <vppinfra/heap.h>
#include <vppinfra/pool.h>
#include <vppinfra/format.h>
diff --git a/src/vpp/api/test_ha.c b/src/vpp/api/test_ha.c
index e05361b1d59..96cbfbe3899 100644
--- a/src/vpp/api/test_ha.c
+++ b/src/vpp/api/test_ha.c
@@ -35,7 +35,6 @@
#include <vppinfra/bitmap.h>
#include <vppinfra/fifo.h>
#include <vppinfra/time.h>
-#include <vppinfra/mheap.h>
#include <vppinfra/heap.h>
#include <vppinfra/pool.h>
#include <vppinfra/format.h>
diff --git a/src/vpp/api/vpp_get_metrics.c b/src/vpp/api/vpp_get_metrics.c
index 46536645dc9..04036bcdd61 100644
--- a/src/vpp/api/vpp_get_metrics.c
+++ b/src/vpp/api/vpp_get_metrics.c
@@ -33,7 +33,6 @@
#include <vppinfra/bitmap.h>
#include <vppinfra/fifo.h>
#include <vppinfra/time.h>
-#include <vppinfra/mheap.h>
#include <vppinfra/heap.h>
#include <vppinfra/pool.h>
#include <vppinfra/format.h>
diff --git a/src/vpp/stats/stat_segment.c b/src/vpp/stats/stat_segment.c
index 968c0566b3f..b060969f04f 100644
--- a/src/vpp/stats/stat_segment.c
+++ b/src/vpp/stats/stat_segment.c
@@ -22,7 +22,6 @@
#undef HAVE_MEMFD_CREATE
#include <vppinfra/linux/syscall.h>
#include <vpp-api/client/stat_client.h>
-#include <vppinfra/mheap.h>
stat_segment_main_t stat_segment_main;
@@ -345,9 +344,9 @@ vlib_map_stat_segment_init (void)
sys_page_sz = clib_mem_get_page_size ();
- heap = create_mspace_with_base (((u8 *) memaddr) + sys_page_sz, memory_size
- - sys_page_sz, 1 /* locked */ );
- mspace_disable_expand (heap);
+ heap = clib_mem_create_heap (((u8 *) memaddr) + sys_page_sz, memory_size
+ - sys_page_sz, 1 /* locked */ ,
+ "stat segment");
sm->heap = heap;
sm->memfd = mfd;
@@ -381,7 +380,7 @@ vlib_map_stat_segment_init (void)
/* Total shared memory size */
clib_mem_usage_t usage;
- mheap_usage (sm->heap, &usage);
+ clib_mem_get_heap_usage (sm->heap, &usage);
sm->directory_vector[STAT_COUNTER_MEM_STATSEG_TOTAL].value =
usage.bytes_total;
@@ -475,7 +474,8 @@ show_stat_segment_command_fn (vlib_main_t * vm,
if (verbose)
{
ASSERT (sm->heap);
- vlib_cli_output (vm, "%U", format_mheap, sm->heap, 0 /* verbose */ );
+ vlib_cli_output (vm, "%U", format_clib_mem_heap, sm->heap,
+ 0 /* verbose */ );
}
return 0;
@@ -658,7 +658,7 @@ do_stat_segment_updates (stat_segment_main_t * sm)
/* Stats segment memory heap counter */
clib_mem_usage_t usage;
- mheap_usage (sm->heap, &usage);
+ clib_mem_get_heap_usage (sm->heap, &usage);
sm->directory_vector[STAT_COUNTER_MEM_STATSEG_USED].value =
usage.bytes_used;
diff --git a/src/vppinfra/CMakeLists.txt b/src/vppinfra/CMakeLists.txt
index 9e8bc3c442c..3d54be2307f 100644
--- a/src/vppinfra/CMakeLists.txt
+++ b/src/vppinfra/CMakeLists.txt
@@ -133,7 +133,6 @@ set(VPPINFRA_HEADERS
memcpy_sse3.h
mem.h
mhash.h
- mheap.h
mpcap.h
os.h
pcap.h
diff --git a/src/vppinfra/mem.h b/src/vppinfra/mem.h
index 9fc7f0efa76..2fd4bfb5dbb 100644
--- a/src/vppinfra/mem.h
+++ b/src/vppinfra/mem.h
@@ -45,8 +45,6 @@
#include <vppinfra/clib.h> /* uword, etc */
#include <vppinfra/clib_error.h>
-#include <vppinfra/dlmalloc.h>
-
#include <vppinfra/os.h>
#include <vppinfra/string.h> /* memcpy, clib_memset */
#include <vppinfra/sanitizer.h>
@@ -180,6 +178,7 @@ clib_mem_set_thread_index (void)
always_inline uword
clib_mem_size_nocheck (void *p)
{
+ size_t mspace_usable_size_with_delta (const void *p);
return mspace_usable_size_with_delta (p);
}
@@ -190,6 +189,8 @@ clib_mem_alloc_aligned_at_offset (uword size, uword align, uword align_offset,
{
void *heap, *p;
uword cpu;
+ void *mspace_get_aligned (void *msp, unsigned long n_user_data_bytes,
+ unsigned long align, unsigned long align_offset);
if (align_offset > align)
{
@@ -270,6 +271,7 @@ always_inline uword
clib_mem_is_heap_object (void *p)
{
void *heap = clib_mem_get_per_cpu_heap ();
+ int mspace_is_heap_object (void *msp, void *p);
return mspace_is_heap_object (heap, p);
}
@@ -279,6 +281,7 @@ clib_mem_free (void *p)
{
u8 *heap = clib_mem_get_per_cpu_heap ();
+ void mspace_put (void *msp, void *p_arg);
/* Make sure object is in the correct heap. */
ASSERT (clib_mem_is_heap_object (p));
@@ -333,6 +336,10 @@ clib_mem_set_heap (void *heap)
return clib_mem_set_per_cpu_heap (heap);
}
+void clib_mem_destroy_heap (void *heap);
+void *clib_mem_create_heap (void *base, uword size, int is_locked, char *fmt,
+ ...);
+
void clib_mem_main_init ();
void *clib_mem_init (void *heap, uword size);
void *clib_mem_init_with_page_size (uword memory_size,
@@ -343,8 +350,6 @@ void *clib_mem_init_thread_safe_numa (void *memory, uword memory_size,
void clib_mem_exit (void);
-void clib_mem_validate (void);
-
void clib_mem_trace (int enable);
int clib_mem_is_traced (void);
@@ -374,9 +379,14 @@ typedef struct
uword bytes_max;
} clib_mem_usage_t;
-void clib_mem_usage (clib_mem_usage_t * usage);
+void clib_mem_get_heap_usage (void *heap, clib_mem_usage_t * usage);
+
+void *clib_mem_get_heap_base (void *heap);
+uword clib_mem_get_heap_size (void *heap);
+uword clib_mem_get_heap_free_space (void *heap);
u8 *format_clib_mem_usage (u8 * s, va_list * args);
+u8 *format_clib_mem_heap (u8 * s, va_list * va);
/* Allocate virtual address space. */
always_inline void *
@@ -475,7 +485,6 @@ uword clib_mem_vm_reserve (uword start, uword size,
clib_mem_page_sz_t log2_page_sz);
u64 *clib_mem_vm_get_paddr (void *mem, clib_mem_page_sz_t log2_page_size,
int n_pages);
-void clib_mem_destroy_mspace (void *mspace);
void clib_mem_destroy (void);
int clib_mem_set_numa_affinity (u8 numa_node, int force);
int clib_mem_set_default_numa_affinity ();
diff --git a/src/vppinfra/mem_dlmalloc.c b/src/vppinfra/mem_dlmalloc.c
index 10d3c61c77e..069a0add24b 100644
--- a/src/vppinfra/mem_dlmalloc.c
+++ b/src/vppinfra/mem_dlmalloc.c
@@ -426,13 +426,16 @@ format_mheap_trace (u8 * s, va_list * va)
u8 *
-format_mheap (u8 * s, va_list * va)
+format_clib_mem_heap (u8 * s, va_list * va)
{
void *heap = va_arg (*va, u8 *);
int verbose = va_arg (*va, int);
struct dlmallinfo mi;
mheap_trace_main_t *tm = &mheap_trace_main;
+ if (heap == 0)
+ heap = clib_mem_get_heap ();
+
mi = mspace_mallinfo (heap);
s = format (s, "total: %U, used: %U, free: %U, trimmable: %U",
@@ -459,7 +462,7 @@ clib_mem_usage (clib_mem_usage_t * u)
}
void
-mheap_usage (void *heap, clib_mem_usage_t * usage)
+clib_mem_get_heap_usage (void *heap, clib_mem_usage_t * usage)
{
struct dlmallinfo mi = mspace_mallinfo (heap);
@@ -523,37 +526,45 @@ clib_mem_trace_enable_disable (uword enable)
return rv;
}
-/*
- * These API functions seem like layering violations, but
- * by introducing them we greatly reduce the number
- * of code changes required to use dlmalloc spaces
- */
void *
-mheap_alloc_with_lock (void *memory, uword size, int locked)
+clib_mem_create_heap (void *base, uword size, int is_locked, char *fmt, ...)
{
void *rv;
- if (memory == 0)
- return create_mspace (size, locked);
+ if (base == 0)
+ rv = create_mspace (size, is_locked);
else
- {
- rv = create_mspace_with_base (memory, size, locked);
- if (rv)
- mspace_disable_expand (rv);
- return rv;
- }
+ rv = create_mspace_with_base (base, size, is_locked);
+
+ if (rv)
+ mspace_disable_expand (rv);
+ return rv;
}
-void *
-clib_mem_create_heap (void *base, uword size, char *fmt, ...)
+void
+clib_mem_destroy_heap (void *heap)
{
- base = clib_mem_vm_map_internal (base, CLIB_MEM_PAGE_SZ_DEFAULT, size, -1,
- 0, "str");
+ destroy_mspace (heap);
+}
- if (base == 0)
- return 0;
+uword
+clib_mem_get_heap_free_space (void *heap)
+{
+ struct dlmallinfo dlminfo = mspace_mallinfo (heap);
+ return dlminfo.fordblks;
+}
- create_mspace_with_base (base, size, 1 /* locked */ );
- return base;
+void *
+clib_mem_get_heap_base (void *heap)
+{
+ return mspace_least_addr (heap);
+}
+
+uword
+clib_mem_get_heap_size (void *heap)
+{
+ struct dlmallinfo mi;
+ mi = mspace_mallinfo (heap);
+ return mi.arena;
}
/*
diff --git a/src/vppinfra/mheap.h b/src/vppinfra/mheap.h
deleted file mode 100644
index dc0e6072081..00000000000
--- a/src/vppinfra/mheap.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco and/or its affiliates.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/*
- Copyright (c) 2001, 2002, 2003 Eliot Dresselhaus
-
- Permission is hereby granted, free of charge, to any person obtaining
- a copy of this software and associated documentation files (the
- "Software"), to deal in the Software without restriction, including
- without limitation the rights to use, copy, modify, merge, publish,
- distribute, sublicense, and/or sell copies of the Software, and to
- permit persons to whom the Software is furnished to do so, subject to
- the following conditions:
-
- The above copyright notice and this permission notice shall be
- included in all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#ifndef included_mheap_h
-#define included_mheap_h
-
-/* Format mheap data structures as string. */
-u8 *format_mheap (u8 * s, va_list * va);
-void *mheap_alloc_with_lock (void *memory, uword size, int locked);
-void mheap_usage (void *v, clib_mem_usage_t * usage);
-
-#endif /* included_mheap_h */
-
-/*
- * fd.io coding-style-patch-verification: ON
- *
- * Local Variables:
- * eval: (c-set-style "gnu")
- * End:
- */
diff --git a/src/vppinfra/pool.h b/src/vppinfra/pool.h
index db950d27d18..c74e76f0a4c 100644
--- a/src/vppinfra/pool.h
+++ b/src/vppinfra/pool.h
@@ -46,7 +46,6 @@
#include <vppinfra/bitmap.h>
#include <vppinfra/error.h>
-#include <vppinfra/mheap.h>
typedef struct
diff --git a/src/vppinfra/test_mheap.c b/src/vppinfra/test_mheap.c
index de94065edaf..ae0c58a6a74 100644
--- a/src/vppinfra/test_mheap.c
+++ b/src/vppinfra/test_mheap.c
@@ -45,7 +45,6 @@
#include <stdio.h> /* scanf */
#endif
-#include <vppinfra/mheap.h>
#include <vppinfra/format.h>
#include <vppinfra/random.h>
#include <vppinfra/time.h>