LF OS
Hobby operating system for amd64 with high ambitions
|
#include <stdint.h>
Go to the source code of this file.
Data Structures | |
struct | SlabHeader |
Header of a Slab region. More... | |
Typedefs | |
typedef uint16_t | SlabIndexType |
Type for indexing objects in a Slab region. | |
Functions | |
void | init_slab (ptr_t mem_start, ptr_t mem_end, size_t allocation_size) |
ptr_t | slab_alloc (SlabHeader *slab) |
void | slab_free (SlabHeader *slab, ptr_t memory) |
static size_t | slab_overhead (const SlabHeader *slab) |
static ptr_t | slab_mem (const SlabHeader *slab, const SlabIndexType idx) |
static SlabIndexType | slab_index (const SlabHeader *slab, const ptr_t mem) |
struct SlabHeader |
Data Fields | ||
---|---|---|
uint16_t | allocation_size | Size of objects in this region. |
uint32_t | bitmap_size | Size of the bitmap in bytes. |
SlabIndexType | num_entries | Number of objects in this region. |
typedef uint16_t SlabIndexType |
Initialize a new slab allocator at the given memory location. After initialization, you can use mem_start as pointer to SlabHeader for more operations.
mem_start | Memory address where the slab allocator region begins |
mem_end | Memory address where the slab allocator region ends |
allocation_size | Size of single objects in this allocator |
Definition at line 6 of file slab.c.
References bitmap_size(), header, and memset().
ptr_t slab_alloc | ( | SlabHeader * | slab | ) |
Allocate object from slab allocator region.
slab | mem_start given to init_slab before |
Definition at line 22 of file slab.c.
References bitmap_get(), bitmap_set(), SlabHeader::num_entries, panic_message(), and slab_mem().
void slab_free | ( | SlabHeader * | slab, |
ptr_t | memory | ||
) |
Free object in slab allocator region.
slab | mem_start given to init_slab before |
memory | Address to mark as free |
Definition at line 37 of file slab.c.
References bitmap_clear(), and slab_index().
|
inlinestatic |
Calculate index for a given memory address in a given allocator
slab | Pointer to SlabHeader for calculation |
mem | Memory address to calculate index |
Definition at line 76 of file slab.h.
References SlabHeader::allocation_size, and slab_overhead().
|
inlinestatic |
Calculate memory address for a given allocator and index
slab | Pointer to SlabHeader for calculation |
idx | Index of the object in the allocator |
Definition at line 65 of file slab.h.
References SlabHeader::allocation_size, and slab_overhead().
|
inlinestatic |
Calculate the overhead of a given slab allocator.
slab | Pointer to SlabHeader to calculate overhead. |
Definition at line 53 of file slab.h.
References SlabHeader::allocation_size, and SlabHeader::bitmap_size.