Simple slab allocator.
More...
|
|
#define | SLAB_STATIC_SIZE(nblocks, blocksize) ((nblocks) * SLAB_REAL_BLOCKSIZE(blocksize) + sizeof(struct slab_head)) |
| | Macro to compute the static buffer size required for a given allocation.
|
| |
|
| void | slab_init (struct slab_allocator *slabs, size_t blocksize, slab_refill_func_t refill_func) |
| | Initialise a new slab allocator. More...
|
| |
| void | slab_grow (struct slab_allocator *slabs, void *buf, size_t buflen) |
| | Add memory (a new slab) to a slab allocator. More...
|
| |
| void * | slab_alloc (struct slab_allocator *slabs) |
| | Allocate a new block from the slab allocator. More...
|
| |
| void | slab_free (struct slab_allocator *slabs, void *block) |
| | Free a block to the slab allocator. More...
|
| |
| size_t | slab_freecount (struct slab_allocator *slabs) |
| | Returns the count of free blocks in the allocator. More...
|
| |
| errval_t | slab_default_refill (struct slab_allocator *slabs) |
| | General-purpose implementation of a slab allocate/refill function. More...
|
| |
| void* slab_alloc |
( |
struct slab_allocator * |
slabs | ) |
|
Allocate a new block from the slab allocator.
- Parameters
-
| slabs | Pointer to slab allocator instance |
- Returns
- Pointer to block on success, NULL on error (out of memory)
| errval_t slab_default_refill |
( |
struct slab_allocator * |
slabs | ) |
|
General-purpose implementation of a slab allocate/refill function.
Allocates and maps a single page (FIXME: make configurable) and adds it to the allocator.
- Parameters
-
| slabs | Pointer to slab allocator instance |
| void slab_free |
( |
struct slab_allocator * |
slabs, |
|
|
void * |
block |
|
) |
| |
Free a block to the slab allocator.
- Parameters
-
| slabs | Pointer to slab allocator instance |
| block | Pointer to block previously returned by slab_alloc |
| size_t slab_freecount |
( |
struct slab_allocator * |
slabs | ) |
|
Returns the count of free blocks in the allocator.
- Parameters
-
| slabs | Pointer to slab allocator instance |
- Returns
- Free block count
| void slab_grow |
( |
struct slab_allocator * |
slabs, |
|
|
void * |
buf, |
|
|
size_t |
buflen |
|
) |
| |
Add memory (a new slab) to a slab allocator.
- Parameters
-
| slabs | Pointer to slab allocator instance |
| buf | Pointer to start of memory region |
| buflen | Size of memory region (in bytes) |
| void slab_init |
( |
struct slab_allocator * |
slabs, |
|
|
size_t |
blocksize, |
|
|
slab_refill_func_t |
refill_func |
|
) |
| |
Initialise a new slab allocator.
- Parameters
-
| slabs | Pointer to slab allocator instance, to be filled-in |
| blocksize | Size of blocks to be allocated by this allocator |
| refill_func | Pointer to function to call when out of memory (or NULL) |