Skip to content

Commit

Permalink
Do not convert blkio weight value using blkio->io conversion scheme
Browse files Browse the repository at this point in the history
bfq weight controller (i.e. io.bfq.weight if present) is still using the
same bfq weight scheme (i.e 1->1000, see [1].) Unfortunaly the
documentation for this was wrong, and only fixed recently [2].

Therefore, if we map blkio weight to io.bfq.weight, there's no need to
do any conversion.

[1] https://github.com/torvalds/linux/blob/master/Documentation/block/bfq-iosched.rst
[2] torvalds/linux@65752ae

Signed-off-by: Daniel Dao <[email protected]>
  • Loading branch information
dqminh committed Feb 3, 2021
1 parent 7e3c3e8 commit 29e782f
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 26 deletions.
2 changes: 1 addition & 1 deletion libcontainer/cgroups/fs2/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func setIo(dirPath string, cgroup *configs.Cgroup) error {
if cgroup.Resources.BlkioWeight != 0 {
filename := "io.bfq.weight"
if err := fscommon.WriteFile(dirPath, filename,
strconv.FormatUint(cgroups.ConvertBlkIOToCgroupV2Value(cgroup.Resources.BlkioWeight), 10)); err != nil {
strconv.FormatUint(uint64(cgroup.Resources.BlkioWeight), 10)); err != nil {
return err
}
}
Expand Down
11 changes: 0 additions & 11 deletions libcontainer/cgroups/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,17 +400,6 @@ func WriteCgroupProc(dir string, pid int) error {
return err
}

// Since the OCI spec is designed for cgroup v1, in some cases
// there is need to convert from the cgroup v1 configuration to cgroup v2
// the formula for BlkIOWeight is y = (1 + (x - 10) * 9999 / 990)
// convert linearly from [10-1000] to [1-10000]
func ConvertBlkIOToCgroupV2Value(blkIoWeight uint16) uint64 {
if blkIoWeight == 0 {
return 0
}
return uint64(1 + (uint64(blkIoWeight)-10)*9999/990)
}

// Since the OCI spec is designed for cgroup v1, in some cases
// there is need to convert from the cgroup v1 configuration to cgroup v2
// the formula for cpuShares is y = (1 + ((x - 2) * 9999) / 262142)
Expand Down
14 changes: 0 additions & 14 deletions libcontainer/cgroups/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -548,20 +548,6 @@ func TestGetHugePageSizeImpl(t *testing.T) {
}
}

func TestConvertBlkIOToCgroupV2Value(t *testing.T) {
cases := map[uint16]uint64{
0: 0,
10: 1,
1000: 10000,
}
for i, expected := range cases {
got := ConvertBlkIOToCgroupV2Value(i)
if got != expected {
t.Errorf("expected ConvertBlkIOToCgroupV2Value(%d) to be %d, got %d", i, expected, got)
}
}
}

func TestConvertCPUSharesToCgroupV2Value(t *testing.T) {
cases := map[uint64]uint64{
0: 0,
Expand Down

0 comments on commit 29e782f

Please sign in to comment.