50 if (CLIB_DEBUG > 0 && index != ~0)
55 ASSERT (template->baseva < ch->
baseva || template->baseva >=
57 ASSERT (template->baseva + template->size < ch->
baseva ||
58 template->baseva + template->size >=
68 if (index == ~0 || template->baseva < ch->
baseva)
86 new_ch->
baseva =
template->baseva;
87 new_ch->
size =
template->size;
113 new_ch->
baseva =
template->baseva;
114 new_ch->
size =
template->size;
132 ASSERT (
template && template->baseva && template->size);
152 int os_out_of_memory_on_failure)
171 if (ch->
size == size)
213 if (os_out_of_memory_on_failure)
232 uword return_size = 0;
247 return_size = ch->
size;
316 int verbose = va_arg (*va,
int);
323 s =
format (s,
"%d chunks, first index %d\n",
333 s =
format (s,
"[%d] base %llx size %llx (%lld) prev %d %s\n",
340 s =
format (s,
" BUG: baseva not in hash table!\n");
342 else if (p[0] != index)
344 s =
format (s,
" BUG: baseva in hash table %d not %d!\n",
#define CLIB_VALLOC_BUSY
chunk is in use
#define hash_set(h, key, value)
#define hash_unset(h, key)
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
static_always_inline void clib_spinlock_unlock_if_init(clib_spinlock_t *p)
__clib_export void clib_valloc_init(clib_valloc_main_t *vam, clib_valloc_chunk_t *template, int need_lock)
Initialize a virtual memory allocation arena.
void os_out_of_memory(void)
clib_valloc_chunk_t * chunks
pool of virtual chunks
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
#define CLIB_VALLOC_INITIALIZED
object has been initialized
u32 first_index
pool index of first chunk in list
uword * chunk_index_by_baseva
chunk by baseva hash
description fragment has unexpected format
Simple first-fit virtual space allocator.
static void clib_spinlock_init(clib_spinlock_t *p)
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
__clib_export uword clib_valloc_free(clib_valloc_main_t *vam, uword baseva)
Free virtual space.
uword flags
flags (free/busy)
void clib_valloc_add_chunk(clib_valloc_main_t *vam, clib_valloc_chunk_t *template)
Add a chunk of memory to a virtual allocation arena.
#define pool_put(P, E)
Free an object E in pool P.
uword size
size in bytes of this chunk
u32 prev
previous chunk pool index
uword baseva
base VA for this chunk
clib_spinlock_t lock
spinlock
#define hash_create(elts, value_bytes)
u32 next
next chunk pool index
u8 * format_valloc(u8 *s, va_list *va)
format a virtual allocation arena (varargs)
__clib_export uword clib_valloc_alloc(clib_valloc_main_t *vam, uword size, int os_out_of_memory_on_failure)
Allocate virtual space.
static_always_inline void clib_spinlock_lock_if_init(clib_spinlock_t *p)
static uword pool_elts(void *v)
Number of active elements in a pool.