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