ConvertCPUSharesToCgroupV2Value converts CPU shares, used by cgroup v1, to CPU weight, used by cgroup v2. Cgroup v1 CPU shares has a range of [2^1...2^18], i.e. [2...262144], and the default value is 1024. Cgroup v2 CPU weight has a range of [10^0...10^4], i.e. [1...10000], and the default value i
(cpuShares uint64)
| 158 | // Taken from https://github.com/opencontainers/cgroups/blob/v0.0.5/utils.go#L417-L441 |
| 159 | // (Apache License 2.0) |
| 160 | func ConvertCPUSharesToCgroupV2Value(cpuShares uint64) uint64 { |
| 161 | // The value of 0 means "unset". |
| 162 | if cpuShares == 0 { |
| 163 | return 0 |
| 164 | } |
| 165 | if cpuShares <= 2 { |
| 166 | return 1 |
| 167 | } |
| 168 | if cpuShares >= 262144 { |
| 169 | return 10000 |
| 170 | } |
| 171 | l := math.Log2(float64(cpuShares)) |
| 172 | // Quadratic function which fits min, max, and default. |
| 173 | exponent := (l*l+125*l)/612.0 - 7.0/34.0 |
| 174 | |
| 175 | return uint64(math.Ceil(math.Pow(10, exponent))) |
| 176 | } |
| 177 | |
| 178 | // ToResources converts the oci LinuxResources struct into a |
| 179 | // v2 Resources type for use with this package. |
no outgoing calls
searching dependent graphs…