vppinfra: introduce clib_mem_main
[vpp.git] / src / vppinfra / mem_dlmalloc.c
index 38226e2..2cd924a 100644 (file)
 #include <vppinfra/hash.h>
 #include <vppinfra/elf_clib.h>
 #include <vppinfra/sanitizer.h>
-#include <numaif.h>
-
-void *clib_per_cpu_mheaps[CLIB_MAX_MHEAPS];
-void *clib_per_numa_mheaps[CLIB_MAX_NUMAS];
 
 typedef struct
 {
@@ -31,11 +27,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;
@@ -242,47 +234,43 @@ clib_mem_init_thread_safe (void *memory, uword memory_size)
                                 1 /* do clib_mem_set_heap */ );
 }
 
-void *
-clib_mem_init_thread_safe_numa (void *memory, uword memory_size)
+void
+clib_mem_destroy_mspace (void *mspace)
 {
-  void *heap;
-  unsigned long this_numa;
-
-  heap =
-    clib_mem_init_internal (memory, memory_size,
-                           0 /* do NOT clib_mem_set_heap */ );
-
-  ASSERT (heap);
+  mheap_trace_main_t *tm = &mheap_trace_main;
 
-  this_numa = os_get_numa_index ();
+  if (tm->enabled && mspace == tm->current_traced_mheap)
+    tm->enabled = 0;
 
-#if HAVE_NUMA_LIBRARY > 0
-  unsigned long nodemask = 1 << this_numa;
-  void *page_base;
-  unsigned long page_mask;
-  long rv;
+  destroy_mspace (mspace);
+}
 
-  /*
-   * Bind the heap to the current thread's NUMA node.
-   * heap is not naturally page-aligned, so fix it.
-   */
+void
+clib_mem_destroy (void)
+{
+  clib_mem_destroy_mspace (clib_mem_get_heap ());
+}
 
-  page_mask = ~(clib_mem_get_page_size () - 1);
-  page_base = (void *) (((unsigned long) heap) & page_mask);
+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;
 
-  clib_warning ("Bind heap at %llx size %llx to NUMA numa %d",
-               page_base, memory_size, this_numa);
+  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;
+    }
 
-  rv = mbind (page_base, memory_size, MPOL_BIND /* mode */ ,
-             &nodemask /* nodemask */ ,
-             BITS (nodemask) /* max node number */ ,
-             MPOL_MF_MOVE /* flags */ );
+  heap = clib_mem_init_internal (memory, memory_size,
+                                0 /* do NOT clib_mem_set_heap */ );
 
-  if (rv < 0)
-    clib_unix_warning ("mbind");
-#else
-  clib_warning ("mbind unavailable, can't bind to numa %d", this_numa);
-#endif
+  ASSERT (heap);
 
   return heap;
 }