summaryrefslogtreecommitdiffstats
path: root/src/vppinfra/mem_dlmalloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/vppinfra/mem_dlmalloc.c')
-rw-r--r--src/vppinfra/mem_dlmalloc.c59
1 files changed, 35 insertions, 24 deletions
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;
}
/*