aboutsummaryrefslogtreecommitdiffstats
path: root/src/vppinfra
diff options
context:
space:
mode:
Diffstat (limited to 'src/vppinfra')
-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
6 files changed, 50 insertions, 87 deletions
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>