Skip to content

Commit 22df555

Browse files
author
Michael Crosby
committed
Merge branch 'master' into api
Signed-off-by: Michael Crosby <[email protected]> Conflicts: cgroups/systemd/apply_systemd.go
2 parents 1b755bf + f4a4391 commit 22df555

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

cgroups/systemd/apply_systemd.go

+24
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ func (m *Manager) Apply(pid int) error {
150150
return err
151151
}
152152

153+
// TODO: CpuQuota and CpuPeriod not available in systemd
154+
// we need to manually join the cpu.cfs_quota_us and cpu.cfs_period_us
155+
if err := joinCpu(c, pid); err != nil {
156+
return err
157+
}
158+
153159
// -1 disables memorySwap
154160
if c.MemorySwap >= 0 && c.Memory != 0 {
155161
if err := joinMemory(c, pid); err != nil {
@@ -207,6 +213,24 @@ func writeFile(dir, file, data string) error {
207213
return ioutil.WriteFile(filepath.Join(dir, file), []byte(data), 0700)
208214
}
209215

216+
func joinCpu(c *configs.Cgroup, pid int) error {
217+
path, err := getSubsystemPath(c, "cpu")
218+
if err != nil {
219+
return err
220+
}
221+
if c.CpuQuota != 0 {
222+
if err = ioutil.WriteFile(filepath.Join(path, "cpu.cfs_quota_us"), []byte(strconv.FormatInt(c.CpuQuota, 10)), 0700); err != nil {
223+
return err
224+
}
225+
}
226+
if c.CpuPeriod != 0 {
227+
if err = ioutil.WriteFile(filepath.Join(path, "cpu.cfs_period_us"), []byte(strconv.FormatInt(c.CpuPeriod, 10)), 0700); err != nil {
228+
return err
229+
}
230+
}
231+
return nil
232+
}
233+
210234
func joinFreezer(c *configs.Cgroup, pid int) error {
211235
path, err := getSubsystemPath(c, "freezer")
212236
if err != nil {

0 commit comments

Comments
 (0)