Merge pull request #337 from hqhq/hq_add_blkio_weight

add support for blkio.weight
This commit is contained in:
Michael Crosby 2015-01-20 10:40:12 -08:00
commit 3fbf185602
3 changed files with 14 additions and 2 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}