Repository navigation
feat(youki): support --cpuset-cpus and --cpuset-mems in youki update - #3921
Merged
Merged
Conversation
liboci-cli already parses both flags, but update() never read them, so the command exited 0 and changed nothing. Build a LinuxCpu from the two flags and pass it to the cgroup manager. An empty value means the flag was not given, as in runc, so a flag that is not given leaves its value alone. The contest test starts from cpuset.cpus 0, moves it to 1 with the flag, then sets cpuset.mems, and checks that an empty value changes nothing. Signed-off-by: Asifur Rahaman Meeru <asifur.rahaman@meeru.dev>
The systemd driver sent CPUQuotaPerSecUSec=infinity and CPUQuotaPeriodUSec=100ms whenever resources.cpu was set, even when it carried neither a quota nor a period. An update with only cpus or mems therefore reset an existing quota: cpu.max went from "50000 200000" to "max 100000". Send the two properties only when a quota or a period is given. runc does the same in addCPUQuota. Signed-off-by: Asifur Rahaman Meeru <asifur.rahaman@meeru.dev>
ARMeeru
marked this pull request as draft
November 22, 2026 17:03
ARMeeru
marked this pull request as ready for review
November 22, 2026 17:25
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
There are no active review issues for the cpuset update and systemd quota-preservation changes.
No open issues 🎉
What changed in this PR
This PR connects youki update’s cpuset flags to the existing cgroup resource update flow, addressing #3677. It also prevents cpuset-only updates through the systemd driver from resetting an existing CPU quota or period.
Changes:
- Apply
--cpuset-cpusand--cpuset-mems, treating empty values as omitted. - Send systemd quota and period properties only when either value is specified.
- Add unit and integration coverage for cpuset updates and empty-value behavior.
| File | Description |
|---|---|
tests/contest/contest/src/tests/update/mod.rs |
Registers the cpuset CLI integration test. |
tests/contest/contest/src/tests/update/cpuset.rs |
Tests cpuset flags, preservation of unrelated values, and empty-value no-ops. |
crates/youki/src/commands/update.rs |
Builds CPU resources from cpuset flags and adds unit tests. |
crates/libcgroups/src/systemd/cpu.rs |
Guards quota and period updates and adds a regression test. |
Review effort: Balanced
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
youki update --cpuset-cpusand--cpuset-memswere parsed and then ignored: the command exited 0 and changed nothing. This PR passes them to the cgroup manager. An empty value means the flag was not given, as in runc.The second commit is a fix in the systemd driver that this feature needs.
systemd/cpu.rssentCPUQuotaPerSecUSec=infinityandCPUQuotaPeriodUSec=100mswheneverresources.cpuwas set, even with no quota and no period in it. So with--systemd-cgroup, a cpuset-only update reset an existing quota. Measured as root on systemd 262:cpu.maxbeforeupdate --cpuset-cpus 0-150000 200000max 10000050000 20000050000 20000050000 20000050000 200000The same reset is already reachable on main with
update -rand{"cpu":{"cpus":"0-1"}}. The flag only makes it easy to hit, so I did not want to add the flag without the fix. It is the same kind of reset @utam0k pointed out on #3683. The driver now sends the two properties only when a quota or a period is given, which is what runc'saddCPUQuotadoes.This overlaps with #3711 only at the edge: that issue covers what goes wrong when quota or period is given (one resetting the other, the period lost after unsetting the quota, rounding) and the burst and idle flags, and this guard covers only the case where neither is given. If you would rather have it there, I can drop the second commit.
For create, the guard changes nothing when the spec sets a quota or a period. With shares only or cpuset only,
CPUQuotaPeriodUSecis now left unset on the unit instead of being set to 100ms.cpu.maxis the same (max 100000), and for shares only that is also what runc leaves on the unit.Type of Change
Testing
The new contest test
update_cpuset_parameters_via_cli_flags_testis not a port of a bats test. Like the blkio one in #3698, it uses the flag, starts from a non-default value (cpuset.cpus0) and covers the no-op value (an empty string).cpuset.memsstarts unset and is set to 0, so it is a real change on a host with one memory node too.As root with the cgroupfs driver (aarch64, kernel 7.3, cgroup v2), main (dd0f30c) fails it with
cpuset.cpus: expected 1, got 0, and so does this branch withoutbuilder = builder.cpu(cpuset). With this change theupdategroup passes 9/9 (7 skipped for youki, as on main). With runc 1.5.3 (RUNTIME_KIND=runc) it passes 16/16.Without the guard, the new unit test
test_cpuset_only_keeps_quota_and_periodfails on!properties.contains_key(CPU_QUOTA).Manual check of the systemd driver, as root: create with
--systemd-cgroupand"cpu":{"quota":50000,"period":200000}, runupdate --cpuset-cpus 0-1, then readcpu.max,cpuset.cpus.effectiveandsystemctl show -p CPUQuotaPerSecUSec -p AllowedCPUs <unit>. Rootless, the user manager here does not delegate cpuset, andyouki update --systemd-cgroupexits 1 on main too, from the devices controller (Failed to increase rlimit), so a rootless run only shows that the quota is kept.Related Issues
Fixes #3677
Additional Context
LinuxCpuinupdate()and callsbuilder.cpu(..). A second call replaces the first, so whichever PR lands second has to fold both into oneLinuxCpu. I will rebase if feat(update): wire CPU period/quota/share into update, support negative quota #3683 goes first.build_cpusetdoes not depend on where it is.--systemd-cgroup, a CPU the host does not have (--cpuset-cpus 64) exits 0 and only setsAllowedCPUs, because the systemd driver does not writecpuset.cpusitself. runc's does, and errors. This is not specific to the flags (update -rtakes the same path), so I left it out of this PR.