MOS Source Code
Loading...
Searching...
No Matches
slab.c File Reference
#include "mos/mm/slab.h"
#include "mos/filesystem/sysfs/sysfs.h"
#include "mos/misc/setup.h"
#include "mos/mm/mm.h"
#include "mos/syslog/printk.h"
#include <mos/lib/structures/list.h>
#include <mos/lib/sync/spinlock.h>
#include <mos/mos_global.h>
#include <mos_stdlib.h>
#include <mos_string.h>
+ Include dependency graph for slab.c:

Go to the source code of this file.

Classes

struct  slab_header_t
 
struct  slab_metadata_t
 

Functions

static slab_tslab_for (size_t size)
 
static ptr_t slab_impl_new_page (size_t n)
 
static void slab_impl_free_page (ptr_t page, size_t n)
 
static void slab_init_one (slab_t *slab, const char *name, size_t size)
 
static void slab_allocate_mem (slab_t *slab)
 
static void slab_init (void)
 
 MOS_INIT (POST_MM, slab_init)
 
static void kmemcache_free (slab_t *slab, const void *addr)
 
voidslab_alloc (size_t size)
 Allocate a block of memory from the slab allocator.
 
voidslab_calloc (size_t nmemb, size_t size)
 Allocate a block of memory from the slab allocator and zero it.
 
voidslab_realloc (void *oldptr, size_t new_size)
 Reallocate a block of memory from the slab allocator.
 
void slab_free (const void *ptr)
 Free a block of memory from the slab allocator.
 
slab_tkmemcache_create (const char *name, size_t ent_size)
 
voidkmemcache_alloc (slab_t *slab)
 
static bool slab_sysfs_slabinfo (sysfs_file_t *f)
 
 MOS_INIT (SYSFS, slab_sysfs_init)
 

Variables

struct { 
 
   size_t   size 
 
