Skip to content

systemd driver updates CPU quota inconsitently #4622

Open
@hshiina

Description

Description

When CPU quota is updated with fractions, cpu.max is updated as specified:

$ runc update container1 --cpu-quota=123456
$ cat /sys/fs/cgroup/system.slice/runc-container1.scope/cpu.max
123456 100000

However, after another parameter is updated, cpu.max is rounded up:

$ runc update container1 --memory 100000000
$ cat /sys/fs/cgroup/system.slice/runc-container1.scope/cpu.max
124000 100000

It looks the rounded value is passed to systemd:

// systemd converts CPUQuotaPerSecUSec (microseconds per CPU second) to CPUQuota
// (integer percentage of CPU) internally. This means that if a fractional percent of
// CPU is indicated by Resources.CpuQuota, we need to round up to the nearest
// 10ms (1% of a second) such that child cgroups can set the cpu.cfs_quota_us they expect.
cpuQuotaPerSecUSec = uint64(quota*1000000) / period
if cpuQuotaPerSecUSec%10000 != 0 {
cpuQuotaPerSecUSec = ((cpuQuotaPerSecUSec / 10000) + 1) * 10000
}

However, the original value seems to be written to the file:
return m.fsMgr.Set(r)

Steps to reproduce the issue

  1. Create a container with systemd driver:
    $ runc --systemd-cgroup run container1
    
  2. Update the CPU quota of the container with fraction:
    $ runc update container1 --cpu-quota=123456
    
  3. See cpu.max:
    $ cat /sys/fs/cgroup/system.slice/runc-container1.scope/cpu.max
    123456 100000
    
  4. Update another parameter of the container:
    $ runc update container1 --memory 100000000
    
  5. See cpu.max again:
    $ cat /sys/fs/cgroup/system.slice/runc-container1.scope/cpu.max
     124000 100000
    

We can see how the file is updated in the steps with tail -f:

$ tail -f  /sys/fs/cgroup/system.slice/runc-container1.scope/cpu.max
max 100000
tail: /sys/fs/cgroup/system.slice/runc-container1.scope/cpu.max: file truncated
max 100000
tail: /sys/fs/cgroup/system.slice/runc-container1.scope/cpu.max: file truncated
124000 100000
tail: /sys/fs/cgroup/system.slice/runc-container1.scope/cpu.max: file truncated
123456 100000
tail: /sys/fs/cgroup/system.slice/runc-container1.scope/cpu.max: file truncated
124000 100000

Describe the results you received and expected

The CPU quota should be configured consistently whether it is rounded up or not.

What version of runc are you using?

$ runc -v
runc version 1.2.4
commit: v1.2.4-0-g6c52b3f
spec: 1.2.0
go: go1.22.10
libseccomp: 2.5.5

Host OS information

No response

Host kernel information

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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