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

runc update: cpu period and cpu burst being reset to defaults after an unrelated update #4225

Open
lifubang opened this issue Mar 17, 2024 · 8 comments

Comments

@lifubang
Copy link
Member

root@acmcoder:/home/acmcoder/ubuntutest# runc --systemd-cgroup run -d test
root@acmcoder:/home/acmcoder/ubuntutest# find /sys/fs/cgroup/ -name "*test*"
/sys/fs/cgroup/system.slice/runc-test.scope
root@acmcoder:/home/acmcoder/ubuntutest# cat /sys/fs/cgroup/system.slice/runc-test.scope/cpu.max
max 100000
root@acmcoder:/home/acmcoder/ubuntutest# runc --systemd-cgroup update --cpu-period 900000 test
root@acmcoder:/home/acmcoder/ubuntutest# cat /sys/fs/cgroup/system.slice/runc-test.scope/cpu.max
max 900000
root@acmcoder:/home/acmcoder/ubuntutest# runc --systemd-cgroup update --memory 500M test
root@acmcoder:/home/acmcoder/ubuntutest# cat /sys/fs/cgroup/system.slice/runc-test.scope/cpu.max
max 100000
root@acmcoder:/home/acmcoder/ubuntutest#
@lifubang
Copy link
Member Author

lifubang commented Mar 17, 2024

root@acmcoder:/home/acmcoder/ubuntutest# uname -a
Linux acmcoder 5.15.0-100-generic #110~20.04.1-Ubuntu SMP Tue Feb 13 14:25:03 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

@kolyshkin
Copy link
Contributor

AFAIK it does not make sense to set --cpu-period without --cpu-quota. And if you set cpu-quota, the bug is no longer reproducible.

To aid in debugging, I have used this patch

--- a/libcontainer/cgroups/systemd/v2.go
+++ b/libcontainer/cgroups/systemd/v2.go
@@ -278,6 +278,8 @@ func genV2ResourcesProperties(dirPath string, r *configs.Resources, cm *dbusConn
                properties = append(properties, unifiedProps...)
        }
 
+       logrus.Debugf("Properties: %+v", properties)
+
        return properties, nil
 }
 

Also, it makes sense to take a look at what systemd saves for the given unit:

$ tail /run/systemd/transient/runc-test.scope.d/*

==> /run/systemd/transient/runc-test.scope.d/50-CPUQuota.conf <==
# This is a drop-in unit file extension, created via "systemctl set-property"
# or an equivalent operation. Do not edit.
[Scope]
CPUQuota=100%

==> /run/systemd/transient/runc-test.scope.d/50-CPUQuotaPeriodSec.conf <==
# This is a drop-in unit file extension, created via "systemctl set-property"
# or an equivalent operation. Do not edit.
[Scope]
CPUQuotaPeriodSec=900ms
...

@kolyshkin
Copy link
Contributor

Maybe the solution to this issue is to disallow setting --cpu-period without setting --cpu-quota as they are inter-dependent.

@kolyshkin
Copy link
Contributor

Perhaps commit 32746fb is doing what it should do. Looking...

@kolyshkin
Copy link
Contributor

The problem is, with the current code it's impossible to distinguish between "unset" and "set to 0", thus the following code:

runc/update.go

Lines 294 to 298 in 18c313b

if (p == 0 && q == 0) || (p != 0 && q != 0) {
// both values are either set or unset (0)
config.Cgroups.Resources.CpuPeriod = p
config.Cgroups.Resources.CpuQuota = q
} else {

resets both quota and period.

Something like this commit from #4142 should fix this, although it needs to be reworked. Stay tuned.

@kolyshkin
Copy link
Contributor

Still, even with the fixed code, there is no way to know if period or quota were ever been set before.

So, the best way to solve this is to require cpu-period and cpu-quota to be set together (and possibly break backward compatibility).

The way to solve this without breaking backward compatibility is to assume period (or quota) is not set if it's 0 in state.json.

I'll try to come up with a PR.

@kolyshkin
Copy link
Contributor

Should be fixed in #4227

@kolyshkin kolyshkin changed the title Issue for resource limit set in cgroup v2(systemd driver) runc update: some resource limits (cpu period, cpu burst) being reset to default values Mar 19, 2024
@kolyshkin kolyshkin changed the title runc update: some resource limits (cpu period, cpu burst) being reset to default values runc update: cpu period and cpu burst being reset to defaults after an unrelated update Mar 19, 2024
@kolyshkin
Copy link
Contributor

There's a similar bug for cpu-burst (it is reset to 0 after some unrelated runc update).

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

No branches or pull requests

2 participants