   const char *   name 
 
BUILTIN_SLAB_SIZES [] 
 
static slab_t slab_slab = { 0 }
 
static slab_t slabs [MOS_ARRAY_SIZE(BUILTIN_SLAB_SIZES)] = { 0 }
 
static list_head slabs_list = LIST_HEAD_INIT(slabs_list)
 

Function Documentation

◆ slab_for()

static slab_t * slab_for ( size_t size)
inlinestatic

Definition at line 46 of file slab.c.

Referenced by slab_alloc().

◆ slab_impl_new_page()

static ptr_t slab_impl_new_page ( size_t n)
static

Definition at line 57 of file slab.c.

Referenced by slab_alloc(), and slab_allocate_mem().

+ Here is the call graph for this function:

◆ slab_impl_free_page()

static void slab_impl_free_page ( ptr_t page,
size_t n )
static

Definition at line 64 of file slab.c.

Referenced by slab_free().

+ Here is the call graph for this function:

◆ slab_init_one()

static void slab_init_one ( slab_t * slab,
const char * name,
size_t size )
static

Definition at line 70 of file slab.c.

Referenced by kmemcache_create(), and slab_init().

+ Here is the call graph for this function:

◆ slab_allocate_mem()

static void slab_allocate_mem ( slab_t * slab)
static

Definition at line 83 of file slab.c.

Referenced by kmemcache_alloc(), kmemcache_create(), and slab_init().

+ Here is the call graph for this function:

◆ slab_init()

static void slab_init ( void )
static

Definition at line 112 of file slab.c.

+ Here is the call graph for this function:

◆ MOS_INIT() [1/2]

MOS_INIT ( POST_MM ,
slab_init  )

◆ kmemcache_free()

static void kmemcache_free ( slab_t * slab,
const void * addr )
static

Definition at line 252 of file slab.c.

Referenced by slab_free(), and slab_realloc().

◆ slab_alloc()

void * slab_alloc ( size_t size)

Allocate a block of memory from the slab allocator.

Parameters
size
Returns
void*

Definition at line 130 of file slab.c.

Referenced by operator new(), operator new[](), slab_calloc(), and slab_realloc().

+ Here is the call graph for this function:

◆ slab_calloc()

void * slab_calloc ( size_t nmemb,
size_t size )

Allocate a block of memory from the slab allocator and zero it.

Parameters
nmemb
size
Returns
void*

Definition at line 148 of file slab.c.

+ Here is the call graph for this function:

◆ slab_realloc()

void * slab_realloc ( void * addr,
size_t size )

Reallocate a block of memory from the slab allocator.

Parameters
addr
size
Returns
void*

Definition at line 158 of file slab.c.

+ Here is the call graph for this function:

◆ slab_free()

void slab_free ( const void * addr)

Free a block of memory from the slab allocator.

Parameters
addr

Definition at line 200 of file slab.c.

Referenced by slab_realloc().

+ Here is the call graph for this function:

◆ kmemcache_create()

slab_t * kmemcache_create ( const char * name,
size_t ent_size )

Definition at line 219 of file slab.c.

Referenced by setup_xsave_slab().

+ Here is the call graph for this function:

◆ kmemcache_alloc()

void * kmemcache_alloc ( slab_t * slab)

Definition at line 227 of file slab.c.

Referenced by kmemcache_create(), and slab_alloc().

+ Here is the call graph for this function:

◆ slab_sysfs_slabinfo()

static bool slab_sysfs_slabinfo ( sysfs_file_t * f)
static

Definition at line 270 of file slab.c.

Referenced by MOS_INIT().

+ Here is the call graph for this function:

◆ MOS_INIT() [2/2]

MOS_INIT ( SYSFS ,
slab_sysfs_init  )

Definition at line 280 of file slab.c.

+ Here is the call graph for this function:

Variable Documentation

◆ size

size_t size

Definition at line 30 of file slab.c.

Referenced by _null_read(), _null_write(), acpi_find_rsdp(), bitmap_create(), check_block_(), console_io_read(), console_io_write(), console_write(), console_write_color(), decode_callback_field(), decode_pointer_field(), decode_static_field(), dentry_path(), dmabuf_share(), dmabuf_share(), dmabuf_unshare(), dmabuf_unshare(), do_print_vmflags(), do_roundtrips(), elf_read_file(), encode_array(), fdt_add_mem_rsv(), fdt_add_reservemap_entry(), fdt_appendprop_addrrange(), fdt_get_mem_rsv(), format_size(), free_with_check(), initrd_read(), io_get_name(), ipc_client_io_read(), ipc_client_io_write(), ipc_client_read(), ipc_client_write(), ipc_msg_create(), ipc_read_as_msg(), ipc_read_msg(), ipc_server_io_read(), ipc_server_io_write(), ipc_server_read(), ipc_server_write(), ipc_write_as_msg(), LLVMFuzzerTestOneInput(), main(), malloc_with_check(), mmap_anonymous(), mmap_file(), mmstat_dec(), mmstat_inc(), MOS_STATIC_ASSERT(), MOS_STATIC_ASSERT(), MOS_STATIC_ASSERT(), munmap(), of_read_number(), operator new(), operator new[](), dt_reg::iterator::operator*(), pb_dec_bytes(), pb_dec_fixed_length_bytes(), pb_dec_string(), pb_enc_string(), pb_encode_string(), pb_encode_submessage(), pb_get_encoded_size(), pb_make_string_substream(), pipe_read(), pipe_write(), pipeio_io_read(), pipeio_io_write(), print_property_value(), read_raw_value(), realloc_with_check(), ring_buffer_pop_back(), ring_buffer_pop_front(), ring_buffer_pos_pop_back(), ring_buffer_pos_pop_front(), ring_buffer_pos_push_back(), ring_buffer_pos_push_front(), ring_buffer_push_back(), ring_buffer_push_front(), round_blocksize(), rpc_arg_next(), rpc_arg_pb(), rpc_arg_sized_next(), rpc_call_arg(), rpc_write_result(), sbi_console_write(), simple_page_write_begin(), simple_page_write_end(), slab_alloc(), slab_calloc(), slab_for(), slab_init(), slab_init_one(), snprintf(), stack_grow(), stack_init(), stack_pop(), stack_push(), syscall_dmabuf_unshare(), syscall_io_read(), syscall_io_write(), syscall_mmap_anonymous(), syscall_mmap_file(), syscall_munmap(), syscall_vm_protect(), sysfs_fops_read(), sysfs_fops_write(), vfs_generic_read(), vfs_generic_write(), vfs_getcwd(), vfs_io_ops_getname(), vfs_ipc_file_read(), vfs_ipc_file_write(), vfs_read_pagecache(), vfs_readlinkat(), vfs_simple_write_begin(), vm_protect(), vsnprintf(), vsnprintf_do_pointer_kernel(), and x86_cpu_setup_xsave_area().

◆ name

const char* name

Definition at line 31 of file slab.c.

Referenced by console_get(), cpio_i_iterate_dir(), create_thread(), dentry_create(), dentry_get_from_parent(), dentry_lookup_child(), dirter_add(), dt_property::dt_property(), dump_fdt_node(), fdt_add_property_(), fdt_add_subnode(), fdt_add_subnode_namelen(), fdt_appendprop(), fdt_appendprop_addrrange(), fdt_appendprop_cell(), fdt_appendprop_u32(), fdt_appendprop_u64(), fdt_begin_node(), fdt_cells(), fdt_delprop(), fdt_get_alias(), fdt_get_alias_namelen(), fdt_get_path(), fdt_get_property(), fdt_get_property_namelen(), fdt_get_property_namelen_(), fdt_get_property_w(), fdt_getprop(), fdt_getprop_by_offset(), fdt_getprop_namelen(), fdt_getprop_namelen_w(), fdt_getprop_w(), fdt_nop_property(), fdt_property(), fdt_property_cell(), fdt_property_placeholder(), fdt_property_u32(), fdt_property_u64(), fdt_resize_property_(), fdt_set_name(), fdt_setprop(), fdt_setprop_cell(), fdt_setprop_inplace(), fdt_setprop_inplace_cell(), fdt_setprop_inplace_namelen_partial(), fdt_setprop_inplace_u32(), fdt_setprop_inplace_u64(), fdt_setprop_placeholder(), fdt_setprop_u32(), fdt_setprop_u64(), fdt_subnode_offset(), fdt_subnode_offset_namelen(), get_path_len(), dt_node::get_property(), dt_node::has_property(), ipc_connect(), ipc_connect_to_server(), ipc_create(), ipc_get_server(), ipc_server_create(), ipc_sysfs_lookup_ipc(), kmemcache_create(), kthread_create(), kthread_create_no_sched(), memfd_create(), memfd_create(), MOS_STATIC_ASSERT(), dt_node::operator[](), overlay_apply_node(), overlay_fixup_one_phandle(), overlay_fixup_phandle(), overlay_phandle_add_offset(), overlay_symbol_update(), overlay_update_local_node_references(), process_allocate(), process_new(), riscv64_trap_handler(), slab_init(), slab_init_one(), start_thread(), syscall_create_thread(), syscall_ipc_connect(), syscall_ipc_create(), syscall_memfd_create(), syscall_thread_setname(), thread_new(), vfs_find_filesystem(), x86_cpu_setup_xsave_area(), and x86_handle_exception().

◆ [struct]

const struct { ... } BUILTIN_SLAB_SIZES[]
Initial value:
= {
{ 4, "builtin-4" }, { 8, "builtin-8" }, { 16, "builtin-16" }, { 24, "builtin-24" },
{ 32, "builtin-32" }, { 48, "builtin-48" }, { 64, "builtin-64" }, { 96, "builtin-96" },
{ 128, "builtin-128" }, { 256, "builtin-256" }, { 384, "builtin-384" }, { 512, "builtin-512" },
{ 1024, "builtin-1024" },
}

Referenced by slab_init().

◆ slab_slab

slab_t slab_slab = { 0 }
static

Definition at line 41 of file slab.c.

Referenced by kmemcache_create(), and slab_init().

◆ slabs

slab_t slabs[MOS_ARRAY_SIZE(BUILTIN_SLAB_SIZES)] = { 0 }
static

Definition at line 43 of file slab.c.

Referenced by slab_for(), and slab_init().

◆ slabs_list

list_head slabs_list = LIST_HEAD_INIT(slabs_list)
static

Definition at line 44 of file slab.c.

Referenced by slab_init_one(), and slab_sysfs_slabinfo().