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§
- Memory
Reading - A memory reading with its provenance.
Enums§
- Memory
Source - 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
MemAvailablefrom/proc/meminfo(kB → bytes). macOS: read total host RAM viasysctl 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
Noneif measurement is not supported on this platform.