Skip to main content

detect_available_memory

Function detect_available_memory 

Source
pub(crate) fn detect_available_memory() -> MemoryReading
Expand description

Detects available memory for the process.

Detection chain (first success wins):

  1. BGE_M3_AVAILABLE_MEMORY_BYTES env override.
  2. Linux cgroup v2: /sys/fs/cgroup/memory.max.
  3. Linux cgroup v1: /sys/fs/cgroup/memory/memory.limit_in_bytes.
  4. Linux: /proc/meminfo MemAvailable.
  5. macOS: sysctl hw.memsize (total host RAM; no cgroup support).
  6. Fallback: 4 GiB constant with a warning log.