mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
cgroup2: add CpuMax conversion
Fix #2243 Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
This commit is contained in:
@@ -609,3 +609,18 @@ func ConvertCPUSharesToCgroupV2Value(cpuShares uint64) uint64 {
|
||||
}
|
||||
return (1 + ((cpuShares-2)*9999)/262142)
|
||||
}
|
||||
|
||||
// ConvertCPUQuotaCPUPeriodToCgroupV2Value generates cpu.max string.
|
||||
func ConvertCPUQuotaCPUPeriodToCgroupV2Value(quota int64, period uint64) string {
|
||||
if quota <= 0 && period == 0 {
|
||||
return ""
|
||||
}
|
||||
if period == 0 {
|
||||
// This default value is documented in https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html
|
||||
period = 100000
|
||||
}
|
||||
if quota <= 0 {
|
||||
return fmt.Sprintf("max %d", period)
|
||||
}
|
||||
return fmt.Sprintf("%d %d", quota, period)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user