Skip to main content

Module sysinfo

Module sysinfo 

Source
Expand description

Memory detection for auto-budget computation.

Production target is Linux (Fargate/ECS). On Linux we walk the cgroup hierarchy to find the container memory limit, then fall back to host RAM reported by /proc/meminfo. On macOS we read host RAM via sysctl; cgroup support requires unsafe FFI so it is deferred.

§cgroup-v2 detection on ECS Managed Instances (Bottlerocket)

ECS Managed Instances launch containers without --cgroupns=private, so /sys/fs/cgroup/memory.max resolves to the unified-hierarchy root, which reads "max" (no limit). The actual container memory limit is set at a deeper path whose last component is recorded in /proc/self/cgroup (unified-hierarchy format: a single line 0::<path>, e.g. 0::/ecs.slice/ecs-…-task.scope/<id>).

cgroup_memory() reads /proc/self/cgroup, extracts that path, then reads memory.max at each ancestor (deepest first) until it finds a numeric limit or exhausts the tree. Falls through to host_ram only when the entire walk yields "max" (truly unconstrained host).

RSS tracking (read_process_rss_bytes) is Linux-only (parses /proc/self/statm). On macOS it returns None; the auto-budget logic treats None as “cannot measure model footprint” and uses conservative defaults.

Structs§

MemoryReading
A memory reading with its provenance.

Enums§

MemorySource
Where the available-memory reading came from.

Functions§

cgroup_memory 🔒
cgroup_v2_walk 🔒
Reads the cgroup v2 memory limit by walking ancestors of the container’s cgroup path.
detect_available_memory 🔒
Detects available memory for the process.
env_override 🔒
host_ram 🔒
Linux: parse MemAvailable from /proc/meminfo (kB → bytes). macOS: read total host RAM via sysctl hw.memsize.
linux_meminfo_available 🔒
linux_rss 🔒
page_size_bytes 🔒
read_process_rss_bytes 🔒
Returns the current process’s RSS (Resident Set Size) in bytes, or None if measurement is not supported on this platform.