ram-sentinel 0.2.0

A surgical OOM prevention daemon for Linux desktops. Configurably monitors RAM, swap, and/or PSI (Pressure Stall Information) to selectively kill low-priority processes (e.g., browser tabs) before the system freezes.
use byte_unit::Byte;
use std::sync::OnceLock;
use sysinfo::{MemoryRefreshKind, RefreshKind, System};

static TOTAL_MEMORY: OnceLock<u64> = OnceLock::new();

pub fn parse_size(s: &str) -> Option<u64> {
    Byte::parse_str(s, true).ok().map(|b| b.as_u64())
}

pub fn get_total_memory() -> u64 {
    *TOTAL_MEMORY.get_or_init(|| {
        let mut sys = System::new_with_specifics(
            RefreshKind::nothing().with_memory(MemoryRefreshKind::everything()),
        );
        sys.refresh_memory();
        sys.total_memory()
    })
}