-
Notifications
You must be signed in to change notification settings - Fork 850
Description
Description
I came across a new Kubernetes blog post that highlights a change in the formula used to convert CPU cores from cgroup v1 (cpu.shares) to cgroup v2 (cpu.weight): New Conversion from cgroup v1 CPU Shares to v2 CPU Weight
- New formula:
cpu.weight = ⌈ 10 ^ (L^2 / 612 + 125 * L / 612 − 7 / 34) ⌉, where: L=log2(cpu.shares)(Please verify this with the code) - Old formula:
cpu.weight = (1 + ((cpu.shares - 2) * 9999) / 262142)
Required Code Change: The implementation in LinuxUtilizationParserCgroupV2.cs should be updated to use the new conversion formula. This change is required to ensure that requested CPU values are computed correctly when running on cgroup v2.
Impact: Updating this logic will fix incorrect values in the request.utilization metric. Additionally, there may be other metrics that rely on the CPU request calculation and are therefore also affected. These should be reviewed as part of this change.
References:
- Reference Thread: Conversion of cgroup v1 CPU shares to v2 CPU weight causes workloads to have low CPU priority kubernetes/kubernetes#131216
- Reference K8s PRs:
Reproduction Steps
I checked on an AKS cluster v1.32.7 that cpu.weight is calculated with the new formula.
High level steps:
- Run a container with cpu request
100m - Exec into the container
cat /sys/fs/cgroup/cpu.weight. The value would be17based on the new formula.
Expected behavior
The formula in LinuxUtilizationParserCgroupV2.cs should be updated according to the new formula. This ensures that the request.utilization metric is calculated and reported correctly when running on cgroup v2 systems.
Actual behavior
The LinuxUtilizationParserCgroupV2.cs is using the old conversion formula. As a result, the computed CPU request is inaccurate, causing the request.utilization metric to report incorrect values on cgroup v2.
Regression?
No response
Known Workarounds
No response
Configuration
- Dotnet SDK: 8.0.410
- OS: Linux
<PackageReference Include="Microsoft.Extensions.Diagnostics.ResourceMonitoring" Version="10.0.0" />
Other information
No response