diff --git a/libcontainer/cgroups/fs2/io.go b/libcontainer/cgroups/fs2/io.go index 77174f437fe..30011ab2e5a 100644 --- a/libcontainer/cgroups/fs2/io.go +++ b/libcontainer/cgroups/fs2/io.go @@ -17,6 +17,7 @@ import ( func isIoSet(r *configs.Resources) bool { return r.BlkioWeight != 0 || + len(r.BlkioWeightDevice) > 0 || len(r.BlkioThrottleReadBpsDevice) > 0 || len(r.BlkioThrottleWriteBpsDevice) > 0 || len(r.BlkioThrottleReadIOPSDevice) > 0 || @@ -28,9 +29,10 @@ func setIo(dirPath string, r *configs.Resources) error { return nil } + const bfqWeight = "io.bfq.weight" + if r.BlkioWeight != 0 { - filename := "io.bfq.weight" - if err := fscommon.WriteFile(dirPath, filename, + if err := fscommon.WriteFile(dirPath, bfqWeight, strconv.FormatUint(uint64(r.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 @@ -43,6 +45,16 @@ func setIo(dirPath string, r *configs.Resources) error { } } } + for _, wd := range r.BlkioWeightDevice { + // per-device weight is supported since kernel v5.4, commit 795fe54c2a8. + if err := fscommon.WriteFile(dirPath, bfqWeight, wd.WeightString()); err != nil { + if os.IsNotExist(err) { + // Kernel module bfq is not loaded -- ignore it. + break + } + return err + } + } for _, td := range r.BlkioThrottleReadBpsDevice { if err := fscommon.WriteFile(dirPath, "io.max", td.StringName("rbps")); err != nil { return err