Skip to content

core/cgroup: fix TasksMaxScale percentage serialization - #41011

Merged
yuwata merged 1 commit into
systemd:mainfrom
Cyrus-Xi:patch-1
Mar 10, 2026
Merged

yuwata merged 1 commit into
systemd:mainfrom
Cyrus-Xi:patch-1

Conversation

@Cyrus-Xi

@Cyrus-Xi Cyrus-Xi commented Mar 9, 2026 •

Copy link
Copy Markdown
Contributor

bus_cgroup_set_tasks_max_scale() uses a hand-rolled percentage format that produces values ~10x too
small (e.g., TasksMax=4.0% instead of TasksMax=40.00%).

The function computes whole-percent values (scaled = v * 100 / UINT32_MAX) but the format string
treats them as tenths-of-percent (scaled/10 . scaled%10). On daemon-reload, the incorrect value is
re-read, silently reducing the effective TasksMax by ~5-10x.

Fix by replacing with UINT32_SCALE_TO_PERMYRIAD() + PERMYRIAD_AS_PERCENT_FORMAT_STR, matching
BUS_DEFINE_SET_CGROUP_LIMIT.

Fixes #41009

(Note: This PR was developed with AI assistance (Claude Code).)

@github-actions github-actions Bot added the please-review PR is ready for (re-)review by a maintainer label Mar 9, 2026
@daandemeyer

Copy link
Copy Markdown
Collaborator

@claude review

Comment thread src/core/dbus-cgroup.c Resolved
@github-actions

github-actions Bot commented Mar 9, 2026

Copy link
Copy Markdown

Claude review of PR #41011 (f0dbd84)

The fix is correct. The old code computed scaled = v * 100 / UINT32_MAX (range 0–100) then formatted as scaled/10 . scaled%10 %, which is off by 10× (e.g. 50% → "5.0%"). The new code replaces this with UINT32_SCALE_TO_PERMYRIAD + PERMYRIAD_AS_PERCENT_FORMAT_STR, exactly matching the pattern used by BUS_DEFINE_SET_CGROUP_LIMIT for memory properties. The name suffix-stripping approach is also an improvement over the old hardcoded "TasksMax" string.

CI: all completed checks pass; build test, mkosi, CodeQL, and CIFuzz still in progress.

Nits

  • Trailing whitespace on blank line — src/core/dbus-cgroup.c:1015 — blank line between assert_se and int scaled has trailing spaces

@daandemeyer

Copy link
Copy Markdown
Collaborator

@Cyrus-Xi please add a test to test/units/TEST-19-CGROUP.sh

@github-actions github-actions Bot added the tests label Mar 9, 2026
@ikruglov

ikruglov commented Mar 9, 2026

Copy link
Copy Markdown
Member

@Cyrus-Xi please squash all commits into one.

@Cyrus-Xi

Cyrus-Xi commented Mar 9, 2026 •

Copy link
Copy Markdown
Contributor Author

added test and squashed commits into 1

edit: made executable to fix failing CI

@Cyrus-Xi
Cyrus-Xi force-pushed the patch-1 branch 2 times, most recently from 9df1b5f to 635f004 Compare March 9, 2026 20:34
Comment thread src/core/dbus-cgroup.c Resolved
@yuwata yuwata added pid1 reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks and removed please-review PR is ready for (re-)review by a maintainer labels Mar 10, 2026
  bus_cgroup_set_tasks_max_scale() used a hand-rolled percentage format
  that produced values ~10x too small (e.g., "TasksMax=4.0%" instead of
  "TasksMax=40.00%").

  On daemon-reload, the incorrect value was re-read, silently reducing
  the effective TasksMax by ~10x and causing fork rejections on systems
  with high thread counts.

  Fix by using the existing PERMYRIAD macros, consistent with memory
  property handlers (MemoryMax, MemoryHigh, MemoryLow, etc.).

  Fixes: systemd#41009
@github-actions github-actions Bot added please-review PR is ready for (re-)review by a maintainer and removed reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks labels Mar 10, 2026
@Cyrus-Xi
Cyrus-Xi requested a review from yuwata March 10, 2026 01:52

@yuwata yuwata left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM.

@claude review.

@yuwata yuwata added good-to-merge/waiting-for-ci 👍 PR is good to merge, but CI hasn't passed at time of review. Please merge if you see CI has passed and removed please-review PR is ready for (re-)review by a maintainer labels Mar 10, 2026
@yuwata

yuwata commented Mar 10, 2026 •

Copy link
Copy Markdown
Member

Hmm, the commit message has spurious indent. Let's fix it on merge (by using squash merge).

@yuwata
yuwata merged commit 9d15e09 into systemd:main Mar 10, 2026
55 of 57 checks passed
@yuwata yuwata mentioned this pull request Mar 10, 2026
@github-actions github-actions Bot removed the good-to-merge/waiting-for-ci 👍 PR is good to merge, but CI hasn't passed at time of review. Please merge if you see CI has passed label Mar 10, 2026
@Cyrus-Xi
Cyrus-Xi deleted the patch-1 branch March 10, 2026 23:48
keszybz pushed a commit to keszybz/systemd that referenced this pull request Mar 11, 2026
bus_cgroup_set_tasks_max_scale() used a hand-rolled percentage format
that produced values ~10x too small (e.g., "TasksMax=4.0%" instead of
"TasksMax=40.00%").

On daemon-reload, the incorrect value was re-read, silently reducing
the effective TasksMax by ~10x and causing fork rejections on systems
with high thread counts.

Fix by using the existing PERMYRIAD macros, consistent with memory
property handlers (MemoryMax, MemoryHigh, MemoryLow, etc.).

Fixes: systemd#41009
(cherry picked from commit 9d15e09)
keszybz pushed a commit to keszybz/systemd that referenced this pull request Mar 11, 2026
bus_cgroup_set_tasks_max_scale() used a hand-rolled percentage format
that produced values ~10x too small (e.g., "TasksMax=4.0%" instead of
"TasksMax=40.00%").

On daemon-reload, the incorrect value was re-read, silently reducing
the effective TasksMax by ~10x and causing fork rejections on systems
with high thread counts.

Fix by using the existing PERMYRIAD macros, consistent with memory
property handlers (MemoryMax, MemoryHigh, MemoryLow, etc.).

Fixes: systemd#41009
(cherry picked from commit 9d15e09)
keszybz pushed a commit that referenced this pull request Mar 12, 2026
bus_cgroup_set_tasks_max_scale() used a hand-rolled percentage format
that produced values ~10x too small (e.g., "TasksMax=4.0%" instead of
"TasksMax=40.00%").

On daemon-reload, the incorrect value was re-read, silently reducing
the effective TasksMax by ~10x and causing fork rejections on systems
with high thread counts.

Fix by using the existing PERMYRIAD macros, consistent with memory
property handlers (MemoryMax, MemoryHigh, MemoryLow, etc.).

Fixes: #41009
(cherry picked from commit 9d15e09)
bluca pushed a commit to bluca/systemd that referenced this pull request Mar 12, 2026
bus_cgroup_set_tasks_max_scale() used a hand-rolled percentage format
that produced values ~10x too small (e.g., "TasksMax=4.0%" instead of
"TasksMax=40.00%").

On daemon-reload, the incorrect value was re-read, silently reducing
the effective TasksMax by ~10x and causing fork rejections on systems
with high thread counts.

Fix by using the existing PERMYRIAD macros, consistent with memory
property handlers (MemoryMax, MemoryHigh, MemoryLow, etc.).

Fixes: systemd#41009
(cherry picked from commit 9d15e09)
(cherry picked from commit 7102649)
bluca pushed a commit that referenced this pull request Mar 12, 2026
bus_cgroup_set_tasks_max_scale() used a hand-rolled percentage format
that produced values ~10x too small (e.g., "TasksMax=4.0%" instead of
"TasksMax=40.00%").

On daemon-reload, the incorrect value was re-read, silently reducing
the effective TasksMax by ~10x and causing fork rejections on systems
with high thread counts.

Fix by using the existing PERMYRIAD macros, consistent with memory
property handlers (MemoryMax, MemoryHigh, MemoryLow, etc.).

Fixes: #41009
(cherry picked from commit 9d15e09)
(cherry picked from commit 7102649)
bluca pushed a commit to bluca/systemd that referenced this pull request Mar 12, 2026
bus_cgroup_set_tasks_max_scale() used a hand-rolled percentage format
that produced values ~10x too small (e.g., "TasksMax=4.0%" instead of
"TasksMax=40.00%").

On daemon-reload, the incorrect value was re-read, silently reducing
the effective TasksMax by ~10x and causing fork rejections on systems
with high thread counts.

Fix by using the existing PERMYRIAD macros, consistent with memory
property handlers (MemoryMax, MemoryHigh, MemoryLow, etc.).

Fixes: systemd#41009
(cherry picked from commit 9d15e09)
(cherry picked from commit 7102649)
(cherry picked from commit 8498799)
bluca pushed a commit to bluca/systemd that referenced this pull request Mar 12, 2026
bus_cgroup_set_tasks_max_scale() used a hand-rolled percentage format
that produced values ~10x too small (e.g., "TasksMax=4.0%" instead of
"TasksMax=40.00%").

On daemon-reload, the incorrect value was re-read, silently reducing
the effective TasksMax by ~10x and causing fork rejections on systems
with high thread counts.

Fix by using the existing PERMYRIAD macros, consistent with memory
property handlers (MemoryMax, MemoryHigh, MemoryLow, etc.).

Fixes: systemd#41009
(cherry picked from commit 9d15e09)
(cherry picked from commit 7102649)
(cherry picked from commit 8498799)
bluca pushed a commit that referenced this pull request Mar 12, 2026
bus_cgroup_set_tasks_max_scale() used a hand-rolled percentage format
that produced values ~10x too small (e.g., "TasksMax=4.0%" instead of
"TasksMax=40.00%").

On daemon-reload, the incorrect value was re-read, silently reducing
the effective TasksMax by ~10x and causing fork rejections on systems
with high thread counts.

Fix by using the existing PERMYRIAD macros, consistent with memory
property handlers (MemoryMax, MemoryHigh, MemoryLow, etc.).

Fixes: #41009
(cherry picked from commit 9d15e09)
(cherry picked from commit 7102649)
(cherry picked from commit 8498799)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

bus_cgroup_set_tasks_max_scale: TasksMax percentage serialized 5-10x too low due to units mismatch

5 participants