diff options
author | Alex Auvolat <alex.auvolat@ens.fr> | 2014-12-04 20:41:36 +0100 |
---|---|---|
committer | Alex Auvolat <alex.auvolat@ens.fr> | 2014-12-04 20:41:36 +0100 |
commit | 902eea7a56b38c20bbdca414e58fc6c3f4393025 (patch) | |
tree | bdf41874662f70b8d881c9af315a396b50893d50 /kernel/include/slab_alloc.h | |
parent | 3d1d4a069309e8bf07ea90500a0dcc97f50deacf (diff) | |
download | kogata-902eea7a56b38c20bbdca414e58fc6c3f4393025.tar.gz kogata-902eea7a56b38c20bbdca414e58fc6c3f4393025.zip |
First implementation of slab allocator. Needs more testing and polishing
Diffstat (limited to 'kernel/include/slab_alloc.h')
-rw-r--r-- | kernel/include/slab_alloc.h | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/kernel/include/slab_alloc.h b/kernel/include/slab_alloc.h new file mode 100644 index 0000000..a3bd7de --- /dev/null +++ b/kernel/include/slab_alloc.h @@ -0,0 +1,34 @@ +#pragma once + +// Self-contained piece of library : a slab allocator... +// Depends on page_alloc_fun_t and page_free_fun_t : a couple of functions +// that can allocate/free multiples of one page at a time + +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> + +#include <sys.h> + +// expected format for the array of slab_type_t given to slab_create : +// an array of slab_type descriptors, with last descriptor full of zeroes +// and with obj_size increasing (strictly) in the array +typedef struct slab_type { + const char *descr; + size_t obj_size; + size_t pages_per_cache; +} slab_type_t; + +struct mem_allocator; +typedef struct mem_allocator mem_allocator_t; + +typedef void* (*page_alloc_fun_t)(const size_t bytes); +typedef void (*page_free_fun_t)(const void* ptr); + +mem_allocator_t* create_slab_allocator(const slab_type_t *types, page_alloc_fun_t af, page_free_fun_t ff); +void destroy_slab_allocator(mem_allocator_t*); + +void* slab_alloc(mem_allocator_t* a, const size_t sz); +void slab_free(mem_allocator_t* a, const void* ptr); + +/* vim: set ts=4 sw=4 tw=0 noet :*/ |