Skip to main content

available_memory_bytes

Function available_memory_bytes 

Source
pub fn available_memory_bytes() -> Option<u64>
Expand description

RAM available for new allocations right now, in bytes, or None when the platform offers no honest answer.

“Available” here means the OS’s own estimate of what a new consumer can take without pushing the machine into swap — not merely “free”, which undercounts by excluding reclaimable caches:

  • Linux: MemAvailable from /proc/meminfo, the kernel’s purpose-built estimate (free + reclaimable page cache − watermarks). This is the one legitimate use of /proc/meminfo in this module — availability has no sysconf spelling — and it degrades safely: None on any other Unix, which the ceiling rule answers with the half-of-total fallback.
  • Windows: GlobalMemoryStatusEx’s ullAvailPhys, the direct analog.
  • macOS: host_statistics64 free + inactive pages — inactive is macOS’s reclaimable class, the moral equivalent of Linux’s page cache share.