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

Đang mở
#16,753 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@Srizdebnath đang làm issue này rồi.

Từ ngày 21/11/2026.

  • #16754 của @Srizdebnath — đang mở

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
32/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
linux, rust
Lĩnh vực
operating-systems

Hướng nghiên cứu

Start from cgroups2_quota, which takes split(':').nth(2) of /proc/self/cgroup — a path containing a colon is truncated there, so cpu.max is never found. Fix the path extraction (split on the first two fields only), then walk from the leaf cgroup up through its ancestors reading each cpu.max and keep the smallest quota, as GNU does. Verify with the two systemd-run/systemctl --user set-property repros in the issue: the colon case must print 2 and the nested-quota case 1 on a 4-CPU box. Note a linked PR #16754 is already open, so coordinate before starting.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

U - nproc

nproc misses cgroup v2 CPU quotas in two cases where GNU honors them.

1. The cgroup path contains a :

cgroups2_quota takes split(':').nth(2) of /proc/self/cgroup, so a path such as 0::/user.slice/.../app-dbus\x2d:1.3\x2dorg.gnome.Console.slice/vte-spawn-....scope (the default for a GNOME Console terminal) is cut at the colon, cpu.max is not found, and the quota is ignored.

$ systemd-run --user --scope -q --unit='nq:colon' -p CPUQuota=200% sh -c 'nproc; ./target/debug/nproc'
2      # GNU 9.11
4      # uutils

2. The quota is set on an ancestor cgroup

Only the process's own cpu.max is read. A quota on a parent slice also limits the process, and GNU uses the smallest quota along the path:

$ systemctl --user set-property --runtime nq.slice CPUQuota=150%
$ systemd-run --user --scope -q --slice=nq.slice sh -c 'nproc; ./target/debug/nproc'
2      # GNU
4      # uutils
$ systemctl --user set-property --runtime nq.slice CPUQuota=100%
$ systemd-run --user --scope -q --slice=nq.slice -p CPUQuota=300% sh -c 'nproc; ./target/debug/nproc'
1      # GNU
3      # uutils

(4 CPUs, cgroup v2, GNU coreutils 9.11.)

Ngôn ngữ chính
Rust
Star
24.4k
Fork
2.2k
Merge trung bình
2 ngày 23 giờ
Pull request đã merge (30 ngày)
402

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của uutils/coreutils

Tất cả issue của uutils/coreutils

Issue tương tự

Thêm issue về Rust

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.