@@ -280,7 +280,9 @@ func systemdVersionAtoi(str string) (int, error) {
280280 return ver , nil
281281}
282282
283- func addCpuQuota (cm * dbusConnManager , properties * []systemdDbus.Property , quota int64 , period uint64 ) {
283+ // addCPUQuota adds CPUQuotaPeriodUSec and CPUQuotaPerSecUSec to the properties. The passed quota may be modified
284+ // along with round-up during calculation in order to write the same value to cgroupfs later.
285+ func addCPUQuota (cm * dbusConnManager , properties * []systemdDbus.Property , quota * int64 , period uint64 ) {
284286 if period != 0 {
285287 // systemd only supports CPUQuotaPeriodUSec since v242
286288 sdVer := systemdVersion (cm )
@@ -292,10 +294,10 @@ func addCpuQuota(cm *dbusConnManager, properties *[]systemdDbus.Property, quota
292294 " (setting will still be applied to cgroupfs)" , sdVer )
293295 }
294296 }
295- if quota != 0 || period != 0 {
297+ if * quota != 0 || period != 0 {
296298 // corresponds to USEC_INFINITY in systemd
297299 cpuQuotaPerSecUSec := uint64 (math .MaxUint64 )
298- if quota > 0 {
300+ if * quota > 0 {
299301 if period == 0 {
300302 // assume the default
301303 period = defCPUQuotaPeriod
@@ -304,9 +306,11 @@ func addCpuQuota(cm *dbusConnManager, properties *[]systemdDbus.Property, quota
304306 // (integer percentage of CPU) internally. This means that if a fractional percent of
305307 // CPU is indicated by Resources.CpuQuota, we need to round up to the nearest
306308 // 10ms (1% of a second) such that child cgroups can set the cpu.cfs_quota_us they expect.
307- cpuQuotaPerSecUSec = uint64 (quota * 1000000 ) / period
309+ cpuQuotaPerSecUSec = uint64 (* quota * 1000000 ) / period
308310 if cpuQuotaPerSecUSec % 10000 != 0 {
309311 cpuQuotaPerSecUSec = ((cpuQuotaPerSecUSec / 10000 ) + 1 ) * 10000
312+ // Update the requested quota along with the round-up in order to write the same value to cgroupfs.
313+ * quota = int64 (cpuQuotaPerSecUSec ) * int64 (period ) / 1000000
310314 }
311315 }
312316 * properties = append (* properties ,
0 commit comments