-
Notifications
You must be signed in to change notification settings - Fork 119
Expand file tree
/
Copy pathmemory_pressure.rs
More file actions
49 lines (45 loc) · 1.84 KB
/
memory_pressure.rs
File metadata and controls
49 lines (45 loc) · 1.84 KB
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
45
46
47
48
49
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;
pub const MODERATE_MEMORY_PRESSURE_THRESHOLD: f64 = 0.85;
pub const HIGH_MEMORY_PRESSURE_THRESHOLD: f64 = 0.90;
pub const CRITICAL_MEMORY_PRESSURE_THRESHOLD: f64 = 0.95;
/// Memory pressure level.
///
/// The current memory pressure level is computed as a function of the current process
/// resident set size (RSS) and the user-configured memory limit (`max_rss`).
///
/// As the memory pressure level increases, the system will apply increasing backpressure to
/// push state cached in memory to storage.
///
/// - `Low`: less than 85% of the user-configured memory limit has been allocated.
/// - `Moderate`: between 85% and 90% of the user-configured memory limit has been allocated.
/// - `High`: between 90% and 95% of the user-configured memory limit has been allocated.
/// - `Critical`: more than 95% of the user-configured memory limit has been allocated.
#[derive(
Debug, Default, Clone, Copy, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize, ToSchema,
)]
#[repr(u8)]
#[serde(rename_all = "snake_case")]
pub enum MemoryPressure {
/// Less than 85% of the user-configured memory limit has been allocated.
#[default]
Low = 0,
/// Between 85% and 90% of the user-configured memory limit has been allocated.
Moderate = 1,
/// Between 90% and 95% of the user-configured memory limit has been allocated.
High = 2,
/// More than 95% of the user-configured memory limit has been allocated.
Critical = 3,
}
impl TryFrom<u8> for MemoryPressure {
type Error = ();
fn try_from(value: u8) -> Result<Self, Self::Error> {
match value {
0 => Ok(MemoryPressure::Low),
1 => Ok(MemoryPressure::Moderate),
2 => Ok(MemoryPressure::High),
3 => Ok(MemoryPressure::Critical),
_ => Err(()),
}
}
}