Skip to content

Exclude cgroup implementation from non-Linux Unix builds - #126738

Merged
jkotas merged 7 commits into
mainfrom
copilot/exclude-cgroup-variants-non-linux
Apr 20, 2026
Merged

jkotas merged 7 commits into
mainfrom
copilot/exclude-cgroup-variants-non-linux

Conversation

Copilot AI commented Apr 10, 2026 •

Copy link
Copy Markdown
Contributor

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
@github-actions github-actions Bot added the area-PAL-coreclr only for closed issues label Apr 10, 2026
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
Comment thread src/coreclr/pal/src/misc/cgroup.cpp Resolved
Copilot AI requested review from Copilot and removed request for Copilot April 10, 2026 01:58
Comment thread src/coreclr/gc/unix/cgroup.cpp Resolved
Comment thread src/coreclr/pal/src/misc/cgroup.cpp Resolved
Comment thread src/coreclr/gc/unix/cgroup.cpp Resolved
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
Comment thread src/coreclr/gc/unix/cgroup.cpp Resolved
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
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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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.

Comment thread src/coreclr/pal/src/misc/cgroup.cpp Resolved
Comment thread src/coreclr/gc/unix/cgroup.cpp Resolved
@jkotas

jkotas commented Apr 18, 2026

Copy link
Copy Markdown
Member

@janvorli PTLA

@janvorli janvorli 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

@jkotas
jkotas merged commit 7e14c35 into main Apr 20, 2026
109 of 113 checks passed
@jkotas
jkotas deleted the copilot/exclude-cgroup-variants-non-linux branch April 20, 2026 15:41
@github-actions github-actions Bot locked and limited conversation to collaborators May 21, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-PAL-coreclr only for closed issues

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.

4 participants