Repository navigation
Deduplicate GC and PAL cgroup implementations - #137578
Conversation
|
Azure Pipelines: Successfully started running 4 pipeline(s). 11 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Move the cgroup CPU limit into `gc/unix/cgroup.cpp` next to the memory limit, sharing the cgroup discovery code, and move `GetCurrentProcessCpuCount` from `utilcode` to the VM so it can use it. Delete the PAL copy and `PAL_GetCpuLimit`. Move `PAL_GetTotalCpuCount` and `PAL_GetLogicalCpuCountFromOS` to minipal as `minipal_get_cpu_total_count` and `minipal_get_cpu_affinity_count`. Co-authored-by: Cursor <[email protected]>
3892422 to
7c3962c
Compare
`SimpleRWLock` is compiled into the DAC, which does not have `GetCurrentProcessCpuCount` now that it moved to the VM. Co-authored-by: Cursor <[email protected]>
|
Thanks for cleaning this up. This contributes to #99171. There is still a copy of this code in NativeAOT: https://github.com/dotnet/runtime/blob/main/src/coreclr/nativeaot/Runtime/unix/cgroupcpu.cpp |
Delete `nativeaot/Runtime/unix/cgroupcpu.cpp`. NativeAOT already compiles `gc/unix/cgroup.cpp`, and `GCToOSInterface::Initialize` initializes it. Co-authored-by: Cursor <[email protected]>
|
Good point, thanks. NativeAOT now uses the GC copy too, and |
There was a problem hiding this comment.
🔵 Needs a closer look
CPU-quota discovery now shares GC lifecycle state, requiring cgroup v1/v2 and CoreCLR/NativeAOT startup/shutdown validation that this source-only review could not perform.
No open issues 🎉
What changed in this PR
Consolidates Unix cgroup CPU-limit handling alongside the GC’s memory-limit implementation, removing duplicate PAL and NativeAOT code.
Changes:
- Shares cgroup discovery and CPU-quota queries between CoreCLR and NativeAOT.
- Moves process CPU-count calculation into the VM and adds reusable minipal CPU-count helpers.
- Removes obsolete implementations, declarations, exports, and build entries.
| File | Description |
|---|---|
src/native/minipal/minipalconfig.h.in |
Exposes affinity-query availability. |
src/native/minipal/cpucount.h |
Declares total and affinity CPU-count helpers. |
src/native/minipal/cpucount.c |
Implements shared CPU-count helpers. |
src/native/minipal/configure.cmake |
Detects sched_getaffinity. |
src/coreclr/vm/util.hpp |
Declares the relocated process CPU-count function. |
src/coreclr/vm/util.cpp |
Combines CPU affinity, configuration, and shared cgroup limits. |
src/coreclr/vm/simplerwlock.hpp |
Avoids the VM CPU-count query in diagnostic builds. |
src/coreclr/utilcode/util.cpp |
Uses minipal and removes process CPU-count logic. |
src/coreclr/pal/src/misc/sysinfo.cpp |
Replaces PAL CPU-count helpers with minipal. |
src/coreclr/pal/src/misc/cgroup.cpp |
Deletes duplicate cgroup implementation. |
src/coreclr/pal/src/init/pal.cpp |
Removes PAL cgroup initialization and cleanup. |
src/coreclr/pal/src/include/pal/cgroup.h |
Deletes obsolete cgroup lifecycle declarations. |
src/coreclr/pal/src/CMakeLists.txt |
Removes the deleted PAL source from the build. |
src/coreclr/pal/inc/pal.h |
Removes obsolete CPU-count and quota APIs. |
src/coreclr/nativeaot/Runtime/unix/PalUnix.cpp |
Uses shared GC cgroup CPU-limit queries. |
src/coreclr/nativeaot/Runtime/unix/cgroupcpu.h |
Deletes duplicate CPU-limit declarations. |
src/coreclr/nativeaot/Runtime/unix/cgroupcpu.cpp |
Deletes NativeAOT’s duplicate cgroup implementation. |
src/coreclr/nativeaot/Runtime/CMakeLists.txt |
Removes the deleted NativeAOT source from the build. |
src/coreclr/inc/utilcode.h |
Removes the relocated CPU-count declaration. |
src/coreclr/gc/unix/cgroup.h |
Declares the shared CPU-limit query. |
src/coreclr/gc/unix/cgroup.cpp |
Adds CPU-quota parsing and lazy shared initialization. |
src/coreclr/dlls/mscordac/mscordac_unixexports.src |
Removes obsolete PAL export entries. |
Review effort: Balanced
Co-authored-by: Cursor <[email protected]>
There was a problem hiding this comment.
🔵 Needs a closer look
Earlier shared cgroup initialization affects CoreCLR and NativeAOT startup, but static-only review leaves lifecycle, container CPU-quota, and cross-platform behavior needing maintainer validation.
No open issues 🎉
Review effort: Balanced
|
@AaronRobinsonMSFT, if this one goes in first, it will be easier to rebase #137579 branch and resolve the feedback. |
`gc/unix/cgroup.cpp` becomes `minipal/cgroup.c`, so the VM and NativeAOT no longer use code from the GC directory. The GC keeps its memory limit and usage policy in `gcenv.unix.cpp`. Co-authored-by: Cursor <[email protected]>
There was a problem hiding this comment.
🔵 Needs a closer look
Shared cgroup ownership and lifecycle changes span CoreCLR, NativeAOT, and standalone GC, requiring maintainer validation of startup/shutdown and platform-specific CPU limits that this source-only review could not perform.
No open issues 🎉
Review effort: Balanced
Co-authored-by: Cursor <[email protected]>
Co-authored-by: Cursor <[email protected]> # Conflicts: # src/coreclr/pal/src/init/pal.cpp
|
/ba-g osx dead letter |
Move the cgroup CPU limit into
gc/unix/cgroup.cppnext to the memory limit, sharing the cgroup discovery code, and moveGetCurrentProcessCpuCountfromutilcodeto the VM so it can use it. Delete the PAL copy andPAL_GetCpuLimit.