Skip to content

Commit 4b8134f

Browse files
committed
Convert blkioWeight to io.weight properly
Signed-off-by: Boris Popovschi <[email protected]>
1 parent 81ef502 commit 4b8134f

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

libcontainer/cgroups/fs2/io.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ import (
1717
func setIo(dirPath string, cgroup *configs.Cgroup) error {
1818
if cgroup.Resources.BlkioWeight != 0 {
1919
filename := "io.bfq.weight"
20-
if err := fscommon.WriteFile(dirPath, filename, strconv.FormatUint(uint64(cgroup.Resources.BlkioWeight), 10)); err != nil {
20+
if err := fscommon.WriteFile(dirPath, filename,
21+
strconv.FormatUint(cgroups.ConvertBlkIOToCgroupV2Value(cgroup.Resources.BlkioWeight), 10)); err != nil {
2122
return err
2223
}
2324
}
24-
2525
for _, td := range cgroup.Resources.BlkioThrottleReadBpsDevice {
2626
if err := fscommon.WriteFile(dirPath, "io.max", td.StringName("rbps")); err != nil {
2727
return err

libcontainer/cgroups/utils.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,14 @@ func isEINVAL(err error) bool {
587587
}
588588
}
589589

590+
// Since the OCI spec is designed for cgroup v1, in some cases
591+
// there is need to convert from the cgroup v1 configuration to cgroup v2
592+
// the formula for BlkIOWeight is y = (1 + (x - 10) * 9999 / 990)
593+
// convert linearly from [10-1000] to [1-10000]
594+
func ConvertBlkIOToCgroupV2Value(blkIoWeight uint16) uint64 {
595+
return uint64(1 + (blkIoWeight-10)*9999/990)
596+
}
597+
590598
// Since the OCI spec is designed for cgroup v1, in some cases
591599
// there is need to convert from the cgroup v1 configuration to cgroup v2
592600
// the formula for cpuShares is y = (1 + ((x - 2) * 9999) / 262142)

0 commit comments

Comments
 (0)