ZXFoundation™ 26h2
Loading...
Searching...
No Matches
kmalloc.cxxm File Reference

General-purpose kernel memory allocator — kmalloc / kfree. More...

import std;
import zxfoundation.base.config;
import zxfoundation.base.types;
import zxfoundation.sys.syschk.core;
import lib.error;
import zxfoundation.memory.slub.types;
import zxfoundation.memory.slub;
Include dependency graph for kmalloc.cxxm:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

no_export constexpr auto zxfoundation::memory::kmalloc::detail::bucket_for (u64 size) noexcept -> u32
 Return the bucket index for a requested size in O(1) time.
symalias kfree (void *ptr) noexcept -> void
auto zxfoundation::memory::kmalloc::kfree (void *ptr) noexcept -> void
 Free a pointer previously returned by kmalloc().
template<typename T>
auto zxfoundation::memory::kmalloc::kfree_t (T *ptr) noexcept -> void
 Typed kfree: calls T::~T() then frees the slab slot.
symalias kmalloc (u64 size) noexcept -> void *
auto zxfoundation::memory::kmalloc::kmalloc (u64 size) noexcept -> void *
 Allocate at least size bytes of kernel memory.
auto zxfoundation::memory::kmalloc::kmalloc_bucket (u64 size) noexcept -> u32
 Return the bucket index for a size, or KMALLOC_NUM_SIZES if too large.
auto zxfoundation::memory::kmalloc::kmalloc_bucket_size (u32 idx) noexcept -> u64
 Return the size of the Nth bucket, or 0 if out of range.
auto zxfoundation::memory::kmalloc::kmalloc_cache (u32 idx) noexcept -> slub::kmem_cache_ref_active
 Return the kmem_cache for the Nth bucket, or nullptr.
auto zxfoundation::memory::kmalloc::kmalloc_init () noexcept -> void
 Create all size-class caches.
template<typename T>
auto zxfoundation::memory::kmalloc::kmalloc_t () noexcept -> T *
 Typed kmalloc: allocate sizeof(T), aligned to alignof(T).

Variables

no_export std::array< slub::kmem_cache_ref_active, KMALLOC_NUM_SIZESzxfoundation::memory::kmalloc::detail::g_caches {}
no_export bool zxfoundation::memory::kmalloc::detail::g_initialized {false}
no_export constexpr const char * zxfoundation::memory::kmalloc::detail::g_names [KMALLOC_NUM_SIZES]
 Names for each size-class cache (diagnostic use only).
no_export constexpr u64 zxfoundation::memory::kmalloc::detail::g_sizes [KMALLOC_NUM_SIZES]
 Size of each bucket (powers of two, starting at 8).
no_export constexpr u64 zxfoundation::memory::kmalloc::detail::KMALLOC_MAX_SIZE = 32768ULL
 Maximum single-allocation size via kmalloc.
no_export constexpr u32 zxfoundation::memory::kmalloc::detail::KMALLOC_NUM_SIZES = 13U
 Number of size-class caches.

Detailed Description

General-purpose kernel memory allocator — kmalloc / kfree.

SPDX-License-Identifier: Apache-2.0

Function Documentation

◆ kmalloc()

auto zxfoundation::memory::kmalloc::kmalloc ( u64 size) ->void *
nodiscardexportnoexcept

Allocate at least size bytes of kernel memory.

Parameters
[in]sizeRequested byte count. Must be > 0 and <= KMALLOC_MAX_SIZE.

Variable Documentation

◆ g_names

no_export constexpr const char* zxfoundation::memory::kmalloc::detail::g_names[KMALLOC_NUM_SIZES]
constexpr
Initial value:
{
"kmalloc-8", "kmalloc-16", "kmalloc-32",
"kmalloc-64", "kmalloc-128", "kmalloc-256",
"kmalloc-512", "kmalloc-1024", "kmalloc-2048",
"kmalloc-4096", "kmalloc-8192", "kmalloc-16384",
"kmalloc-32768",
}

Names for each size-class cache (diagnostic use only).

◆ g_sizes

no_export constexpr u64 zxfoundation::memory::kmalloc::detail::g_sizes[KMALLOC_NUM_SIZES]
constexpr
Initial value:
{
8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768
}

Size of each bucket (powers of two, starting at 8).