dotnet/extensions

Incorrect calculation of CPU Share from cgroups v2 CPU weight

evgenyfedorov2 opened this issue · 0 comments

Description

The equation

// Calculate CPU pod request in millicores based on the weight, using the formula:
// y = (1 + ((x - 2) * 9999) / 262142), where y is the CPU weight and x is the CPU share (cgroup v1)
// https://github.com/kubernetes/enhancements/tree/master/keps/sig-node/2254-cgroup-v2#phase-1-convert-from-cgroups-v1-settings-to-v2
long cpuPodShare = ((cpuPodWeight * 262142) + 19997) / 9999;

does not match the formula

y = (1 + ((x - 2) * 9999) / 262142), where y is the CPU weight and x is the CPU share (cgroup v1).

Reproduction Steps

N/A

Expected behavior

X should be calculated like this: x = ((y- 1) * 262142 / 9999) + 2

Actual behavior

X is calculated incorrectly: x = ((y * 262142) + 19997) / 9999

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response