Skip to content

Commit bca53e7

Browse files
committed
systemd: adjust CPUQuotaPerSecUSec to compensate for systemd internal handling
Signed-off-by: Seth Jennings <[email protected]>
1 parent b2567b3 commit bca53e7

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)