Skip to main content

BufferManager

Struct BufferManager 

Source
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

Source

pub fn new(config: BufferManagerConfig) -> Arc<Self>

Creates a new buffer manager with the given configuration.

Source

pub fn with_defaults() -> Arc<Self>

Creates a buffer manager with default configuration.

Source

pub fn with_budget(budget: usize) -> Arc<Self>

Creates a buffer manager with a specific budget.

Source

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.

Source

pub fn pressure_level(&self) -> PressureLevel

Returns the current pressure level.

Source

pub fn stats(&self) -> BufferStats

Returns current buffer statistics.

Source

pub fn register_consumer(&self, consumer: Arc<dyn MemoryConsumer>)

Registers a memory consumer for eviction callbacks.

Source

pub fn unregister_consumer(&self, name: &str)

Unregisters a memory consumer by name.

Source

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.

Source

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.

Source

pub fn is_force_ram(&self, name: &str) -> bool

Returns true if a consumer is currently pinned via ForceRam.

Source

pub fn evict_to_target(&self, target_bytes: usize) -> usize

Forces eviction to reach the target usage.

Returns the number of bytes actually freed.

Source

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.

Source

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.

Source

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.

Source

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).

Source

pub fn config(&self) -> &BufferManagerConfig

Returns the configuration.

Source

pub fn budget(&self) -> usize

Returns the memory budget.

Source

pub fn allocated(&self) -> usize

Returns currently allocated bytes.

Source

pub fn available(&self) -> usize

Returns available bytes.

Source

pub fn shutdown(&self)

Shuts down the buffer manager.

Trait Implementations§

Source§

impl Drop for BufferManager

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl GrantReleaser for BufferManager

Source§

fn release(&self, size: usize, region: MemoryRegion)

Releases memory back to the manager.
Source§

fn try_allocate_raw(&self, size: usize, region: MemoryRegion) -> bool

Tries to allocate additional memory (for resize operations).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.