Skip to content

fix: read cgroupv2 memory usage from the cgroup that owns memory.max - #39

Open
david-fraley wants to merge 2 commits into
mainfrom
dfraley/cgroupv2-memory-usage-limit-owner
Open

david-fraley wants to merge 2 commits into
mainfrom
dfraley/cgroupv2-memory-usage-limit-owner

Conversation

@david-fraley

Copy link
Copy Markdown

Fixes #38 (CORE-693).

In cgroup v2, memory() found memory.max by walking up to an ancestor, but still read memory.current and memory.stat from the process's own cgroup. In docker-in-docker and devcontainer workspaces the agent sits in /init.scope while nested containers sit in sibling /docker/<id>, so usage was massively understated (6% reported vs 89% actual) and memory alerts never fired before an OOM kill.

Now usage is read from the same cgroup that owns the limit, so used and total describe the same domain. When the process's own cgroup holds the limit, or there is no limit, behavior is unchanged. If the limit owner has no usage files, it falls back to the old behavior.

Added Memory/UsageFromLimitOwner with an /init.scope + /docker/<id> fixture; it fails on main and passes with this change. CPU may have the same shape (noted in the issue) but is not changed here.


Generated by Coder Agents on behalf of @david-fraley.

@DanielleMaywood

This comment was marked as resolved.

Comment thread cgroupv2.go
Comment thread cgroupv2.go Outdated
Comment thread cgroupv2.go
Comment thread cgroupv2.go Outdated
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.

bug: cgroup v2 memory usage ignores sibling cgroups under the limit-owning ancestor (docker-in-docker, devcontainers)

3 participants