From 54968f68bc2ba50f59a66fba9f6823215a0bc4f6 Mon Sep 17 00:00:00 2001 From: Qiang Huang Date: Mon, 19 Jan 2015 14:29:02 +0800 Subject: [PATCH] add support for blkio.weight Signed-off-by: Qiang Huang --- cgroups/cgroups.go | 1 + cgroups/fs/blkio.go | 10 ++++++++-- cgroups/systemd/apply_systemd.go | 5 +++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/cgroups/cgroups.go b/cgroups/cgroups.go index 106698d1..497437f5 100644 --- a/cgroups/cgroups.go +++ b/cgroups/cgroups.go @@ -51,6 +51,7 @@ type Cgroup struct { 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 CpusetMems string `json:"cpuset_mems,omitempty"` // MEM to use + BlkioWeight int64 `json:"blkio_weight,omitempty"` // Specifies per cgroup weight, range is from 10 to 1000. Freezer FreezerState `json:"freezer,omitempty"` // set the freeze value for the process Slice string `json:"slice,omitempty"` // Parent slice to use for systemd } diff --git a/cgroups/fs/blkio.go b/cgroups/fs/blkio.go index ce824d56..b64e4684 100644 --- a/cgroups/fs/blkio.go +++ b/cgroups/fs/blkio.go @@ -15,11 +15,17 @@ type BlkioGroup struct { } func (s *BlkioGroup) Set(d *data) error { - // we just want to join this group even though we don't set anything - if _, err := d.join("blkio"); err != nil && !cgroups.IsNotFound(err) { + dir, err := d.join("blkio") + if err != nil && !cgroups.IsNotFound(err) { return err } + if d.c.BlkioWeight != 0 { + if err := writeFile(dir, "blkio.weight", strconv.FormatInt(d.c.BlkioWeight, 10)); err != nil { + return err + } + } + return nil } diff --git a/cgroups/systemd/apply_systemd.go b/cgroups/systemd/apply_systemd.go index 41dce311..c866bf0b 100644 --- a/cgroups/systemd/apply_systemd.go +++ b/cgroups/systemd/apply_systemd.go @@ -119,6 +119,11 @@ func Apply(c *cgroups.Cgroup, pid int) (map[string]string, error) { newProp("CPUShares", uint64(c.CpuShares))) } + if c.BlkioWeight != 0 { + properties = append(properties, + newProp("BlockIOWeight", uint64(c.BlkioWeight))) + } + if _, err := theConn.StartTransientUnit(unitName, "replace", properties...); err != nil { return nil, err }