1/* @title: Slab allocator */
2#pragma once
3#include <compiler/core.h>
4#include <linker/symbols.h>
5#include <stdbool.h>
6#include <stddef.h>
7#include <structures/list.h>
8
9struct slab_domain;
10
11struct slab_elcm_candidate {
12 size_t pages;
13 size_t bitmap_size_bytes;
14 size_t obj_count;
15};
16
17/* provides the ability for different subsystems to be able to make a constant
18 * slab size so frequently allocated objects can waste a little less memory */
19struct slab_size_constant {
20 const char *name;
21 size_t size;
22 size_t align;
23 struct list_node list;
24 struct {
25 struct slab_elcm_candidate cand;
26 } internal;
27};
28
29#define SLAB_SIZE_REGISTER(n, s, a) \
30 LINKER_SECTION_OBJECT(struct slab_size_constant, slab_sizes) \
31 slab_size_constant_##n = { \
32 .name = #n, \
33 .size = s, \
34 .align = a, \
35 .list = LIST_NODE_INIT(slab_size_constant_##n.list), \
36 .internal = {{0}}, \
37 }
38
39/* convenience wrapper */
40#define SLAB_SIZE_REGISTER_FOR_STRUCT(sname, al) \
41 SLAB_SIZE_REGISTER(sname, sizeof(struct sname), al)
42
43#define SLAB_OBJ_ALIGN_DEFAULT 8u
44#define SLAB_FREE_POISON_BYTE 0x67
45#define SLAB_ALLOC_NONZERO_POISON_BYTE 0x42
46
47void slab_allocator_init(void);
48void slab_domain_init(void);
49void slab_domains_print(void);
50void slab_domain_init_late(void);
51
52LINKER_SECTION_EXTERN(struct slab_size_constant, slab_sizes);
53
54bool slab_domain_busy(struct slab_domain *domain);
55