opencontainers / runc

CLI tool for spawning and running containers according to the OCI specification
https://www.opencontainers.org/
Apache License 2.0
11.89k stars 2.11k forks source link

cgroup v2 root stats should not be calculated as v1 #4059

Open linxiulei opened 1 year ago

linxiulei commented 1 year ago

Description

From the comments in https://github.com/opencontainers/runc/blob/main/libcontainer/cgroups/fs2/memory.go#L218, it appears the root stats of cgroup v2 was collected in a way to be similar to how v1 is implemented. My understanding, root stats v2 should be collected as memory.current in non-root cgroups, which is supposed to be total memory as opposed to just anon + file.

This issue causes missing a visible amount memory not counted in Usage (e.g. kernel memory) and is misleading. I propose using the value from /proc/meminfo to get the total memory usage for root stat.

Steps to reproduce the issue

  1. run a kubelet
  2. curl localhost:10255/stats/summary to check the root stats
  3. stats got from step 2 do not match the system memory usage

Describe the results you received and expected

root stats' usageBytes should match system memory usage

What version of runc are you using?

runc version 1.1.7 commit: a916309fff0f838eb94e928713dbc3c0d0ac7aa4 spec: 1.0.2-dev go: go1.20.5 libseccomp: 2.5.4

Host OS information

No response

Host kernel information

No response

Zheaoli commented 12 months ago

I think this maybe make sense.

For now, we use /proc/meminfo to calculate the swap info, and memory.stat to calculate the usage info. I think this may be strange. Perhaps we should calculate the memory info for the same place

cc @lifubang

Zheaoli commented 11 months ago

ping @lifubang @AkihiroSuda (

kolyshkin commented 11 months ago

@linxiulei @Zheaoli we have changed this code a few times already to please k8s. Feel free to open a PR.