1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//! Resource guard module for preventing system overload.
//!
//! This module provides safeguards to prevent out-of-memory conditions
//! during large-scale operations.
//!
//! # Example
//!
//! ```
//! use ringkernel_core::resource::{ResourceGuard, MemoryEstimate};
//!
//! let guard = ResourceGuard::new();
//! let estimate = MemoryEstimate::new()
//! .with_primary(1024 * 1024) // 1 MB
//! .with_auxiliary(512 * 1024); // 512 KB
//!
//! if !guard.can_allocate(estimate.total_bytes()) {
//! panic!("Insufficient memory");
//! }
//!
//! // Or use the trait-based estimator
//! struct MyWorkload { elements: usize }
//! impl ringkernel_core::resource::MemoryEstimator for MyWorkload {
//! fn estimate(&self) -> MemoryEstimate {
//! MemoryEstimate::new().with_primary((self.elements * 64) as u64)
//! }
//! fn name(&self) -> &str { "MyWorkload" }
//! }
//! ```
pub use ;
pub use ;
pub use ;
pub use ;
/// Default maximum memory usage (4 GB).
pub const DEFAULT_MAX_MEMORY_BYTES: u64 = 4 * 1024 * 1024 * 1024;
/// Safety margin for system memory (leave 1 GB free).
pub const SYSTEM_MEMORY_MARGIN: u64 = 1024 * 1024 * 1024;