Skip to main content

read_host_memory

Function read_host_memory 

Source
pub async fn read_host_memory() -> Option<HostMemory>
Expand description

Read the host root-slice level: (MemTotal, host used bytes).

Async (tokio::fs) so it never blocks the runtime; read once per collection cycle and shared by every service (see HostMemory).

Mirrors systemd’s root-slice handling exactly: the limit is physical_memory() (== MemTotal; verified sysinfo.totalram matches it byte-exact on this kernel) and the current is procfs_memory_get_used() (src/basic/procfs-util.c), which returns MemTotal − MemAvailable, so the root level contributes MemTotal − used == MemAvailable — verified live, D-Bus MemoryAvailable for a limitless service equalled MemAvailable byte-exact.

Both numbers come from the host /proc/meminfo even for container reads: a container’s PID 1 computes the same two numbers from the same host /proc. Read /proc/meminfo once per collection cycle; see HostMemory.