Skip to content

Conversion of cgroup v1 CPU shares to v2 CPU weight causes workloads to have low CPU priority #4772

@mwek

Description

@mwek

Description

In cgroup v1, the default CPU shares is 1024.
In cgroup v2, the default CPU weight is 100.

When creating a container with 1024 CPU shares, the current formula translates the value to 39, resulting in ~39% of the actual CPU weight it should receive.

To preserve the default values, we should use a different formula: CPUWeight = 1 + ((CPUShares – 2) * 99) / (1024 - 2)

Reference:

Steps to reproduce the issue

  1. container_id=$(docker run -d --cpu-shares 1024 ubuntu bash -c 'sleep infinity')
  2. cat /sys/fs/cgroup/system.slice/docker-${container_id}.scope/cpu.weight (prints 39)

Describe the results you received and expected

The CPU weight is returned as 39, where I expect it to return 100.

What version of runc are you using?

1.2.4

Host OS information

No response

Host kernel information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions