fix(lc_lib): pick most constraining memory reading#23
Merged
Conversation
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.
qzhuyan
approved these changes
May 13, 2026
This was referenced May 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_bytesas the kernel sentinel (~8 EiB). 0.3.6 preferred cgroup over/proc/meminfounconditionally, 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/1throws, 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 dialyzercleanrebar3 xrefclean./check_vsns.escriptpasses