diff options
author | Damjan Marion <damarion@cisco.com> | 2022-03-19 00:07:52 +0100 |
---|---|---|
committer | Florin Coras <florin.coras@gmail.com> | 2022-03-30 18:27:13 +0000 |
commit | 299571aca34d36e637e43cfbba6275662d0d7795 (patch) | |
tree | a48be21950d082afb7dd93562f76f0ba554e8919 /src/vppinfra/heap.h | |
parent | 9539647b895c456ca53892a9259e3127c6b92d35 (diff) |
vppinfra: vector allocator rework
- support of in-place growth of vectors (if there is available space next to
existing alloc)
- drops the need for alloc_aligned_at_offset from memory allocator,
which allows easier swap to different memory allocator and reduces
malloc overhead
- rework of pool and vec macros to inline functions to improve debuggability
- fix alignment - in many cases macros were not using native alignment
of the particular datatype. Explicitly setting alignment with XXX_aligned()
versions of the macro is not needed anymore in > 99% of cases
- fix ASAN usage
- avoid use of vector of voids, this was root cause of several bugs
found in vec_* and pool_* function where sizeof() was used on voids
instead of real vector data type
- introduce minimal alignment which is currently 8 bytes, vectors will
be always aligned at least to that value (underlay allocator actually always
provide 16-byte aligned allocs)
Type: improvement
Change-Id: I20f4b081bb13bbf7bc0ace85cc4e301787f12fdf
Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/vppinfra/heap.h')
-rw-r--r-- | src/vppinfra/heap.h | 38 |
1 files changed, 4 insertions, 34 deletions
diff --git a/src/vppinfra/heap.h b/src/vppinfra/heap.h index 8b430644dbd..f496fe07b2e 100644 --- a/src/vppinfra/heap.h +++ b/src/vppinfra/heap.h @@ -163,12 +163,6 @@ heap_header (void *v) return vec_header (v); } -always_inline uword -heap_header_bytes () -{ - return vec_header_bytes (sizeof (heap_header_t)); -} - always_inline void heap_dup_header (heap_header_t * old, heap_header_t * new) { @@ -198,10 +192,8 @@ _heap_dup (void *v_old, uword v_bytes) if (!v_old) return v_old; - v_new = 0; - v_new = - _vec_resize (v_new, _vec_len (v_old), v_bytes, sizeof (heap_header_t), - HEAP_DATA_ALIGN); + v_new = _vec_realloc (0, _vec_len (v_old), 1, sizeof (heap_header_t), + HEAP_DATA_ALIGN, 0); h_new = heap_header (v_new); heap_dup_header (h_old, h_new); clib_memcpy_fast (v_new, v_old, v_bytes); @@ -220,9 +212,8 @@ uword heap_bytes (void *v); always_inline void * _heap_new (u32 len, u32 n_elt_bytes) { - void *v = _vec_resize ((void *) 0, len, (uword) len * n_elt_bytes, - sizeof (heap_header_t), - HEAP_DATA_ALIGN); + void *v = _vec_realloc ((void *) 0, len, n_elt_bytes, sizeof (heap_header_t), + HEAP_DATA_ALIGN, 0); heap_header (v)->elt_bytes = n_elt_bytes; return v; } @@ -249,27 +240,6 @@ heap_get_max_len (void *v) return v ? heap_header (v)->max_len : 0; } -/* Create fixed size heap with given block of memory. */ -always_inline void * -heap_create_from_memory (void *memory, uword max_len, uword elt_bytes) -{ - heap_header_t *h; - void *v; - - if (max_len * elt_bytes < sizeof (h[0])) - return 0; - - h = memory; - clib_memset (h, 0, sizeof (h[0])); - h->max_len = max_len; - h->elt_bytes = elt_bytes; - h->flags = HEAP_IS_STATIC; - - v = (void *) (memory + heap_header_bytes ()); - _vec_len (v) = 0; - return v; -} - /* Execute BODY for each allocated heap element. */ #define heap_foreach(var,len,heap,body) \ do { \ |