Exclude cgroup implementation from non-Linux Unix builds#126738
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>
…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>
src/coreclr/gc/unix/cgroup.cpp
Outdated
|
|
||
| size_t GetRestrictedPhysicalMemoryLimit() | ||
| { | ||
| #if defined(TARGET_LINUX) || defined(TARGET_ANDROID) |
There was a problem hiding this comment.
@copilot Merge these ifdefs so that there is one big ifdef over the whole file, duplicate the method implementations as needed.
There was a problem hiding this comment.
Done in da6f367 — GetRestrictedPhysicalMemoryLimit and GetPhysicalMemoryUsed are now inside the single #if defined(TARGET_LINUX) || defined(TARGET_ANDROID) block, with stub implementations (return 0 / return false) in the #else branch. There are no more inner ifdefs in the file.
…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>
…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>
| @@ -10,31 +10,24 @@ Module Name: | |||
| Abstract: | |||
| Read cpu limits for the current process | |||
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).
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. |
| BOOL | ||
| PALAPI | ||
| PAL_GetCpuLimit(UINT* val) | ||
| { |
There was a problem hiding this comment.
In the non-Linux/Android stub implementation, val is unused. With common Unix build flags (e.g., -Wunused-parameter/-Werror), this can produce a build break. Consider explicitly marking it unused (e.g., casting to void or using the project’s unused-parameter macro) before returning FALSE.
| { | |
| { | |
| (void)val; |
| } | ||
|
|
||
| bool GetCpuLimit(uint32_t* val) | ||
| { |
There was a problem hiding this comment.
In the non-Linux/Android stub, val is unused. This can trigger -Wunused-parameter warnings (and potentially -Werror failures) on non-Linux Unix builds. Mark the parameter as unused (e.g., (void)val; / UNREFERENCED_PARAMETER(val)) in the stub implementation.
| { | |
| { | |
| (void)val; |
| } | ||
|
|
||
| bool GetPhysicalMemoryUsed(size_t* val) | ||
| { |
There was a problem hiding this comment.
In the non-Linux/Android stub, val is unused. This can trigger -Wunused-parameter warnings (and potentially -Werror failures) on macOS/FreeBSD builds—the primary targets of this change. Mark the parameter as unused in the stub (e.g., cast to void / use the project’s unused-parameter macro).
| { | |
| { | |
| (void)val; |
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