#include <vppinfra/format.h>
#include <vppinfra/clib_error.h>
-/* while usage of dlmalloc APIs is genrally discouraged, in this particular
- * case there is significant benefit of calling them directly due to
- * smaller memory consuption (no wwp and headroom space) */
-#include <vppinfra/dlmalloc.h>
-
#define CLIB_MEM_BULK_DEFAULT_MIN_ELTS_PER_CHUNK 32
typedef struct clib_mem_bulk_chunk_hdr
u32 elts_per_chunk;
u32 align;
u32 chunk_align;
- void *mspace;
+ clib_mem_heap_t *heap;
clib_mem_bulk_chunk_hdr_t *full_chunks, *avail_chunks;
} clib_mem_bulk_t;
clib_mem_bulk_t *b;
uword sz;
- if ((b = mspace_memalign (heap->mspace, 16, sizeof (clib_mem_bulk_t))) == 0)
+ b = clib_mem_heap_alloc_aligned_or_null (heap, sizeof (clib_mem_bulk_t), 16);
+ if (b == 0)
return 0;
if (align < 16)
clib_mem_unpoison (b, sizeof (clib_mem_bulk_t));
clib_memset (b, 0, sizeof (clib_mem_bulk_t));
- b->mspace = heap->mspace;
+ b->heap = heap;
b->align = align;
b->elt_sz = round_pow2 (elt_sz, align);
b->chunk_hdr_sz = round_pow2 (sizeof (clib_mem_bulk_chunk_hdr_t), align);
{
clib_mem_bulk_t *b = h;
clib_mem_bulk_chunk_hdr_t *c, *next;
- void *ms = b->mspace;
+ clib_mem_heap_t *heap = b->heap;
c = b->full_chunks;
while (c)
{
next = c->next;
- clib_mem_poison (c, bulk_chunk_size (b));
- mspace_free (ms, c);
+ clib_mem_heap_free (heap, c);
c = next;
}
}
clib_mem_poison (b, sizeof (clib_mem_bulk_t));
- mspace_free (ms, b);
+ clib_mem_heap_free (heap, b);
}
static inline void *
if (b->avail_chunks == 0)
{
u32 i, sz = bulk_chunk_size (b);
- c = mspace_memalign (b->mspace, b->chunk_align, sz);
+ c = clib_mem_heap_alloc_aligned_or_null (b->heap, sz, b->chunk_align);
+ if (c == 0)
+ return 0;
clib_mem_unpoison (c, sz);
clib_memset (c, 0, sizeof (clib_mem_bulk_chunk_hdr_t));
b->avail_chunks = c;
{
/* chunk is empty - give it back */
remove_from_chunk_list (&b->avail_chunks, c);
- clib_mem_poison (c, bulk_chunk_size (b));
- mspace_free (b->mspace, c);
+ clib_mem_heap_free (b->heap, c);
return;
}