Expand description
Centralized memory management with pressure handling.
When you need to control total memory usage across the database (not just
individual allocations), this is what you use. The BufferManager tracks
all allocations, monitors memory pressure, and can trigger spilling when
you’re running low.
§Architecture
┌────────────────────────────────────────────────────────────┐
│ BufferManager │
│ ┌──────────────┬──────────────┬──────────────┬──────────┐ │
│ │ GraphStorage │ IndexBuffers │ Execution │ Spill │ │
│ │ │ │ Buffers │ Staging │ │
│ └──────────────┴──────────────┴──────────────┴──────────┘ │
│ │ │
│ Pressure Thresholds: │ │
│ < 70% Normal │ │
│ 70-85% Moderate (evict cold) │
│ 85-95% High (aggressive evict/spill) │
│ > 95% Critical (block allocations) │
└────────────────────────────────────────────────────────────┘§Usage
ⓘ
use grafeo_common::memory::buffer::{BufferManager, MemoryRegion};
// Create with default config (75% of system RAM)
let manager = BufferManager::with_defaults();
// Or with specific budget
let manager = BufferManager::with_budget(1024 * 1024 * 100); // 100MB
// Allocate memory
if let Some(grant) = manager.try_allocate(1024, MemoryRegion::ExecutionBuffers) {
// Use the memory...
// Memory is automatically released when grant is dropped
}
// Check pressure level
let level = manager.pressure_level();
if level.should_spill() {
// Trigger spilling for spillable operators
}Modules§
- priorities
- Standard priority levels for common consumer types.
Structs§
- Buffer
Manager - The central unified buffer manager.
- Buffer
Manager Config - Configuration for the buffer manager.
- Buffer
Stats - Statistics about buffer manager state.
- Composite
Grant - A collection of memory grants that can be managed together.
- Consumer
Stats - Statistics about a memory consumer.
- Memory
Grant - RAII wrapper for memory allocations.
Enums§
- Memory
Region - Memory region identifiers for budget partitioning.
- Pressure
Level - Memory pressure level thresholds.
- Spill
Error - Error type for spilling operations.
Traits§
- Grant
Releaser - Trait for releasing memory grants.
- Memory
Consumer - Trait for subsystems that consume managed memory.