ZXFoundation™ 26h2
Loading...
Searching...
No Matches
core.cxx File Reference

SLUB slab allocator — full SMP-aware implementation — implementation. More...

import std;
import zxfoundation.sys.syschk.core;
import arch.s390x.cpu.lowcore;
import zxfoundation.scoms.kobject.types;
import zxfoundation.scoms.kobject.base;
import zxfoundation.sync.qspinlock.core;
import zxfoundation.memory.slub.types;
import zxfoundation.base.config;
import zxfoundation.memory.pmm;
import zxfoundation.memory.pmm.types;
import zxfoundation.memory.hhdm;
import lib.error;
import zxfoundation.memory.objects;
import lib.align;
import zxfoundation.memory.numa;
import zxfoundation.sync.lockable;
import zxfoundation.memory.numa.types;
import zxfoundation.sync.rcu.core;
import arch.s390x.cpu.irq;
import zxfoundation.sync.rcu.types;
import arch.s390x.cpu.clock;
import arch.s390x.cpu.processor;
import zxfoundation.sched.context.core;
import zxfoundation.base.types;
Include dependency graph for core.cxx:

Functions

auto zxfoundation::memory::slub::detail::activate_slab (kmem_cache &cache, kmem_cache_cpu &cs, slab_header *sh) noexcept -> void
 Activate a slab: freeze it and set as the CPU's active slab.
auto zxfoundation::memory::slub::detail::alloc_new_slab (kmem_cache &cache, u8 preferred_node) noexcept -> slab_header *
 Allocate a new slab page from PMM and initialise it.
auto zxfoundation::memory::slub::detail::alloc_slow (kmem_cache &cache) noexcept -> void *
auto zxfoundation::memory::slub::detail::deactivate_cpu_slab (kmem_cache &cache, kmem_cache_cpu &cs) noexcept -> void
 Return a CPU-owned slab to its PMM-owner partial list. The owner-node lock serializes concurrent remote frees.
auto zxfoundation::memory::slub::detail::decode_fp (const kmem_cache &cache, void *obj, void *stored) noexcept -> void *
auto zxfoundation::memory::slub::detail::encode_fp (const kmem_cache &cache, void *obj, void *next) noexcept -> void *
auto zxfoundation::memory::slub::detail::first_object (const kmem_cache &cache, slab_header *sh) noexcept -> void *
 Compute the first object base address within a slab.
auto zxfoundation::memory::slub::detail::free_slab (kmem_cache &cache, slab_header *sh) noexcept -> void
 Free a slab page: immediately or via RCU depending on flags.
auto zxfoundation::memory::slub::detail::free_slab_rcu_cb (sync::rcu::rcu_head *head) noexcept -> void
 RCU callback: free a slab page to PMM after grace period.
auto zxfoundation::memory::slub::detail::free_slow (kmem_cache &cache, slab_header *sh, void *obj) noexcept -> void
auto zxfoundation::memory::slub::detail::get_fp (const kmem_cache &cache, void *obj) noexcept -> void *
 Read and decode the next-pointer from a free object.
auto zxfoundation::memory::slub::kmem_alloc (kmem_cache &cache) noexcept -> void *
 Allocate one object from the given cache.
auto zxfoundation::memory::slub::kmem_cache_count () noexcept -> u32
 Return the total number of registered caches.
auto zxfoundation::memory::slub::kmem_cache_create (const char *name, u32 object_size, u32 align, slub_flags flags) noexcept -> std::expected< kmem_cache_ref_active, lib::kernel_error >
 Create a new slab cache.
auto zxfoundation::memory::slub::kmem_cache_destroy (kmem_cache *cache) noexcept -> void
 Destroy a slab cache.
auto zxfoundation::memory::slub::kmem_cache_live_objects (const kmem_cache &cache) noexcept -> i64
 Return the number of live (allocated) objects in a cache.
auto zxfoundation::memory::slub::kmem_cache_shrink (kmem_cache *cache) noexcept -> u32
 Return empty node-partial slabs to PMM.
auto zxfoundation::memory::slub::kmem_free (kmem_cache &cache, void *obj) noexcept -> void
 Typed allocation helper — returns a pointer to T.
auto zxfoundation::memory::slub::kmem_free_raw (void *ptr) noexcept -> void
 Free a slab-allocated object without knowing its cache.
auto zxfoundation::memory::slub::kmem_get_cache (u32 idx) noexcept -> kmem_cache *
 Return a pointer to the Nth registered cache, or nullptr.
