Barrelfish
Functions
slab.c File Reference

Simple slab allocator. More...

Functions

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...
 

Detailed Description

Simple slab allocator.

This file implements a simple slab allocator. It allocates blocks of a fixed size from a pool of contiguous memory regions ("slabs").

Function Documentation

void* slab_alloc ( struct slab_allocator *  slabs)

Allocate a new block from the slab allocator.

Parameters
slabsPointer 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
slabsPointer to slab allocator instance
void slab_free ( struct slab_allocator *  slabs,
void *  block 
)

Free a block to the slab allocator.

Parameters
slabsPointer to slab allocator instance
blockPointer 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
slabsPointer 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
slabsPointer to slab allocator instance
bufPointer to start of memory region
buflenSize 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
slabsPointer to slab allocator instance, to be filled-in
blocksizeSize of blocks to be allocated by this allocator
refill_funcPointer to function to call when out of memory (or NULL)