summaryrefslogtreecommitdiffstats
path: root/src/vppinfra/mem_dlmalloc.c
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 /src/vppinfra/mem_dlmalloc.c
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>
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;
}
/*