auto zxfoundation::memory::slub::detail::node_add_partial (kmem_cache &cache, slab_header *sh) noexcept -> void
 Add a slab to the node partial list (prepend).
auto zxfoundation::memory::slub::detail::node_remove_partial (kmem_cache &cache, slab_header *sh) noexcept -> void
 Remove a slab from the node partial list.
auto zxfoundation::memory::slub::detail::node_state (kmem_cache &cache, u8 node_id) noexcept -> kmem_cache_node &
auto zxfoundation::memory::slub::detail::set_fp (const kmem_cache &cache, void *obj, void *next) noexcept -> void
 Write the encoded next-pointer into a free object.
auto zxfoundation::memory::slub::detail::slab_of (const kmem_cache &cache, void *obj) noexcept -> slab_header *
 Recover the slab header for a cache-known allocation.
auto zxfoundation::memory::slub::slub_attach_authorities () noexcept -> void
 Attach memory_object authorities to all live kmem_caches.
auto zxfoundation::memory::slub::slub_init () noexcept -> void
 Initialise the SLUB allocator. Must be called before any kmem_cache_create(). Allocates the cache table from PMM (PMM must be initialized).

Variables

static u32 zxfoundation::memory::slub::detail::g_cache_count {0}
static sync::qspinlock::qspinlock zxfoundation::memory::slub::detail::g_cache_table_lock {}
static kmem_cachezxfoundation::memory::slub::detail::g_cache_table_ptr {nullptr}
 Dynamically allocated pool of kmem_cache objects.
static bool zxfoundation::memory::slub::detail::g_initialized {false}

Detailed Description

SLUB slab allocator — full SMP-aware implementation — implementation.

SPDX-License-Identifier: Apache-2.0

Function Documentation

◆ activate_slab()

auto zxfoundation::memory::slub::detail::activate_slab ( kmem_cache & cache,
kmem_cache_cpu & cs,
slab_header * sh )->void
inlinenoexcept

Activate a slab: freeze it and set as the CPU's active slab.

Precondition
preempt_disable + irq_save_disable in effect.

◆ alloc_new_slab()

auto zxfoundation::memory::slub::detail::alloc_new_slab ( kmem_cache & cache,
u8 preferred_node )->slab_header *
nodiscardnoexcept

Allocate a new slab page from PMM and initialise it.

Returns
Pointer to the initialised slab_header, or nullptr on OOM.

◆ kmem_alloc()

auto zxfoundation::memory::slub::kmem_alloc ( kmem_cache & cache) ->void *
nodiscardexportnoexcept

Allocate one object from the given cache.

Returns
Pointer to the allocated object (HHDM virtual address), or nullptr on OOM.

◆ kmem_cache_create()

auto zxfoundation::memory::slub::kmem_cache_create ( const char * name,
u32 object_size,
u32 align,
slub_flags flags )->std::expected< kmem_cache_ref_active, lib::kernel_error >
nodiscardexportnoexcept

Create a new slab cache.

Parameters
[in]nameASCII name for diagnostics.
[in]object_sizesizeof(T) for the object type.
[in]alignRequired alignment. 0 → use object_size alignment.
[in]flagsslub_flags bitmask.

◆ kmem_free()

auto zxfoundation::memory::slub::kmem_free ( kmem_cache & cache,
void * obj )->void
exportnoexcept

Typed allocation helper — returns a pointer to T.

Free one object back to its cache.

Template Parameters
TObject type. sizeof(T) must equal cache.object_size.

Free one object back to its cache.

Parameters
[in]cacheThe cache the object was allocated from.
[in]objPointer to the object to free.
[in]cacheThe cache the object was allocated from.
[in]objPointer to the object to free.

◆ node_add_partial()

auto zxfoundation::memory::slub::detail::node_add_partial ( kmem_cache & cache,
slab_header * sh )->void
inlinenoexcept

Add a slab to the node partial list (prepend).

Precondition
The slab owner's node lock is held.

◆ node_remove_partial()

auto zxfoundation::memory::slub::detail::node_remove_partial ( kmem_cache & cache,
slab_header * sh )->void
inlinenoexcept

Remove a slab from the node partial list.

Precondition
The slab owner's node lock is held.

◆ slub_init()

auto zxfoundation::memory::slub::slub_init ( ) ->void
exportnoexcept

Initialise the SLUB allocator. Must be called before any kmem_cache_create(). Allocates the cache table from PMM (PMM must be initialized).

Initialise the SLUB allocator.