vppinfra: don't call dlmalloc API directly from the code 36/29136/2
authorDamjan Marion <damarion@cisco.com>
Mon, 28 Sep 2020 17:03:37 +0000 (19:03 +0200)
committerDamjan Marion <damarion@cisco.com>
Mon, 28 Sep 2020 18:34:07 +0000 (20:34 +0200)
 - 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>
27 files changed:
src/svm/fifo_segment.c
src/svm/persist.c
src/svm/ssvm.c
src/svm/ssvm.h
src/svm/svm.c
src/svm/svm_test.c
src/svm/svmdb.c
src/svm/svmdbtool.c
src/svm/svmtool.c
src/vcl/vppcom.c
src/vlib/cli.c
src/vlib/threads.c
src/vnet/classify/vnet_classify.c
src/vnet/classify/vnet_classify.h
src/vpp-api/client/test.c
src/vpp/api/api.c
src/vpp/api/gmon.c
src/vpp/api/test_client.c
src/vpp/api/test_ha.c
src/vpp/api/vpp_get_metrics.c
src/vpp/stats/stat_segment.c
src/vppinfra/CMakeLists.txt
src/vppinfra/mem.h
src/vppinfra/mem_dlmalloc.c
src/vppinfra/mheap.h [deleted file]
src/vppinfra/pool.h
src/vppinfra/test_mheap.c

index 3fd7d9d..5fb2758 100644 (file)
@@ -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
index 023c596..d0cf172 100644 (file)
@@ -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>
index 073bc0b..d8831ec 100644 (file)
@@ -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 ());
 }
 
index 6225a63..2a9da3d 100644 (file)
@@ -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>
index fc91782..c087655 100644 (file)
@@ -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);
 
index ab0b9e2..c55d631 100644 (file)
@@ -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>
 
index 15922ad..2c3d351 100644 (file)
@@ -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>
index ca8201b..feb7eed 100644 (file)
@@ -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>
index 643b484..0f38d7f 100644 (file)
@@ -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>
index 7286882..8a934c3 100644 (file)
@@ -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;
index 6841a5b..c485f96 100644 (file)
@@ -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);
          }
       }
index c2ac4a1..0fc306d 100644 (file)
@@ -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;
index f4a6317..8e77d25 100644 (file)
@@ -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,
index db3821b..f0c8124 100644 (file)
@@ -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);
index 6e74761..67c3b68 100644 (file)
@@ -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);
index 99e9eb5..25dcc03 100644 (file)
@@ -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>
index 044410f..a8eecbb 100644 (file)
@@ -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>
index 3c54594..2d89d5c 100644 (file)
@@ -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>
index e05361b..96cbfbe 100644 (file)
@@ -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>
index 4653664..04036bc 100644 (file)
@@ -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>
index 968c056..b060969 100644 (file)
@@ -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;
 
index 9e8bc3c..3d54be2 100644 (file)
@@ -133,7 +133,6 @@ set(VPPINFRA_HEADERS
   memcpy_sse3.h
   mem.h
   mhash.h
-  mheap.h
   mpcap.h
   os.h
   pcap.h
index 9fc7f0e..2fd4bfb 100644 (file)
@@ -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 ();
index 10d3c61..069a0ad 100644 (file)
@@ -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 (file)
index dc0e607..0000000
+++ /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:
- */
index db950d2..c74e76f 100644 (file)
@@ -46,7 +46,6 @@
 
 #include <vppinfra/bitmap.h>
 #include <vppinfra/error.h>
-#include <vppinfra/mheap.h>
 
 
 typedef struct
index de94065..ae0c58a 100644 (file)
@@ -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>