Hierarchical Memory Architecture
Memory-Centric Residency, Hugepages and Locality Design for LLM Inference
01 Abstract
Large language models place heavy pressure on memory capacity and bandwidth; in low-batch decode and CPU-centric deployments, data movement often dominates compute. Apolynux investigates a six-tier hierarchical memory architecture — spanning CPU caches, local RAM, pinned RAM, remote peer RAM, local NVMe, and archival storage — coordinated by an explicit residency manager using NUMA-local placement, HugeTLB evaluation, and controlled memory locking.
02 Problem Statement
Treating host memory as a flat, uniform pool ignores TLB miss overhead, NUMA remote-access penalties, kernel page-reclaim stalls, and page-fault jitter. Simply calling mmap() on a large weight file does not eliminate storage I/O or major page faults; without explicit residency management, critical layers get evicted under memory pressure.
03 Background & Foundations
Database buffer managers and high-performance Linux systems rely on HugeTLB (2 MiB / 1 GiB pages), NUMA memory policies (mbind/set_mempolicy), mlock, and explicit buffer residency tables to keep hot working sets resident and predictable. Apolynux is prototyping these controls specifically for dense trunks, KV caches, and routed MoE expert slabs.
04 Existing Architectural Limitations
- Default 4 KiB pages trigger heavy TLB misses when streaming gigabytes of model weights.
- Naive mmap relies on kernel heuristics that can silently page out hot weights during OS memory pressure.
- Cross-socket NUMA memory accesses silently reduce effective memory bandwidth and inflate decode latency.
- Uncontrolled memory fragmentation degrades long-running KV-cache allocation.
05 Proposed Apolynx Architecture
A six-tier memory hierarchy governed by a Residency Manager tracking per-component tier, NUMA node, access frequency, pin count, and transition states (HOT, WARM, COLD, LOADING, EVICTING).
Tier 0: CPU Caches (L1/L2/L3)
Router metadata, quantisation scales, and compact active working sets.
Tier 1 & 2: Local RAM & Pinned RAM
Active model weights, dense trunk, hot experts, and reclaim-immune pinned slabs via mlock/HugeTLB.
Tier 3: Remote Peer RAM
Shared model components and warm experts accessible across peer cluster nodes via RDMA.
Tier 4 & 5: Local NVMe & Remote Storage
Cold MoE experts on striped NVMe SSDs and archival model repositories.
06 Technical Design
Each model weight block, expert slab, or KV pool is registered as a memory_component_t tracked by the Memory Residency Manager. Transitions between HOT, WARM, COLD, LOADING, and EVICTING are explicitly orchestrated rather than left to opaque OS page faults. Both 2 MiB and 1 GiB HugeTLB reservations are evaluated against transparent hugepages (THP) to balance TLB savings against reservation overhead and fragmentation.
07 Execution Workflow
- 1. Registration: Model loader registers dense layers, experts, and KV pools with size, NUMA preference, and priority.
- 2. Tier Placement: Dense trunk and high-frequency components are allocated on NUMA-local hugepages and pinned.
- 3. Access Accounting: Runtime updates lightweight access_frequency and last_access_time counters.
- 4. Promotion / Demotion: Residency policy promotes rising experts via async I/O and transitions stale slabs to EVICTING.
- 5. Telemetry Audit: Continuous tracking of TLB misses, major/minor page faults, RSS, and remote NUMA traffic.
08 Algorithms, Interfaces & Specification
typedef struct {
uint32_t component_id;
uint64_t size_bytes;
uint32_t residency_tier; /* TIER_CACHE .. TIER_REMOTE_STORAGE */
uint32_t numa_node;
uint64_t access_frequency;
uint64_t last_access_time;
uint32_t pin_count;
uint32_t priority;
} memory_component_t;
/* Residency states: HOT | WARM | COLD | LOADING | EVICTING */
09 Implementation Considerations
- Do not assume mmap alone eliminates storage I/O or page faults; combine with explicit residency verification and async pre-loading.
- Excessive mlock pinning can starve OS page cache and kernel subsystems; reserve pinned budgets strictly.
- 1 GiB hugepages must typically be reserved at boot time and require careful NUMA-node balancing.
10 Performance Evaluation Methodology
Profile effective memory bandwidth, dTLB/iTLB load misses (perf stat), major and minor page faults, NUMA remote-access ratios, page migrations, memory-copy volume, and RSS under sustained multi-turn load.
11 Limitations & Scope Boundaries
- Experimental Prototype stage: hugepage and mlock experiments are active on commodity CPU nodes, with full residency automation in progress.
- Benefits of 2 MiB / 1 GiB hugepages depend heavily on actual stride patterns and available contiguous host RAM.
12 Open Research Questions & Challenges
- What optimal ratio of pinned RAM versus elastic warm cache maximises token throughput on 16–32 GB commodity nodes?
- How can residency transitions avoid inducing memory compaction stalls during long-running inference?
13 Future Directions
- Tight integration with Predictive MoE Expert Streaming (WP 07) and Linux Kernel Optimisation (WP 10).
- Automatic NUMA topology introspection and zero-config tier budgeting.
14 Primary Technical References
- Linux Kernel HugeTLB Pages Documentation — kernel.org — Reservation, mmap(MAP_HUGETLB), and hugetlbfs behaviour.
- Linux NUMA Memory Policy Documentation — kernel.org — mbind, set_mempolicy, and cross-socket bandwidth implications.
- Kwon et al. (SOSP 2023) — PagedAttention — Block-level memory management for LLM KV caches.
Research Status: Experimental Prototype • Scientific Integrity Disclosure
This research programme explicitly separates established computer science principles, existing open-source technologies, Apolynux architectural proposals, experimental implementations, and independently validated results. Apolynux does not claim to have invented OpenFlow, lock-free algorithms, RDMA, hugepages, or Mixture-of-Experts. Our research contribution is the proposed integration of these disciplines into a unified programmable inference architecture, evaluated strictly through repeatable empirical measurement.