From 264dc8a46bb7f7679439d0a2c41c79a09642acab Mon Sep 17 00:00:00 2001 From: Rohit Jnagal Date: Thu, 24 Apr 2014 14:43:02 +0000 Subject: [PATCH] Add support for cpu hardcapping to cgroups. Docker-DCO-1.1-Signed-off-by: Rohit Jnagal (github: rjnagal) --- pkg/cgroups/cgroups.go | 2 ++ pkg/cgroups/fs/cpu.go | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/pkg/cgroups/cgroups.go b/pkg/cgroups/cgroups.go index 3aac971340..9a498609b5 100644 --- a/pkg/cgroups/cgroups.go +++ b/pkg/cgroups/cgroups.go @@ -16,6 +16,8 @@ type Cgroup struct { Memory int64 `json:"memory,omitempty"` // Memory limit (in bytes) MemorySwap int64 `json:"memory_swap,omitempty"` // Total memory usage (memory + swap); set `-1' to disable swap CpuShares int64 `json:"cpu_shares,omitempty"` // CPU shares (relative weight vs. other containers) + CpuQuota int64 `json:"cpu_quota,omitempty"` // CPU hardcap limit (in usecs). Allowed cpu time in a given period. + CpuPeriod int64 `json:"cpu_period,omitempty"` // CPU period to be used for hardcapping (in usecs). 0 to use system default. CpusetCpus string `json:"cpuset_cpus,omitempty"` // CPU to use UnitProperties [][2]string `json:"unit_properties,omitempty"` // systemd unit properties diff --git a/pkg/cgroups/fs/cpu.go b/pkg/cgroups/fs/cpu.go index 8eb0c4ff46..2664811851 100644 --- a/pkg/cgroups/fs/cpu.go +++ b/pkg/cgroups/fs/cpu.go @@ -19,6 +19,16 @@ func (s *cpuGroup) Set(d *data) error { return err } } + if d.c.CpuPeriod != 0 { + if err := writeFile(dir, "cpu.cfs_period_us", strconv.FormatInt(d.c.CpuPeriod, 10)); err != nil { + return err + } + } + if d.c.CpuQuota != 0 { + if err := writeFile(dir, "cpu.cfs_quota_us", strconv.FormatInt(d.c.CpuQuota, 10)); err != nil { + return err + } + } return nil }