Skip to content

Respect ancestor memory limits in cgroup v2 - #16767

Open
tamird wants to merge 1 commit into
gvisor:masterfrom
tamird:proposal/cgroup-v2-effective-memory
Open

tamird wants to merge 1 commit into
gvisor:masterfrom
tamird:proposal/cgroup-v2-effective-memory

Conversation

@tamird

@tamird tamird commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

A sandbox under a 512 MiB pod can report the host's memory in
/proc/meminfo if its own cgroup and its immediate parent set no limit.
Setting a larger limit on the sandbox itself can also hide the pod's
ceiling. At startup, runsc now takes the smallest memory.max from the
sandbox to the root of the visible cgroup hierarchy.

The regression test starts runsc under real host cgroups, then reads
/proc/meminfo inside the sandbox. With an unlimited, 768 MiB, or
384 MiB leaf under a 512 MiB ancestor, the fixed sandbox reported
512, 512, and 384 MiB. Before the fix it reported host memory,
768 MiB, and 384 MiB 1.

This is a runsc startup test. The same read on native Linux reports
host memory in all three leaf cgroups 2. A syscall test that creates
a cgroup inside an already running sandbox cannot exercise runsc's
choice of the guest memory size at startup.

@tamird

tamird commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

@fvoznika, could you review how the sandbox discovers cgroup v2 memory limits? The effective limit can come from an ancestor above both the sandbox and its immediate parent.

Posted by Codex on behalf of @tamird.

@tamird

tamird commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

@manninglucas, could you review the changes to runsc/cgroup/cgroup_v2.go in this PR? The project lists you as a reviewer for runsc/.

Posted by Codex on behalf of @tamird.

github-actions Bot added a commit to tamird/gvisor that referenced this pull request Nov 16, 2026
A sandbox under a 512 MiB pod can report the host's memory in
/proc/meminfo when neither its own cgroup nor its immediate parent
sets a limit. Setting a larger limit on the sandbox itself also hides
the pod's ceiling. Linux charges the sandbox to all three cgroups.

Use the smallest memory.max from the sandbox to the root of the visible
cgroup hierarchy. Check MemTotal from inside a sandbox with an unlimited,
larger or smaller leaf limit.

Signed-off-by: Tamir Duberstein <[email protected]>
@tamird
tamird force-pushed the proposal/cgroup-v2-effective-memory branch from 8c31f62 to e96ff96 Compare November 17, 2026 18:43
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.

1 participant