pub struct BufferManager { /* private fields */ }Expand description
The central unified buffer manager.
Manages memory allocation across all subsystems with pressure-aware eviction and optional spilling support.
Implementations§
Source§impl BufferManager
impl BufferManager
Sourcepub fn new(config: BufferManagerConfig) -> Arc<Self>
pub fn new(config: BufferManagerConfig) -> Arc<Self>
Creates a new buffer manager with the given configuration.
Sourcepub fn with_defaults() -> Arc<Self>
pub fn with_defaults() -> Arc<Self>
Creates a buffer manager with default configuration.
Sourcepub fn with_budget(budget: usize) -> Arc<Self>
pub fn with_budget(budget: usize) -> Arc<Self>
Creates a buffer manager with a specific budget.
Sourcepub fn try_allocate(
self: &Arc<Self>,
size: usize,
region: MemoryRegion,
) -> Option<MemoryGrant>
pub fn try_allocate( self: &Arc<Self>, size: usize, region: MemoryRegion, ) -> Option<MemoryGrant>
Attempts to allocate memory for the given region.
Returns None if allocation would exceed the hard limit after
eviction attempts.
Sourcepub fn pressure_level(&self) -> PressureLevel
pub fn pressure_level(&self) -> PressureLevel
Returns the current pressure level.
Sourcepub fn stats(&self) -> BufferStats
pub fn stats(&self) -> BufferStats
Returns current buffer statistics.
Sourcepub fn register_consumer(&self, consumer: Arc<dyn MemoryConsumer>)
pub fn register_consumer(&self, consumer: Arc<dyn MemoryConsumer>)
Registers a memory consumer for eviction callbacks.
Sourcepub fn unregister_consumer(&self, name: &str)
pub fn unregister_consumer(&self, name: &str)
Unregisters a memory consumer by name.
Sourcepub fn mark_force_ram(&self, name: &str)
pub fn mark_force_ram(&self, name: &str)
Pins a consumer to RAM via crate::storage::TierOverride::ForceRam.
After this call, no spill loop in the buffer manager will spill the consumer with the given name. Allocation pressure that would otherwise have spilled this consumer instead falls through to other consumers, or fails if no other spillable consumer can free enough.
Idempotent: calling twice with the same name is a no-op.
Sourcepub fn clear_force_ram(&self, name: &str)
pub fn clear_force_ram(&self, name: &str)
Removes the crate::storage::TierOverride::ForceRam pin from a
consumer (Phase 8g). After this call, the consumer participates in
spill again like any other.
Sourcepub fn is_force_ram(&self, name: &str) -> bool
pub fn is_force_ram(&self, name: &str) -> bool
Returns true if a consumer is currently pinned via ForceRam.
Sourcepub fn evict_to_target(&self, target_bytes: usize) -> usize
pub fn evict_to_target(&self, target_bytes: usize) -> usize
Forces eviction to reach the target usage.
Returns the number of bytes actually freed.
Sourcepub fn spill_all(&self) -> usize
pub fn spill_all(&self) -> usize
Spills all consumers that support it, regardless of memory pressure.
Used when TierOverride::ForceDisk is configured. Returns total bytes freed.
Consumers pinned via Self::mark_force_ram are skipped.
Sourcepub fn spill_consumer_by_name(&self, name: &str) -> usize
pub fn spill_consumer_by_name(&self, name: &str) -> usize
Spills all consumers whose MemoryConsumer::name equals name.
Used for targeted crate::storage::TierOverride::ForceDisk enforcement
at database open: each section type configured as ForceDisk triggers a
spill on its matching consumer only, leaving other consumers untouched.
Best-effort: a failure on one consumer does not stop the others. Returns total bytes freed across all matching consumers.
If name is pinned via Self::mark_force_ram, this call is a no-op
and returns 0. The pin is honored even on explicit-by-name spill
requests: ForceRam is a hard contract.
Sourcepub fn reload_eligible(&self, target_fraction: f64) -> usize
pub fn reload_eligible(&self, target_fraction: f64) -> usize
Reloads OnDisk consumers back into RAM, in priority order (highest
priority first), as long as projected usage stays below
target_fraction of the budget.
Phase 9a: closes the loop on the spill / reload lifecycle. Today consumers spill on memory pressure and stay OnDisk forever; this method gives users (or a future background thread) an explicit trigger to bring spilled state back into RAM after pressure drops.
The walk visits consumers whose
MemoryConsumer::current_tier is
super::tiered::StorageTier::OnDisk and calls
MemoryConsumer::reload on each. After each reload, if current
allocation exceeds target_fraction * budget, the loop stops and
leaves remaining consumers on disk. reload() errors are
logged-and-skipped: the operation is best-effort.
Returns the number of consumers successfully reloaded.
target_fraction is clamped to [0.0, 1.0]. A value of 0.7 means
“stop bringing things back when we’d hit 70% of the budget” —
matching the soft-limit threshold default.
Sourcepub fn snapshot_consumer_tiers(&self) -> Vec<(String, StorageTier)>
pub fn snapshot_consumer_tiers(&self) -> Vec<(String, StorageTier)>
Returns the current tier reported by each registered consumer that wraps a section.
Tier is sourced from MemoryConsumer::current_tier. Consumers whose
names don’t follow the "section:<TypeName>" convention are skipped
(e.g. CDC, overlay).
Sourcepub fn config(&self) -> &BufferManagerConfig
pub fn config(&self) -> &BufferManagerConfig
Returns the configuration.