LF OS
Hobby operating system for amd64 with high ambitions
Loading...
Searching...
No Matches
slab.h File Reference

(29312b1 fbconsole, panic: render panic after framebuffer was given to userspace - without clearing screen contents)

#include <stdint.h>
+ Include dependency graph for slab.h:
+ This graph shows which files directly or indirectly include this file:

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)
 

Data Structure Documentation

◆ SlabHeader

struct SlabHeader

Header of a Slab region.

Definition at line 10 of file slab.h.

+ Collaboration diagram for 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 Documentation

◆ SlabIndexType

Type for indexing objects in a Slab region.

Definition at line 7 of file slab.h.

Function Documentation

◆ init_slab()

void init_slab ( ptr_t  mem_start,
ptr_t  mem_end,
size_t  allocation_size 
)

Initialize a new slab allocator at the given memory location. After initialization, you can use mem_start as pointer to SlabHeader for more operations.

Parameters
mem_startMemory address where the slab allocator region begins
mem_endMemory address where the slab allocator region ends
allocation_sizeSize of single objects in this allocator

Definition at line 6 of file slab.c.

References bitmap_size(), header, and memset().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ slab_alloc()

ptr_t slab_alloc ( SlabHeader slab)

Allocate object from slab allocator region.

Parameters
slabmem_start given to init_slab before
Returns
Address in memory with the allocated object, NULL if full

Definition at line 22 of file slab.c.

References bitmap_get(), bitmap_set(), SlabHeader::num_entries, panic_message(), and slab_mem().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ slab_free()

void slab_free ( SlabHeader slab,
ptr_t  memory 
)

Free object in slab allocator region.

Parameters
slabmem_start given to init_slab before
memoryAddress to mark as free

Definition at line 37 of file slab.c.

References bitmap_clear(), and slab_index().

+ Here is the call graph for this function:

◆ slab_index()

static SlabIndexType slab_index ( const SlabHeader slab,
const ptr_t  mem 
)
inlinestatic

Calculate index for a given memory address in a given allocator

Parameters
slabPointer to SlabHeader for calculation
memMemory address to calculate index
Returns
Index of the given memory address in the allocator

Definition at line 76 of file slab.h.

References SlabHeader::allocation_size, and slab_overhead().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ slab_mem()

static ptr_t slab_mem ( const SlabHeader slab,
const SlabIndexType  idx 
)
inlinestatic

Calculate memory address for a given allocator and index

Parameters
slabPointer to SlabHeader for calculation
idxIndex of the object in the allocator
Returns
Memory address of the object

Definition at line 65 of file slab.h.

References SlabHeader::allocation_size, and slab_overhead().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ slab_overhead()

static size_t slab_overhead ( const SlabHeader slab)
inlinestatic

Calculate the overhead of a given slab allocator.

Parameters
slabPointer to SlabHeader to calculate overhead.
Returns
Allocator overhead in bytes.

Definition at line 53 of file slab.h.

References SlabHeader::allocation_size, and SlabHeader::bitmap_size.

+ Here is the caller graph for this function: