Skip to content

Cpu pressure#9

Open
daandemeyer wants to merge 7 commits intomainfrom
cpu-pressure
Open

Cpu pressure#9
daandemeyer wants to merge 7 commits intomainfrom
cpu-pressure

Conversation

@daandemeyer
Copy link
Copy Markdown
Owner

No description provided.

@daandemeyer
Copy link
Copy Markdown
Owner Author

@claude review

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 18, 2026

Claude review of PR #9 (dcdf8a8)

<!-- claude-pr-review -->

This PR extends the existing memory pressure monitoring infrastructure in sd-event and PID 1 to also support CPU and IO pressure, using Linux's PSI (Pressure Stall Information) interface. The refactoring approach is clean — the memory-pressure-specific code is generalized to work with a PressureResource enum, reducing duplication across all three resource types.

The PR is well structured across 7 commits:

  1. Test macro migration (prep work)
  2. Unprivileged test support (prep work)
  3. sd-event CPU pressure API
  4. PID 1 / core CPU pressure support
  5. IO pressure support (sd-event + core)
  6. Documentation update (MEMORY_PRESSURE.md → PRESSURE.md)
  7. Minor docs fix

Overall the code quality is high and the generalization is done consistently.

Suggestions

  • CPU auto mode missing cpu_accounting check (dismissed) — src/core/cgroup.hcgroup_context_want_pressure(PRESSURE_CPU) doesn't check c->cpu_accounting, unlike the memory and IO variants. The docs say auto enables "if CPU accounting is anyway enabled", but CPUAccounting=true alone won't trigger it.
  • Missing sanitize_environment entries for CPU/IO pressuresrc/core/manager.csanitize_environment() strips MEMORY_PRESSURE_WATCH/MEMORY_PRESSURE_WRITE but does not strip the corresponding CPU_PRESSURE_WATCH/CPU_PRESSURE_WRITE/IO_PRESSURE_WATCH/IO_PRESSURE_WRITE env vars. If PID 1 inherits these from its environment, they could leak into services.

Nits

  • Parser function namingsrc/core/load-fragment-gperf.gperf.inconfig_parse_memory_pressure_watch is reused for CPU/IO but the name still says "memory"
  • Unused callback parameter in test wrapperssrc/test/test-pressure.c — The wrapper functions ignore the callback parameter passed to them
  • Stale comment in cgroup.csrc/core/cgroup.c:2123 — Comment still says "try to open the memory pressure interface anew" but the code now sets up all pressure resource types
  • IO test file not cleaned upsrc/test/test-pressure.c:496/var/tmp/.io-pressure-test is created during the IO pressure test but never cleaned up afterward

<!-- claude-pr-review -->

Workflow run

@daandemeyer
Copy link
Copy Markdown
Owner Author

@claude review

1 similar comment
@daandemeyer
Copy link
Copy Markdown
Owner Author

@claude review

@daandemeyer
Copy link
Copy Markdown
Owner Author

@claude review

@@ -2110,7 +2116,8 @@ static int unit_update_cgroup(
* that PID 1 runs before init.scope is even set up. Hence, whenever init.scope is realized, let's
* try to open the memory pressure interface anew. */
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude: nit: Stale comment: "try to open the memory pressure interface anew" should be updated to reflect that this now sets up all pressure resource types (memory, CPU, and IO), e.g. "try to open the pressure interfaces anew".

for (;;) {
_cleanup_close_ int fd = -EBADF;

fd = open("/var/tmp/.io-pressure-test", O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC, 0600);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude: nit: /var/tmp/.io-pressure-test is created by the IO pressure child process but never cleaned up after the test (e.g., in outro() or via _cleanup_). Consider adding (void) unlink("/var/tmp/.io-pressure-test"); to the test cleanup.

@daandemeyer
Copy link
Copy Markdown
Owner Author

@claude review

{{type}}.MemoryPressureWatch, config_parse_memory_pressure_watch, 0, offsetof({{type}}, cgroup_context.pressure_watch[PRESSURE_MEMORY])
{{type}}.CPUPressureThresholdSec, config_parse_sec, 0, offsetof({{type}}, cgroup_context.pressure_threshold_usec[PRESSURE_CPU])
{{type}}.CPUPressureWatch, config_parse_memory_pressure_watch, 0, offsetof({{type}}, cgroup_context.pressure_watch[PRESSURE_CPU])
{{type}}.NFTSet, config_parse_cgroup_nft_set, NFT_SET_PARSE_CGROUP, offsetof({{type}}, cgroup_context)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude: nit: config_parse_memory_pressure_watch is reused for CPUPressureWatch and IOPressureWatch, but the function name still says "memory". Consider renaming it to config_parse_pressure_watch for consistency, since it now handles all pressure resource types.

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.

1 participant