Skip to content

Commit

Permalink
libct/cg/fs2: set io weight if possible
Browse files Browse the repository at this point in the history
Per-device weight is supported since kernel v5.4 (kernel commit
795fe54c2a8), so let's set those if supplied.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
  • Loading branch information
kolyshkin committed Jun 11, 2021
1 parent f454bb1 commit 8271ed2
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions libcontainer/cgroups/fs2/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 8271ed2

Please sign in to comment.