Exclude cgroup implementation from non-Linux Unix builds#126738
Open
Exclude cgroup implementation from non-Linux Unix builds#126738
Conversation
…GET_ANDROID guards Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/bd7043b4-36df-4c0e-ad58-eb91a492b4ae Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Exclude all cgroup.cpp variants from build on non-linux Unix OSes
Exclude cgroup implementation from non-Linux Unix builds
Apr 10, 2026
jkotas
reviewed
Apr 10, 2026
…DROID guard Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/cd431f58-bda0-4629-a53c-621508e2df8b Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
jkotas
reviewed
Apr 10, 2026
jkotas
reviewed
Apr 10, 2026
jkotas
reviewed
Apr 10, 2026
…Limit and GetPhysicalMemoryUsed in gc/unix/cgroup.cpp Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/d2623ab2-097f-49ca-b51a-2e9ab2cba834 Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
jkotas
reviewed
Apr 10, 2026
…nditional ifdefs in all cgroup files Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/e040e085-21b6-41eb-abf7-86e5718740f8 Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
…in gc/unix/cgroup.cpp Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/ee4e840a-c95a-429b-ae39-f6218c0f9540 Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
jkotas
approved these changes
Apr 10, 2026
jkotas
reviewed
Apr 10, 2026
| @@ -10,31 +10,24 @@ Module Name: | |||
| Abstract: | |||
| Read cpu limits for the current process | |||
Member
There was a problem hiding this comment.
It would be nice to dedup these files too, not doing that in this PR (we have separate issue for that).
Contributor
There was a problem hiding this comment.
Pull request overview
This PR removes cgroup implementation code from non-Linux Unix builds by gating the cgroup logic behind a single #if defined(TARGET_LINUX) || defined(TARGET_ANDROID) in each cgroup implementation, leaving lightweight stubs for other platforms.
Changes:
- Wrapped PAL, GC, and NativeAOT cgroup implementations in a top-level Linux/Android-only preprocessor guard.
- Removed non-Linux include/implementation branches and simplified cgroup version detection to an unconditional
statfs("/sys/fs/cgroup", ...)on Linux/Android. - Added non-Linux/Android stub implementations for the public entrypoints.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/coreclr/pal/src/misc/cgroup.cpp | PAL cgroup CPU limit implementation now Linux/Android-only with non-Linux stubs. |
| src/coreclr/nativeaot/Runtime/unix/cgroupcpu.cpp | NativeAOT cgroup CPU limit implementation now Linux/Android-only with non-Linux stubs. |
| src/coreclr/gc/unix/cgroup.cpp | GC cgroup memory/usage implementation now Linux/Android-only with non-Linux stubs. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
cgroup code was being compiled and linked on macOS and FreeBSD even though cgroups are a Linux-specific mechanism. While this caused no runtime harm (functions returned 0/false due to missing
/sys/fs/cgroup), the code was dead weight on those platforms.Fixes #99363