mirror of
https://github.com/opencontainers/runc.git
synced 2025-11-01 11:32:44 +08:00
fs2: fallback to setting io.weight if io.bfq.weight
if bfq is not loaded, then io.bfq.weight is not available. io.weight should always be available and is the next best equivalent thing. Signed-off-by: Daniel Dao <dqminh89@gmail.com>
This commit is contained in:
@@ -30,8 +30,16 @@ func setIo(dirPath string, cgroup *configs.Cgroup) error {
|
|||||||
filename := "io.bfq.weight"
|
filename := "io.bfq.weight"
|
||||||
if err := fscommon.WriteFile(dirPath, filename,
|
if err := fscommon.WriteFile(dirPath, filename,
|
||||||
strconv.FormatUint(uint64(cgroup.Resources.BlkioWeight), 10)); err != nil {
|
strconv.FormatUint(uint64(cgroup.Resources.BlkioWeight), 10)); err != nil {
|
||||||
|
// 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
|
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 {
|
for _, td := range cgroup.Resources.BlkioThrottleReadBpsDevice {
|
||||||
if err := fscommon.WriteFile(dirPath, "io.max", td.StringName("rbps")); err != nil {
|
if err := fscommon.WriteFile(dirPath, "io.max", td.StringName("rbps")); err != nil {
|
||||||
|
|||||||
@@ -439,3 +439,14 @@ func ConvertMemorySwapToCgroupV2Value(memorySwap, memory int64) (int64, error) {
|
|||||||
|
|
||||||
return memorySwap - memory, nil
|
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)
|
||||||
|
}
|
||||||
|
|||||||
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -195,8 +195,12 @@ function setup() {
|
|||||||
[ "$status" -eq 0 ]
|
[ "$status" -eq 0 ]
|
||||||
|
|
||||||
runc exec test_cgroups_unified sh -c 'cat /sys/fs/cgroup/io.bfq.weight'
|
runc exec test_cgroups_unified sh -c 'cat /sys/fs/cgroup/io.bfq.weight'
|
||||||
[ "$status" -eq 0 ]
|
if [[ "$status" -eq 0 ]]; then
|
||||||
[ "$output" = 'default 750' ]
|
[ "$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)" {
|
@test "runc run (cgroup v2 resources.unified only)" {
|
||||||
|
|||||||
Reference in New Issue
Block a user