Skip to content

Commit fb6ec65

Browse files
author
Mrunal Patel
authored
Merge pull request #1651 from sjenning/adjust-systemd-cpuquota
systemd: adjust CPUQuotaPerSecUSec to compensate for systemd internal handling
2 parents b2567b3 + bca53e7 commit fb6ec65

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

libcontainer/cgroups/systemd/apply_systemd.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,13 @@ func (m *Manager) Apply(pid int) error {
271271
// cpu.cfs_quota_us and cpu.cfs_period_us are controlled by systemd.
272272
if c.Resources.CpuQuota != 0 && c.Resources.CpuPeriod != 0 {
273273
cpuQuotaPerSecUSec := uint64(c.Resources.CpuQuota*1000000) / c.Resources.CpuPeriod
274+
// systemd converts CPUQuotaPerSecUSec (microseconds per CPU second) to CPUQuota
275+
// (integer percentage of CPU) internally. This means that if a fractional percent of
276+
// CPU is indicated by Resources.CpuQuota, we need to round up to the nearest
277+
// 10ms (1% of a second) such that child cgroups can set the cpu.cfs_quota_us they expect.
278+
if cpuQuotaPerSecUSec%10000 != 0 {
279+
cpuQuotaPerSecUSec = ((cpuQuotaPerSecUSec / 10000) + 1) * 10000
280+
}
274281
properties = append(properties,
275282
newProp("CPUQuotaPerSecUSec", cpuQuotaPerSecUSec))
276283
}

0 commit comments

Comments
 (0)