Skip to content

Exclude cgroup implementation from non-Linux Unix builds#126738

Open
Copilot wants to merge 6 commits intomainfrom
copilot/exclude-cgroup-variants-non-linux
Open

Exclude cgroup implementation from non-Linux Unix builds#126738
Copilot wants to merge 6 commits intomainfrom
copilot/exclude-cgroup-variants-non-linux

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 10, 2026

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

Copilot AI requested review from Copilot and removed request for Copilot April 10, 2026 01:17
Copilot AI linked an issue Apr 10, 2026 that may be closed by this pull request
…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 requested review from Copilot and removed request for Copilot April 10, 2026 01:47
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
Copilot AI requested a review from jkotas April 10, 2026 01:51
Copilot AI requested review from Copilot and removed request for Copilot April 10, 2026 01:58
…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>
Copilot AI requested review from Copilot and removed request for Copilot April 10, 2026 02:04
Copilot AI requested a review from jkotas April 10, 2026 02:05
…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>
Copilot AI requested review from Copilot and removed request for Copilot April 10, 2026 02:16
Copilot AI requested a review from jkotas April 10, 2026 02:18
…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>
Copilot AI requested review from Copilot and removed request for Copilot April 10, 2026 02:25
@jkotas jkotas marked this pull request as ready for review April 10, 2026 02:32
@jkotas jkotas requested review from Copilot and janvorli April 10, 2026 02:32
@jkotas jkotas closed this Apr 10, 2026
@jkotas jkotas reopened this Apr 10, 2026
@@ -10,31 +10,24 @@ Module Name:
Abstract:
Read cpu limits for the current process
Copy link
Copy Markdown
Member

@jkotas jkotas Apr 10, 2026

Choose a reason for hiding this comment

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

It would be nice to dedup these files too, not doing that in this PR (we have separate issue for that).

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exclude all cgroup.cpp variants from build on non-linux Unix OSes.

3 participants