cgroups: add support for blkio.weight_device
Signed-off-by: Qiang Huang <h.huangqiang@huawei.com>
This commit is contained in:
parent
bd8ec36106
commit
054d8e02bf
|
@ -35,6 +35,12 @@ func (s *BlkioGroup) Set(path string, cgroup *configs.Cgroup) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if cgroup.BlkioWeightDevice != "" {
|
||||||
|
if err := writeFile(path, "blkio.weight_device", cgroup.BlkioWeightDevice); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -102,6 +102,35 @@ func TestBlkioSetWeight(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBlkioSetWeightDevice(t *testing.T) {
|
||||||
|
helper := NewCgroupTestUtil("blkio", t)
|
||||||
|
defer helper.cleanup()
|
||||||
|
|
||||||
|
const (
|
||||||
|
weightDeviceBefore = "8:0 400"
|
||||||
|
weightDeviceAfter = "8:0 500"
|
||||||
|
)
|
||||||
|
|
||||||
|
helper.writeFileContents(map[string]string{
|
||||||
|
"blkio.weight_device": weightDeviceBefore,
|
||||||
|
})
|
||||||
|
|
||||||
|
helper.CgroupData.c.BlkioWeightDevice = weightDeviceAfter
|
||||||
|
blkio := &BlkioGroup{}
|
||||||
|
if err := blkio.Set(helper.CgroupPath, helper.CgroupData.c); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
value, err := getCgroupParamString(helper.CgroupPath, "blkio.weight_device")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to parse blkio.weight_device - %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if value != weightDeviceAfter {
|
||||||
|
t.Fatal("Got the wrong value, set blkio.weight_device failed.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestBlkioStats(t *testing.T) {
|
func TestBlkioStats(t *testing.T) {
|
||||||
helper := NewCgroupTestUtil("blkio", t)
|
helper := NewCgroupTestUtil("blkio", t)
|
||||||
defer helper.cleanup()
|
defer helper.cleanup()
|
||||||
|
|
|
@ -216,6 +216,13 @@ func (m *Manager) Apply(pid int) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: Systemd does have `BlockIODeviceWeight` property, but we got problem
|
||||||
|
// using that (at least on systemd 208, see https://github.com/docker/libcontainer/pull/354),
|
||||||
|
// so use fs work around for now.
|
||||||
|
if err := joinBlkio(c, pid); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
paths := make(map[string]string)
|
paths := make(map[string]string)
|
||||||
for sysname := range subsystems {
|
for sysname := range subsystems {
|
||||||
subsystemPath, err := getSubsystemPath(m.Cgroups, sysname)
|
subsystemPath, err := getSubsystemPath(m.Cgroups, sysname)
|
||||||
|
@ -417,3 +424,20 @@ func joinCpuset(c *configs.Cgroup, pid int) error {
|
||||||
|
|
||||||
return s.ApplyDir(path, c, pid)
|
return s.ApplyDir(path, c, pid)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// `BlockIODeviceWeight` property of systemd does not work properly, and systemd
|
||||||
|
// expects device path instead of major minor numbers, which is also confusing
|
||||||
|
// for users. So we use fs work around for now.
|
||||||
|
func joinBlkio(c *configs.Cgroup, pid int) error {
|
||||||
|
path, err := getSubsystemPath(c, "blkio")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if c.BlkioWeightDevice != "" {
|
||||||
|
if err := writeFile(path, "blkio.weight_device", c.BlkioWeightDevice); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
@ -46,6 +46,9 @@ type Cgroup struct {
|
||||||
// Specifies per cgroup weight, range is from 10 to 1000.
|
// Specifies per cgroup weight, range is from 10 to 1000.
|
||||||
BlkioWeight int64 `json:"blkio_weight"`
|
BlkioWeight int64 `json:"blkio_weight"`
|
||||||
|
|
||||||
|
// Weight per cgroup per device, can override BlkioWeight.
|
||||||
|
BlkioWeightDevice string `json:"blkio_weight_device"`
|
||||||
|
|
||||||
// set the freeze value for the process
|
// set the freeze value for the process
|
||||||
Freezer FreezerState `json:"freezer"`
|
Freezer FreezerState `json:"freezer"`
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue