FD.io VPP
v21.10.1-2-g0a485f517
Vector Packet Processing
|
Fixed length block allocator. Pools are built from clib vectors and bitmaps. Use pools when repeatedly allocating and freeing fixed-size data. Pools are fast, and avoid memory fragmentation. More...
Go to the source code of this file.
Data Structures | |
struct | pool_header_t |
Macros | |
#define | pool_aligned_header_bytes vec_aligned_header_bytes (sizeof (pool_header_t), sizeof (void *)) |
Align pool header so that pointers are naturally aligned. More... | |
#define | pool_init_fixed(pool, max_elts) |
initialize a fixed-size, preallocated pool More... | |
#define | pool_validate_index(v, i) |
#define | pool_len(p) vec_len(p) |
Number of elements in pool vector. More... | |
#define | pool_bytes(P) (vec_bytes (P) + pool_header_bytes (P)) |
Memory usage of pool. More... | |
#define | pool_get_aligned_zero_numa(P, E, A, Z, S) _pool_get_aligned_internal_numa(P,E,A,Z,S) |
#define | pool_get_aligned_numa(P, E, A, S) _pool_get_aligned_internal_numa(P,E,A,0/*zero*/,S) |
#define | pool_get_numa(P, E, S) _pool_get_aligned_internal_numa(P,E,0/*align*/,0/*zero*/,S) |
#define | pool_get_aligned(P, E, A) _pool_get_aligned_internal(P,E,A,0) |
Allocate an object E from a pool P with alignment A. More... | |
#define | pool_get_aligned_zero(P, E, A) _pool_get_aligned_internal(P,E,A,1) |
Allocate an object E from a pool P with alignment A and zero it. More... | |
#define | pool_get(P, E) pool_get_aligned(P,E,0) |
Allocate an object E from a pool P (unspecified alignment). More... | |
#define | pool_get_zero(P, E) pool_get_aligned_zero(P,E,0) |
Allocate an object E from a pool P and zero it. More... | |
#define | pool_get_aligned_will_expand(P, YESNO, A) |
See if pool_get will expand the pool or not. More... | |
#define | pool_get_will_expand(P, YESNO) pool_get_aligned_will_expand(P,YESNO,0) |
Tell the caller if pool get will expand the pool. More... | |
#define | pool_is_free(P, E) |
Use free bitmap to query whether given element is free. More... | |
#define | pool_is_free_index(P, I) pool_is_free((P),(P)+(I)) |
Use free bitmap to query whether given index is free. More... | |
#define | pool_put(P, E) |
Free an object E in pool P. More... | |
#define | pool_put_index(p, i) |
Free pool element with given index. More... | |
#define | pool_alloc_aligned(P, N, A) |
Allocate N more free elements to pool (general version). More... | |
#define | pool_alloc(P, N) pool_alloc_aligned(P,N,0) |
Allocate N more free elements to pool (unspecified alignment). More... | |
#define | pool_dup_aligned(P, A) |
Return copy of pool with alignment. More... | |
#define | pool_dup(P) pool_dup_aligned(P,0) |
Return copy of pool without alignment. More... | |
#define | pool_free(p) (p) = _pool_free(p) |
Free a pool. More... | |
#define | pool_foreach_region(LO, HI, POOL, BODY) |
Optimized iteration through pool. More... | |
#define | pool_foreach(VAR, POOL) |
Iterate through pool. More... | |
#define | pool_elt_at_index(p, i) |
Returns pointer to element at given index. More... | |
#define | pool_next_index(P, I) |
Return next occupied pool index after i , useful for safe iteration. More... | |
#define | pool_foreach_index(i, v) |
#define | pool_flush(VAR, POOL, BODY) |
Remove all elements from a pool in a safe way. More... | |
Functions | |
static pool_header_t * | pool_header (void *v) |
Get pool header from user pool pointer. More... | |
void | fpool_free (void *) |
static void | pool_validate (void *v) |
Validate a pool. More... | |
static void | pool_header_validate_index (void *v, uword index) |
static uword | pool_elts (void *v) |
Number of active elements in a pool. More... | |
static uword | pool_header_bytes (void *v) |
Memory usage of pool header. More... | |
static uword | pool_free_elts (void *v) |
Queries whether pool has at least N_FREE free elements. More... | |
static_always_inline uword | pool_get_first_index (void *pool) |
static_always_inline uword | pool_get_next_index (void *pool, uword last) |
Fixed length block allocator. Pools are built from clib vectors and bitmaps. Use pools when repeatedly allocating and freeing fixed-size data. Pools are fast, and avoid memory fragmentation.
Definition in file pool.h.
#define pool_aligned_header_bytes vec_aligned_header_bytes (sizeof (pool_header_t), sizeof (void *)) |
#define pool_alloc | ( | P, | |
N | |||
) | pool_alloc_aligned(P,N,0) |
Allocate N more free elements to pool (general version).
#define pool_bytes | ( | P | ) | (vec_bytes (P) + pool_header_bytes (P)) |
#define pool_dup | ( | P | ) | pool_dup_aligned(P,0) |
Return copy of pool with alignment.
P | pool to copy |
A | alignment (may be zero) |
#define pool_elt_at_index | ( | p, | |
i | |||
) |
Returns pointer to element at given index.
ASSERTs that the supplied index is valid. Even though one can write correct code of the form
use of pool_elt_at_index
is strongly suggested.
#define pool_flush | ( | VAR, | |
POOL, | |||
BODY | |||
) |
Remove all elements from a pool in a safe way.
VAR | each element in the pool |
POOL | The pool to flush |
BODY | The actions to perform on each element before it is returned to the pool. i.e. before it is 'freed' |
#define pool_foreach | ( | VAR, | |
POOL | |||
) |
Iterate through pool.
VAR | A variable of same type as pool vector to be used as an iterator. |
POOL | The pool to iterate across. |
BODY | The operation to perform, typically a code block. See the example below. |
This macro will call BODY
with each active pool element.
It is a bad idea to allocate or free pool element from within pool_foreach
. Build a vector of indices and dispose of them later. Or call pool_flush.
pool_foreach
is a macro, syntax errors can be difficult to find inside BODY
, let alone actual code bugs. One can temporarily split a complex pool_foreach
into a trivial pool_foreach
which builds a vector of active indices, and a vec_foreach() (or plain for-loop) to walk the active index vector. #define pool_foreach_index | ( | i, | |
v | |||
) |
#define pool_foreach_region | ( | LO, | |
HI, | |||
POOL, | |||
BODY | |||
) |
Optimized iteration through pool.
LO | pointer to first element in chunk |
HI | pointer to last element in chunk |
POOL | pool to iterate across |
BODY | operation to perform |
Optimized version which assumes that BODY is smart enough to process multiple (LOW,HI) chunks. See also pool_foreach().
#define pool_get | ( | P, | |
E | |||
) | pool_get_aligned(P,E,0) |
See if pool_get will expand the pool or not.
#define pool_get_will_expand | ( | P, | |
YESNO | |||
) | pool_get_aligned_will_expand(P,YESNO,0) |
#define pool_get_zero | ( | P, | |
E | |||
) | pool_get_aligned_zero(P,E,0) |
#define pool_init_fixed | ( | pool, | |
max_elts | |||
) |
#define pool_is_free | ( | P, | |
E | |||
) |
Use free bitmap to query whether given element is free.
#define pool_is_free_index | ( | P, | |
I | |||
) | pool_is_free((P),(P)+(I)) |
#define pool_len | ( | p | ) | vec_len(p) |
Number of elements in pool vector.
#define pool_next_index | ( | P, | |
I | |||
) |
Return next occupied pool index after i
, useful for safe iteration.
#define pool_put | ( | P, | |
E | |||
) |
Free an object E in pool P.
#define pool_put_index | ( | p, | |
i | |||
) |
#define pool_validate_index | ( | v, | |
i | |||
) |
void fpool_free | ( | void * | ) |
|
inlinestatic |
|
inlinestatic |
static_always_inline uword pool_get_first_index | ( | void * | pool | ) |
static_always_inline uword pool_get_next_index | ( | void * | pool, |
uword | last | ||
) |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |