Skip to content

Commit 9f700d4

Browse files
committed
fix cpu.cfs_quota_us changed when systemd daemon-reload using systemd.
Signed-off-by: xuxinkun <[email protected]>
1 parent 02141ce commit 9f700d4

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

libcontainer/cgroups/systemd/apply_systemd.go

+13
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,19 @@ func (m *Manager) Apply(pid int) error {
269269
newProp("CPUShares", uint64(c.Resources.CpuShares)))
270270
}
271271

272+
// cpu.cfs_quota_us and cpu.cfs_period_us are controlled by systemd.
273+
// The percentage cpuQuota refered specifies how much CPU time the unit
274+
// shall get at maximum, relative to the total CPU time available on one CPU.
275+
// The percentage should be greater than 1%.
276+
if c.Resources.CpuQuota != 0 && c.Resources.CpuPeriod != 0 {
277+
cpuQuota := c.Resources.CpuQuota * 100 / c.Resources.CpuPeriod
278+
if cpuQuota == 0 {
279+
return fmt.Errorf("cpu_quota divided by cpu_period must be greater than 0.01")
280+
}
281+
properties = append(properties,
282+
newProp("CPUQuotaPerSecUSec", uint64(cpuQuota*10000)))
283+
}
284+
272285
if c.Resources.BlkioWeight != 0 {
273286
properties = append(properties,
274287
newProp("BlockIOWeight", uint64(c.Resources.BlkioWeight)))

0 commit comments

Comments
 (0)