Skip to content

feat(youki): support --cpuset-cpus and --cpuset-mems in youki update - #3921

Merged
nayuta723 merged 2 commits into
youki-dev:mainfrom
ARMeeru:feat/update-cpuset-flags
Nov 25, 2026
Merged

nayuta723 merged 2 commits into
youki-dev:mainfrom
ARMeeru:feat/update-cpuset-flags

Conversation

@ARMeeru

@ARMeeru ARMeeru commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Description

youki update --cpuset-cpus and --cpuset-mems were 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.rs sent CPUQuotaPerSecUSec=infinity and CPUQuotaPeriodUSec=100ms whenever resources.cpu was 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.max before after update --cpuset-cpus 0-1
first commit only 50000 200000 max 100000
both commits 50000 200000 50000 200000
runc 1.5.3 50000 200000 50000 200000

The same reset is already reachable on main with update -r and {"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's addCPUQuota does.

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, CPUQuotaPeriodUSec is now left unset on the unit instead of being set to 100ms. cpu.max is the same (max 100000), and for shares only that is also what runc leaves on the unit.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • Test updates
  • CI/CD related changes
  • Other (please describe):

Testing

  • Added new unit tests
  • Added new integration tests
  • Ran existing test suite
  • Tested manually (please provide steps)

The new contest test update_cpuset_parameters_via_cli_flags_test is not a port of a bats test. Like the blkio one in #3698, it uses the flag, starts from a non-default value (cpuset.cpus 0) and covers the no-op value (an empty string). cpuset.mems starts 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 without builder = builder.cpu(cpuset). With this change the update group 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_period fails on !properties.contains_key(CPU_QUOTA).

Manual check of the systemd driver, as root: create with --systemd-cgroup and "cpu":{"quota":50000,"period":200000}, run update --cpuset-cpus 0-1, then read cpu.max, cpuset.cpus.effective and systemctl show -p CPUQuotaPerSecUSec -p AllowedCPUs <unit>. Rootless, the user manager here does not delegate cpuset, and youki update --systemd-cgroup exits 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

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
ARMeeru marked this pull request as draft November 22, 2026 17:03
@ARMeeru
ARMeeru marked this pull request as ready for review November 22, 2026 17:25
@saku3 saku3 added the kind/bug label Nov 22, 2026
@saku3
saku3 requested a balanced review from Copilot November 22, 2026 23:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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-cpus and --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

@nayuta723 nayuta723 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nayuta723
nayuta723 merged commit bb3ebe6 into youki-dev:main Nov 25, 2026
35 of 36 checks passed
@youki-dev-bot youki-dev-bot Bot mentioned this pull request Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]: support --cpuset-cpus and --cpuset-mems in youki update

4 participants