Skip to main content

Module memory_pools

Module memory_pools 

Source
Expand description

Budget shares and the one shared accounting pool — ADR 0073 §2 made executable.

The budget resolved at boot (memory_budget, ADR 0073 §1) is divided into named shares by a single allocation policy. The big memory consumers pre-size their structures from those shares and report live usage into one shared accounting pool.

Per-subsystem caps without shared accounting are explicitly rejected by the ADR: each subsystem stays individually “within limits” while the sum kills the process (OOM by summation). One pool, one total.

The invariant that makes the pool meaningful is

Σ(shares) ≤ budget

It holds by construction: every share is (budget / 10_000) * basis_points and the policy’s basis points sum to at most 10_000. Boot asserts both halves of that statement rather than trusting the arithmetic.

What this module is not: it does not enforce admission. A pool over its share is visible in red.stats and nothing more — enforcement is the next slice (ADR 0073 §4). Reporting is therefore free of policy: a plain relaxed atomic per pool, no allocation, no lock.

Structs§

BudgetSharePolicy
The single allocation policy: named fractions per pool, profile-adjustable.
BudgetShares
The resolved per-pool shares of one process budget.
MemoryAccounting
The one shared accounting pool: fixed shares, live usage.
MemoryEnforcementSnapshot
Process-level enforcement counters surfaced by red.stats.
PoolUsage
One pool’s row in the shared accounting.

Enums§

MemoryPool
The big memory consumers that receive a slice of the budget.

Constants§

BASIS_POINTS_PER_WHOLE
Denominator of the policy fractions. Shares are expressed in basis points (parts per ten thousand) so the whole policy is integer arithmetic — no float rounding standing between the budget and the invariant.
MEMORY_POOLS
Every pool, in the order red.stats reports them.
MEMORY_POOL_COUNT
Number of pools. Arrays are indexed by MemoryPool::index.
PAGE_CACHE_PAGE_SIZE_BYTES
Fixed page size the page-cache share is divided by to obtain a slot count. Pages are fixed size → slots are fixed size → the arena is preallocated.