Skip to main content

Module memory_accounting

Module memory_accounting 

Source
Expand description

Samples every governed pool’s live usage into the shared accounting (ADR 0073 §2). Live usage reporting into the shared accounting pool — ADR 0073 §2.

Every governed pool already owns a counter for its own footprint: the page cache knows its resident slot count, the blob cache its bytes_in_use, the segments their memory_bytes atomics, the WAL queue its buffered bytes. This module is the seam that reads those counters and stores them into the one shared pool, so red.stats can show per-pool share_bytes / used_bytes against a single total.

Pull, not push. The alternative — every subsystem holding an Arc<MemoryAccounting> and updating it inline — would thread the pool into the page-cache hit path and the segment insert path, which is exactly the per-operation cost ADR 0073 §3 forbids. Instead the pools keep the atomics they already maintain and a reader samples them. A refresh is a handful of relaxed loads plus one read lock per segment; the read hot paths gain nothing at all.

Sizing and accounting only: a pool over its share shows up here and is not acted on. Admission enforcement is the next slice (ADR 0073 §4).