Skip to content

Conversation

@AkshatDudeja77
Copy link

This change fixes reporting of swap-only memory metrics for cgroup v2.

Previously, swap usage was either missing or incorrectly derived. This update
adds proper parsing and exposure of swap-only usage so that metrics such as
container_memory_swap and related fields reflect actual cgroup v2 behavior.

Tested locally on cgroup v2 (WSL2) and verified metrics via /metrics endpoint.

@google-cla
Copy link

google-cla bot commented Jan 21, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@AkshatDudeja77
Copy link
Author

I’ve signed the Google CLA. Could you please recheck?

@SergeyKanzhelev
Copy link
Collaborator

/cc @ajaysundark

@dims
Copy link
Collaborator

dims commented Jan 21, 2026

@AkshatDudeja77 the PR is not complete. just adding a file in vendor/ is not going to help from what i can tell.

@ajaysundark
Copy link

ajaysundark commented Jan 22, 2026

The description is misleading. it is not that cgroupv2 swap/stats collection is not working, but it is not working for "kind".

The file added in this PR is from opencontainers/cgroups which is the module used by cadvisor for stats collection. And from what I can see here: https://github.com/opencontainers/cgroups/blob/e0c56cb31dcb3cb2b3d1554b20dd01ced32e2a2b/fs2/memory.go#L115-L119 cgroupv2 swap collection is correctly handled.

I dont see any code changes in this file, it seems to be just a plain import. did you miss to add your changes in the cadvisor itself?

@ajaysundark
Copy link

/retitle Fix cgroup v2 swap-only memory metrics for KIND

@AkshatDudeja77 AkshatDudeja77 changed the title Fix cgroup v2 swap-only memory metrics Fix cgroup v2 swap-only memory metrics for KIND Jan 22, 2026
@AkshatDudeja77
Copy link
Author

Thanks for the clarification. I agree that this issue is specific to KIND. I’ve updated the PR title accordingly and will add the missing cAdvisor-side changes.

@AkshatDudeja77
Copy link
Author

This PR fixes incorrect swap reporting under cgroup v2.

Previously, cAdvisor derived swap as SwapUsage - MemoryUsage, which is incorrect for cgroup v2.

The fix ensures swap metrics are sourced from cgroup v2 swap-only accounting, aligning container stats with kernel semantics and Prometheus metrics output.

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.

4 participants