Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.

Commit f4a4391

Browse files
author
Mrunal Patel
committed
Merge pull request #371 from coolljt0725/add_support_cpu_cfs_quota
Add systemd support cpu.cfs_quota_us and cpu.cfs_period_us
2 parents 3f35b26 + 29f5cb6 commit f4a4391

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 Apply(c *cgroups.Cgroup, pid int) (map[string]string, error) {
150150
return nil, 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 nil, err
157+
}
158+
153159
// -1 disables memorySwap
154160
if c.MemorySwap >= 0 && c.Memory != 0 {
155161
if err := joinMemory(c, pid); err != nil {
@@ -196,6 +202,24 @@ func writeFile(dir, file, data string) error {
196202
return ioutil.WriteFile(filepath.Join(dir, file), []byte(data), 0700)
197203
}
198204

205+
func joinCpu(c *cgroups.Cgroup, pid int) error {
206+
path, err := getSubsystemPath(c, "cpu")
207+
if err != nil {
208+
return err
209+
}
210+
if c.CpuQuota != 0 {
211+
if err = ioutil.WriteFile(filepath.Join(path, "cpu.cfs_quota_us"), []byte(strconv.FormatInt(c.CpuQuota, 10)), 0700); err != nil {
212+
return err
213+
}
214+
}
215+
if c.CpuPeriod != 0 {
216+
if err = ioutil.WriteFile(filepath.Join(path, "cpu.cfs_period_us"), []byte(strconv.FormatInt(c.CpuPeriod, 10)), 0700); err != nil {
217+
return err
218+
}
219+
}
220+
return nil
221+
}
222+
199223
func joinFreezer(c *cgroups.Cgroup, pid int) error {
200224
path, err := getSubsystemPath(c, "freezer")
201225
if err != nil {

0 commit comments

Comments
 (0)