Skip to content

linux/Documentation/core-api/memory-allocation.rst

Imported from _research/manual-study-linux/file-notes/linux__Documentation__core-api__memory-allocation.rst.md.

File Notes: Documentation/core-api/memory-allocation.rst

Status: reviewed.

Purpose

Documents Linux kernel allocation APIs, GFP flags, context constraints, slab cache usage, and freeing rules.

Key Points

Linux exposes different APIs for allocation shape: kmalloc and kmem_cache_alloc for small chunks, vmalloc for large virtually contiguous areas, and alloc_pages for page allocator requests. GFP flags express allocation constraints, including whether reclaim/sleeping is allowed.

For many identical objects, the slab cache allocator requires kmem_cache_create() or kmem_cache_create_usercopy() before kmem_cache_alloc(). Caches created this way should be destroyed only after all allocated objects are freed.

Rust Translation Guidance

Expose allocator APIs by allocation semantics and context. A Rust kernel should not let atomic-context code accidentally use a sleeping allocator. Slab cache types should carry object type, alignment, accounting, and usercopy metadata.

AI-Native Systems Guidance

Agent memory should distinguish ordinary heap allocation, fixed object caches, large virtual buffers, and page-like chunks. Allocation policies should be tied to whether the runtime may block, reclaim, or account to a user/session.

Evidence

  • Allocation API families are summarized at Documentation/core-api/memory-allocation.rst:7-12.
  • GFP flags and common context rules are described at Documentation/core-api/memory-allocation.rst:14-59.
  • Slab cache creation/allocation/freeing rules are at Documentation/core-api/memory-allocation.rst:169-188.