google / google/cadvisor

`container_spec_cpu_shares` will use wrong cgroups v2 conversion formula for runc v1.3.2+

Open
#3,737 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
19.4k
Forks
2.5k
Avg merge
9h 7m
Merged PRs (30d)
1

Description

cadvisor uses the linear conversion metric when converting from cgroups v2 `cpu.weight` to the correct cpu limit share value ([ref](https://github.com/google/cadvisor/blob/5adb1c3bb38b4c5d50b31f39faf3214a44ae479b/container/common/helpers.go#L254-L265)).

Although kubelet has [this conversion](https://github.com/kubernetes/kubernetes/blob/master/pkg/kubelet/cm/cgroup_v2_manager_linux.go#L171-L175), it's not being used anywhere, so presumably the cpu resource request is being converted into cgroup v2 `cpu.weight` in the containerization layer. runc 1.3.2 will use a [different conversion formula](https://github.com/opencontainers/cgroups/pull/20), when they bump their cgroups dependency from 0.0.1 to 0.0.4 ([ref](https://github.com/opencontainers/runc/releases/tag/v1.3.2)), as the new conversion is done in 0.0.3 ([ref](https://github.com/opencontainers/cgroups/releases/tag/v0.0.3)).

This would result in `container_spec_cpu_shares` to become inaccurate as the container runtime layer would use the new conversion to convert shares to weight, and cadvisor the old conversion from weight to shares. I did some calculation to see what the discrepancy would be, and it seems quite big (feel free to double check my math on this):
https://www.desmos.com/calculator/jwnh1p4fov

Is there a plan in place to have a stable version with this new formula from runc?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.