Merge pull request #1805 from derekwaynecarr/systemd-cpuquota-fix
fix systemd cpu quota for -1
This commit is contained in:
commit
2e931185f9
|
@ -5,6 +5,7 @@ package systemd
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -295,13 +296,19 @@ func (m *Manager) Apply(pid int) error {
|
||||||
|
|
||||||
// cpu.cfs_quota_us and cpu.cfs_period_us are controlled by systemd.
|
// cpu.cfs_quota_us and cpu.cfs_period_us are controlled by systemd.
|
||||||
if c.Resources.CpuQuota != 0 && c.Resources.CpuPeriod != 0 {
|
if c.Resources.CpuQuota != 0 && c.Resources.CpuPeriod != 0 {
|
||||||
cpuQuotaPerSecUSec := uint64(c.Resources.CpuQuota*1000000) / c.Resources.CpuPeriod
|
// corresponds to USEC_INFINITY in systemd
|
||||||
// systemd converts CPUQuotaPerSecUSec (microseconds per CPU second) to CPUQuota
|
// if USEC_INFINITY is provided, CPUQuota is left unbound by systemd
|
||||||
// (integer percentage of CPU) internally. This means that if a fractional percent of
|
// always setting a property value ensures we can apply a quota and remove it later
|
||||||
// CPU is indicated by Resources.CpuQuota, we need to round up to the nearest
|
cpuQuotaPerSecUSec := uint64(math.MaxUint64)
|
||||||
// 10ms (1% of a second) such that child cgroups can set the cpu.cfs_quota_us they expect.
|
if c.Resources.CpuQuota > 0 {
|
||||||
if cpuQuotaPerSecUSec%10000 != 0 {
|
// systemd converts CPUQuotaPerSecUSec (microseconds per CPU second) to CPUQuota
|
||||||
cpuQuotaPerSecUSec = ((cpuQuotaPerSecUSec / 10000) + 1) * 10000
|
// (integer percentage of CPU) internally. This means that if a fractional percent of
|
||||||
|
// CPU is indicated by Resources.CpuQuota, we need to round up to the nearest
|
||||||
|
// 10ms (1% of a second) such that child cgroups can set the cpu.cfs_quota_us they expect.
|
||||||
|
cpuQuotaPerSecUSec = uint64(c.Resources.CpuQuota*1000000) / c.Resources.CpuPeriod
|
||||||
|
if cpuQuotaPerSecUSec%10000 != 0 {
|
||||||
|
cpuQuotaPerSecUSec = ((cpuQuotaPerSecUSec / 10000) + 1) * 10000
|
||||||
|
}
|
||||||
}
|
}
|
||||||
properties = append(properties,
|
properties = append(properties,
|
||||||
newProp("CPUQuotaPerSecUSec", cpuQuotaPerSecUSec))
|
newProp("CPUQuotaPerSecUSec", cpuQuotaPerSecUSec))
|
||||||
|
|
Loading…
Reference in New Issue