Memory Arenas
include/mem/arena.h View source View on GitHubThis subsystem allows the kernel to provide generic memory arenas that explicitly declare their capabilities and accept generic parameters and have extensible extra functions, for whatever purposes they desire.
Broadly, everything (or almost everything) is built with substantial room for extensibility, which allows for very different arenas that all funnel through this API, which exists to enforce safety and provide a unified substrate.
Structs
Section titled “Structs”arena_params
Section titled “arena_params” struct arena_params (3 fields) source
These are generally passed into the arena allocation creation as a generic way of giving parameters. Notably NOT arena_attributes, as these are merely the param words.
Also usable in arena_alloc_special in substitution of the size parameter, which is relevant to some allocators
void *ptr struct alloc_params alloc_params uint64_t params[4] arena_attributes
Section titled “arena_attributes” struct arena_attributes (2 fields) source
enum arena_flags flags struct arena_params params For the underlying arena, to describe whatever
arena_result
Section titled “arena_result” struct arena_result (2 fields) source
arena_err
Section titled “arena_err” enum arena_err (2 variants) source
Errors 128+ can be used by any provider
ARENA_ERR_BUDGET = ERR_DELTA_START ARENA_ERR_ALLOC_INVALID arena_flags
Section titled “arena_flags” enum arena_flags : uint64_t (7 variants) source
arena_flags: 64 bit bitflags
These flags denote the subset of globally recognized arena capabilities
Upper 32 bits are available for whatever needs it in the arena allocator internally
┌─────────────────────────────────────────────────────────────┐Bits │ 63--32 31..28 27..24 23..20 19..16 15..12 11..8 7..4 3..0 │Use │ AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA │ └─────────────────────────────────────────────────────────────┘A - Unused (available) * - Unused (unavailable)
ARENA_FLAG_TAGGED = 1 << 0 “tagging at the per-object granularity
ARENA_FLAG_TRACED = 1 << 1 “stack trace at the per-object granularity”
ARENA_FLAG_LOGGED = 1 << 2 Has a log site
ARENA_FLAG_LOCKED = 1 << 3 Use locks
ARENA_FLAG_REFCOUNTED = 1 << 4 A reference counter is used
ARENA_FLAG_RCU = 1 << 5 Protected by RCU and a defer callback
ARENA_FLAG_BUDGETED = 1 << 6 Have a budget
arena_strategy
Section titled “arena_strategy” enum arena_strategy (9 variants) source
There are 31 default arena policies (1-31, 0 is omitted to avoid uninitialized issues and bugs), and 32 marks the point where anything at or greater than this is a strategy registered by other code, not by default
ARENA_STRATEGY_SIMPLE = 1 simple, carve out from valloc
ARENA_STRATEGY_BUMP Bump allocator
ARENA_STRATEGY_FIXED All allocations are the same size, managed at initialization time
ARENA_STRATEGY_FREELIST ARENA_STRATEGY_SLAB this should ideally reuse slab allocator code, which might mean a little porting will need to happen.
Hopefully not much, since this is ideally just a wrapper around objects
ARENA_STRATEGY_MINI_SLAB DIFFERENT. Notably significantly lighter-weight than the full slab allocator
ARENA_STRATEGY_BUDDY ARENA_STRATEGY_RESERVE Reserve allocators are explicitly fed memory in, so they never perform an underlying allocation operation
ARENA_STRATEGY_MAX = 32 Functions
Section titled “Functions”arena_global_init
Section titled “arena_global_init”void arena_global_init(void) source Variables
Section titled “Variables”arena_err_facility
Section titled “arena_err_facility”extern struct err_facility arena_err_facility source