Skip to main content

graphos_common/memory/buffer/
mod.rs

1//! Unified buffer manager for memory management.
2//!
3//! This module provides centralized memory management across all subsystems
4//! with pressure-aware allocation, eviction, and spilling support.
5//!
6//! # Architecture
7//!
8//! ```text
9//! ┌────────────────────────────────────────────────────────────┐
10//! │                    BufferManager                           │
11//! │  ┌──────────────┬──────────────┬──────────────┬──────────┐ │
12//! │  │ GraphStorage │ IndexBuffers │ Execution    │ Spill    │ │
13//! │  │              │              │ Buffers      │ Staging  │ │
14//! │  └──────────────┴──────────────┴──────────────┴──────────┘ │
15//! │                         │                                  │
16//! │  Pressure Thresholds:   │                                  │
17//! │  < 70%  Normal          │                                  │
18//! │  70-85% Moderate (evict cold)                              │
19//! │  85-95% High (aggressive evict/spill)                      │
20//! │  > 95%  Critical (block allocations)                       │
21//! └────────────────────────────────────────────────────────────┘
22//! ```
23//!
24//! # Usage
25//!
26//! ```ignore
27//! use graphos_common::memory::buffer::{BufferManager, MemoryRegion};
28//!
29//! // Create with default config (75% of system RAM)
30//! let manager = BufferManager::with_defaults();
31//!
32//! // Or with specific budget
33//! let manager = BufferManager::with_budget(1024 * 1024 * 100); // 100MB
34//!
35//! // Allocate memory
36//! if let Some(grant) = manager.try_allocate(1024, MemoryRegion::ExecutionBuffers) {
37//!     // Use the memory...
38//!     // Memory is automatically released when grant is dropped
39//! }
40//!
41//! // Check pressure level
42//! let level = manager.pressure_level();
43//! if level.should_spill() {
44//!     // Trigger spilling for spillable operators
45//! }
46//! ```
47
48mod consumer;
49mod grant;
50mod manager;
51mod region;
52mod stats;
53
54pub use consumer::{ConsumerStats, MemoryConsumer, SpillError, priorities};
55pub use grant::{CompositeGrant, GrantReleaser, MemoryGrant};
56pub use manager::{BufferManager, BufferManagerConfig};
57pub use region::MemoryRegion;
58pub use stats::{BufferStats, PressureLevel};