pub trait MemoryConsumer: Send + Sync {
// Required methods
fn name(&self) -> &str;
fn memory_usage(&self) -> usize;
fn eviction_priority(&self) -> u8;
fn region(&self) -> MemoryRegion;
fn evict(&self, target_bytes: usize) -> usize;
fn current_tier(&self) -> StorageTier;
// Provided methods
fn can_spill(&self) -> bool { ... }
fn spill(&self, _target_bytes: usize) -> Result<usize, SpillError> { ... }
fn reload(&self) -> Result<(), SpillError> { ... }
}Expand description
Trait for subsystems that consume managed memory.
Memory consumers register with the buffer manager and participate in eviction when memory pressure is detected. Lower priority consumers are evicted first.
Required Methods§
Sourcefn memory_usage(&self) -> usize
fn memory_usage(&self) -> usize
Returns current memory usage in bytes.
Sourcefn eviction_priority(&self) -> u8
fn eviction_priority(&self) -> u8
Returns eviction priority (0 = lowest priority, evict first; 255 = highest, evict last).
Sourcefn region(&self) -> MemoryRegion
fn region(&self) -> MemoryRegion
Returns which memory region this consumer belongs to.
Sourcefn evict(&self, target_bytes: usize) -> usize
fn evict(&self, target_bytes: usize) -> usize
Attempts to evict/release memory to reach target usage.
Returns the number of bytes actually freed.
Sourcefn current_tier(&self) -> StorageTier
fn current_tier(&self) -> StorageTier
Reports the consumer’s current storage tier (Phase 8b introspection).
No default: tier cannot be inferred from memory_usage() alone
because a spillable consumer can be on disk with zero heap usage,
and crate::memory::buffer::BufferManager::reload_eligible only
reloads consumers reporting StorageTier::OnDisk. Implementors
that never spill should return StorageTier::InMemory when
memory_usage() > 0 and StorageTier::Uninitialized otherwise.
Used by crate::memory::buffer::BufferManager::snapshot_consumer_tiers
for observability and tests; not on any hot path.