Skip to content

nproc: honor cgroup v2 quotas on ancestors and paths with ':' - #16754

Open
Srizdebnath wants to merge 1 commit into
uutils:mainfrom
Srizdebnath:nproc-cgroup-quota
Open

Srizdebnath wants to merge 1 commit into
uutils:mainfrom
Srizdebnath:nproc-cgroup-quota

Conversation

@Srizdebnath

Copy link
Copy Markdown

Fixes #16753.

cgroups2_quota had two gaps compared with GNU:

  • It took split(':').nth(2) of /proc/self/cgroup, which cuts a path containing : (the default GNOME Console scope, app-dbus\x2d:1.3\x2d...). It now uses everything after the 0:: prefix.
  • It only read the process's own cpu.max. It now walks up to /sys/fs/cgroup and takes the smallest quota, skipping levels with no cpu.max or a max quota. Rounding per level is unchanged.

The parsing and the walk take the file reader as a closure so they have unit tests without a real cgroup tree. Checked against GNU 9.11 with systemd-run --user:

setup GNU before after
scope nq:colon, CPUQuota=200% 2 4 2
parent 150%, leaf none 2 4 2
parent 100%, leaf 300% 1 3 1
parent 300%, leaf 100% 1 1 1
no quota 4 4 4

cargo test -p uu_nproc, test_nproc, fmt and clippy pass.

Read the cgroup v2 path from the "0::" line of /proc/self/cgroup instead
of splitting on every ':', and take the smallest cpu.max quota from the
process's cgroup up to the root, like GNU.

Fixes uutils#16753

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nproc: cgroup v2 quota ignored when the cgroup path contains ':' or the quota is on a parent cgroup

1 participant