33 { 4,
"builtin-4" }, { 8,
"builtin-8" }, { 16,
"builtin-16" }, { 24,
"builtin-24" },
34 { 32,
"builtin-32" }, { 48,
"builtin-48" }, { 64,
"builtin-64" }, { 96,
"builtin-96" },
35 { 128,
"builtin-128" }, { 256,
"builtin-256" }, { 384,
"builtin-384" }, { 512,
"builtin-512" },
36 { 1024,
"builtin-1024" },
89 mos_panic(
"slab: failed to allocate memory for slab");
97 slab_ptr->
slab = slab;
98 pr_dinfo2(slab,
"slab header is at %p", (
void *) slab_ptr);
102 const size_t max_n = available_size / slab->
ent_size - 1;
103 const size_t fact = slab->
ent_size /
sizeof(
void *);
105 for (
size_t i = 0; i < max_n; i++)
107 arr[i * fact] = &arr[(i + 1) * fact];
109 arr[max_n * fact] =
NULL;
114 pr_dinfo2(slab,
"initializing the slab allocator");
142 metadata->
pages = page_count;
169 metadata->
size = new_size;
239 pr_dcont(slab,
" -> %p", (
void *) alloc);
274 sysfs_printf(f,
"%15s, ent_size=%5zu, first_free=" PTR_FMT ", %5zu objects\n", slab->name, slab->ent_size, slab->first_free, slab->nobjs);
#define MOS_ASSERT_X(cond, msg,...)
MOSAPI void linked_list_init(list_node_t *head_node)
Initialise a circular double linked list.
#define LIST_HEAD_INIT(container)
MOSAPI void list_node_append(list_node_t *head, list_node_t *item)
#define list_foreach(t, v, h)
Iterate over a list.
#define list_node(element)
Get the ‘list_node’ of a list element. This is exactly the reverse of ‘list_entry’ above.
list_node_t list_head
A linked list head.
#define phyframe_va(frame)
#define mm_free_pages(frame, npages)
phyframe_t * mm_get_free_pages(size_t npages)
void mmstat_dec(mmstat_type_t type, size_t size)
Decrement the memory usage statistics.
void mmstat_inc(mmstat_type_t type, size_t size)
Increment the memory usage statistics.
#define MOS_ARRAY_SIZE(x)
#define ALIGN_UP_TO_PAGE(addr)
#define ALIGN_DOWN_TO_PAGE(addr)
#define is_aligned(ptr, alignment)
#define ALIGN_UP(addr, size)
#define mos_panic(fmt,...)
static void * memcpy(void *s1, const void *s2, size_t n)
static void * memset(void *s, int c, size_t n)
#define pr_dcont(feat, fmt,...)
#define pr_dinfo2(feat, fmt,...)
#define MOS_INIT(_comp, _fn)
static void slab_init(void)
void slab_free(const void *ptr)
Free a block of memory from the slab allocator.
static void slab_impl_free_page(ptr_t page, size_t n)
static slab_t slabs[MOS_ARRAY_SIZE(BUILTIN_SLAB_SIZES)]
slab_t * kmemcache_create(const char *name, size_t ent_size)
static bool slab_sysfs_slabinfo(sysfs_file_t *f)
static slab_t * slab_for(size_t size)
static void slab_init_one(slab_t *slab, const char *name, size_t size)
void * slab_alloc(size_t size)
Allocate a block of memory from the slab allocator.
static void slab_allocate_mem(slab_t *slab)
void * kmemcache_alloc(slab_t *slab)
static list_head slabs_list
static void kmemcache_free(slab_t *slab, const void *addr)
static const struct @26 BUILTIN_SLAB_SIZES[]
void * slab_realloc(void *oldptr, size_t new_size)
Reallocate a block of memory from the slab allocator.
static ptr_t slab_impl_new_page(size_t n)
void * slab_calloc(size_t nmemb, size_t size)
Allocate a block of memory from the slab allocator and zero it.
#define spinlock_acquire(lock)
#define spinlock_release(lock)
ssize_t sysfs_printf(sysfs_file_t *file, const char *fmt,...)
should_inline void sysfs_register_root_file(sysfs_item_t *item)
Register an entry in the sysfs root directory.
#define SYSFS_RO_ITEM(_name, _show_fn)