LF OS
Hobby operating system for amd64 with high ambitions
Loading...
Searching...
No Matches
slab.h
Go to the documentation of this file.
1#ifndef _SLAB_H_INCLUDED
2#define _SLAB_H_INCLUDED
3
4#include <stdint.h>
5
8
20
29void init_slab(ptr_t mem_start, ptr_t mem_end, size_t allocation_size);
30
38
45void slab_free(SlabHeader* slab, ptr_t memory);
46
53static inline size_t slab_overhead(const SlabHeader* slab) {
54 size_t overhead = sizeof(SlabHeader) + slab->bitmap_size;
55 return overhead + (slab->allocation_size - (overhead % slab->allocation_size));
56}
57
65static inline ptr_t slab_mem(const SlabHeader* slab, const SlabIndexType idx) {
66 return (idx * slab->allocation_size) + slab_overhead(slab) + (ptr_t)slab;
67}
68
76static inline SlabIndexType slab_index(const SlabHeader* slab, const ptr_t mem) {
77 return (mem - slab_overhead(slab) - (ptr_t)slab) / slab->allocation_size;
78}
79
80#endif
unsigned short uint16_t
Definition arch.h:8
uint64_t ptr_t
Definition arch.h:17
unsigned int uint32_t
Definition arch.h:11
static size_t slab_overhead(const SlabHeader *slab)
Definition slab.h:53
SlabIndexType num_entries
Number of objects in this region.
Definition slab.h:15
ptr_t slab_alloc(SlabHeader *slab)
Definition slab.c:22
uint16_t allocation_size
Size of objects in this region.
Definition slab.h:12
void slab_free(SlabHeader *slab, ptr_t memory)
Definition slab.c:37
static SlabIndexType slab_index(const SlabHeader *slab, const ptr_t mem)
Definition slab.h:76
static ptr_t slab_mem(const SlabHeader *slab, const SlabIndexType idx)
Definition slab.h:65
uint32_t bitmap_size
Size of the bitmap in bytes.
Definition slab.h:18
void init_slab(ptr_t mem_start, ptr_t mem_end, size_t allocation_size)
Definition slab.c:6
uint16_t SlabIndexType
Type for indexing objects in a Slab region.
Definition slab.h:7
Header of a Slab region.
Definition slab.h:10