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:
MemAvailablefrom/proc/meminfo, the kernel’s purpose-built estimate (free + reclaimable page cache − watermarks). This is the one legitimate use of/proc/meminfoin this module — availability has nosysconfspelling — and it degrades safely:Noneon any other Unix, which the ceiling rule answers with the half-of-total fallback. - Windows:
GlobalMemoryStatusEx’sullAvailPhys, the direct analog. - macOS:
host_statistics64free + inactive pages — inactive is macOS’s reclaimable class, the moral equivalent of Linux’s page cache share.