Skip to content

fix(lc_lib): pick most constraining memory reading#23

Merged
zmstone merged 2 commits into
mainfrom
260513-refine-mem-usage-report
May 13, 2026
Merged

fix(lc_lib): pick most constraining memory reading#23
zmstone merged 2 commits into
mainfrom
260513-refine-mem-usage-report

Conversation

@zmstone

@zmstone zmstone commented May 13, 2026

Copy link
Copy Markdown
Member

Summary

Follow-up to #22 (0.3.6). Reported by William Yang: on some hosts cgroup is mounted but no memory limit is set, so the cgroup v1 reading "succeeds" but reports memory.limit_in_bytes as the kernel sentinel (~8 EiB). 0.3.6 preferred cgroup over /proc/meminfo unconditionally, so the usage ratio collapsed to ~0.

Pick the most constraining reading instead: among {cgroup2, cgroup v1, sys}, smallest non-zero total wins, with the larger usage ratio breaking ties. Smallest total is always the real binding limit — a genuine cgroup cap is at most node memory, while an unlimited cgroup's sentinel is far larger than node memory.

cgroup v2's "max" token was already handled (read_int_fs/1 throws, yielding {0,0}).

Test plan

  • rebar3 eunit — 6 tests pass (2 prior + 4 new picker cases: all-zero, sentinel fallback, real-limit selection, tie-break)
  • rebar3 dialyzer clean
  • rebar3 xref clean
  • ./check_vsns.escript passes

zmstone added 2 commits May 13, 2026 09:16
On hosts where cgroup is mounted but no memory limit is set, cgroup v1
reports memory.limit_in_bytes as a sentinel value (~8 EiB), making the
usage ratio collapse to ~0. The 0.3.6 priority list (cgroup2, cgroup, sys)
fell into that trap because cgroup v1 read "successfully".

Replace first_valid/1 with pick_most_constraining/1: among the three
readings, choose the smallest non-zero total (with larger usage ratio as
a tie-break). Smallest non-zero total is the real binding limit because
a real cgroup cap is at most node memory while an unlimited cgroup's
sentinel is far larger.
@zmstone zmstone merged commit ff202bb into main May 13, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants