Merge pull request #2820 from dqminh/io-cgroup2-fallback

fs2: fallback to setting io.weight if io.bfq.weight
This commit is contained in:
Akihiro Suda
2021-03-26 18:58:51 +09:00
committed by GitHub
4 changed files with 40 additions and 3 deletions
+9 -1
View File
@@ -30,7 +30,15 @@ func setIo(dirPath string, cgroup *configs.Cgroup) error {
filename := "io.bfq.weight"
if err := fscommon.WriteFile(dirPath, filename,
strconv.FormatUint(uint64(cgroup.Resources.BlkioWeight), 10)); err != nil {
return err
// if io.bfq.weight does not exist, then bfq module is not loaded.
// Fallback to use io.weight with a conversion scheme
if !os.IsNotExist(err) {
return err
}
v := cgroups.ConvertBlkIOToIOWeightValue(cgroup.Resources.BlkioWeight)
if err := fscommon.WriteFile(dirPath, "io.weight", strconv.FormatUint(v, 10)); err != nil {
return err
}
}
}
for _, td := range cgroup.Resources.BlkioThrottleReadBpsDevice {
+11
View File
@@ -439,3 +439,14 @@ func ConvertMemorySwapToCgroupV2Value(memorySwap, memory int64) (int64, error) {
return memorySwap - memory, nil
}
// 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 to IOWeight is y = (1 + (x - 10) * 9999 / 990)
// convert linearly from [10-1000] to [1-10000]
func ConvertBlkIOToIOWeightValue(blkIoWeight uint16) uint64 {
if blkIoWeight == 0 {
return 0
}
return uint64(1 + (uint64(blkIoWeight)-10)*9999/990)
}
+14
View File
@@ -642,3 +642,17 @@ func TestConvertMemorySwapToCgroupV2Value(t *testing.T) {
}
}
}
func TestConvertBlkIOToIOWeightValue(t *testing.T) {
cases := map[uint16]uint64{
0: 0,
10: 1,
1000: 10000,
}
for i, expected := range cases {
got := ConvertBlkIOToIOWeightValue(i)
if got != expected {
t.Errorf("expected ConvertBlkIOToIOWeightValue(%d) to be %d, got %d", i, expected, got)
}
}
}
+6 -2
View File
@@ -196,8 +196,12 @@ function setup() {
[ "$status" -eq 0 ]
runc exec test_cgroups_unified sh -c 'cat /sys/fs/cgroup/io.bfq.weight'
[ "$status" -eq 0 ]
[ "$output" = 'default 750' ]
if [[ "$status" -eq 0 ]]; then
[ "$output" = 'default 750' ]
else
runc exec test_cgroups_unified sh -c 'cat /sys/fs/cgroup/io.weight'
[ "$output" = 'default 7475' ]
fi
}
@test "runc run (cgroup v2 resources.unified only)" {