Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not convert blkio weight value using blkio->io conversion scheme #2786

Merged
merged 1 commit into from
Feb 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libcontainer/cgroups/fs2/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func setIo(dirPath string, cgroup *configs.Cgroup) error {
if cgroup.Resources.BlkioWeight != 0 {
filename := "io.bfq.weight"
if err := fscommon.WriteFile(dirPath, filename,
strconv.FormatUint(cgroups.ConvertBlkIOToCgroupV2Value(cgroup.Resources.BlkioWeight), 10)); err != nil {
strconv.FormatUint(uint64(cgroup.Resources.BlkioWeight), 10)); err != nil {
return err
}
}
Expand Down
11 changes: 0 additions & 11 deletions libcontainer/cgroups/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,17 +400,6 @@ func WriteCgroupProc(dir string, pid int) error {
return err
}

// 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 is y = (1 + (x - 10) * 9999 / 990)
// convert linearly from [10-1000] to [1-10000]
func ConvertBlkIOToCgroupV2Value(blkIoWeight uint16) uint64 {
if blkIoWeight == 0 {
return 0
}
return uint64(1 + (uint64(blkIoWeight)-10)*9999/990)
}

// 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 cpuShares is y = (1 + ((x - 2) * 9999) / 262142)
Expand Down
14 changes: 0 additions & 14 deletions libcontainer/cgroups/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -548,20 +548,6 @@ func TestGetHugePageSizeImpl(t *testing.T) {
}
}

func TestConvertBlkIOToCgroupV2Value(t *testing.T) {
cases := map[uint16]uint64{
0: 0,
10: 1,
1000: 10000,
}
for i, expected := range cases {
got := ConvertBlkIOToCgroupV2Value(i)
if got != expected {
t.Errorf("expected ConvertBlkIOToCgroupV2Value(%d) to be %d, got %d", i, expected, got)
}
}
}

func TestConvertCPUSharesToCgroupV2Value(t *testing.T) {
cases := map[uint64]uint64{
0: 0,
Expand Down
14 changes: 14 additions & 0 deletions tests/integration/cgroups.bats
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,20 @@ function setup() {
[[ "$output" == *'invalid configuration'* ]]
}

@test "runc run (blkio weight)" {
requires root cgroups_v2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't require root?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AkihiroSuda once #2818 is merged we will be able to enable it (rm root, add [[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...because currently runc exec test_cgroups_unified sh -c 'cat /sys/fs/cgroup/io.bfq.weight' is not working


set_cgroups_path "$BUSYBOX_BUNDLE"
update_config '.linux.resources.blockIO |= {"weight": 750}' "${BUSYBOX_BUNDLE}"

runc run -d --console-socket "$CONSOLE_SOCKET" test_cgroups_unified
[ "$status" -eq 0 ]

runc exec test_cgroups_unified sh -c 'cat /sys/fs/cgroup/io.bfq.weight'
[ "$status" -eq 0 ]
[ "$output" = 'default 750' ]
}

@test "runc run (cgroup v2 resources.unified only)" {
requires root cgroups_v2

Expand Down