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

systemd driver updates CPU quota inconsitently #4622

Open
hshiina opened this issue Feb 10, 2025 · 3 comments · May be fixed by opencontainers/cgroups#4
Open

systemd driver updates CPU quota inconsitently #4622

hshiina opened this issue Feb 10, 2025 · 3 comments · May be fixed by opencontainers/cgroups#4

Comments

@hshiina
Copy link

hshiina commented Feb 10, 2025

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

@rata
Copy link
Member

rata commented Feb 20, 2025

@hshiina thanks for the report! I'm currently super busy with some k8s deadlines. But you got quite into the code already, wanna try to open a PR to fix this too? ;)

@hshiina
Copy link
Author

hshiina commented Feb 21, 2025

@hshiina thanks for the report! I'm currently super busy with some k8s deadlines. But you got quite into the code already, wanna try to open a PR to fix this too? ;)

Sure. I will try to post a PR.
/assign

@rata
Copy link
Member

rata commented Feb 21, 2025

Feel free to cc me in the PR :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants