Uh oh!
There was an error while loading. Please reload this page.
[release/10.0] : Change the PerfMap crst into an UNSAFE_ANYMODE crst - #129142
Conversation
…ore ideal for perfmap scenarios
…s contract for use on Windows
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
There was a problem hiding this comment.
Pull request overview
Backport of the .NET 10 CoreCLR PerfMap deadlock fix to release/10.0, addressing a lock-ordering / GC-mode-toggle deadlock when PerfMap stub logging runs on paths that hold CRST_UNSAFE_ANYMODE locks (notably virtual-call-stub / code fragment heap allocation paths). The change also introduces a configuration escape hatch to disable stub logging while keeping PerfMap generation available for other symbol types.
Changes:
- Make the PerfMap lock (
PerfMap::s_csPerfMap)CRST_UNSAFE_ANYMODEto prevent cooperative↔preemptive GC-mode toggling while under otherUNSAFE_ANYMODElocks. - Add a
PerfMapStubGranularitybit to disable stub logging (value 4), providing an escape hatch for affected customers. - Adjust virtual call stub generation paths to optionally switch GC mode around stub generation and to reinitialize bucket-table probers after potential GC-mode transitions.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/coreclr/vm/virtualcallstub.cpp | Wraps stub generation with conditional GC-mode switching when PerfMap is enabled, and refreshes probers after potential invalidation; removes FEATURE_PERFMAP guards around stub logging calls. |
| src/coreclr/vm/perfmap.h | Adds a no-FEATURE_PERFMAP stub PerfMap definition and introduces s_LogStubs in the FEATURE_PERFMAP path. |
| src/coreclr/vm/perfmap.cpp | Switches PerfMap crst to CRST_UNSAFE_ANYMODE, adds s_LogStubs config handling, and gates stub logging on the new switch. |
| src/coreclr/vm/eventing/eventpipe/ds-rt-coreclr.h | Updates PerfMap enable path contracts for diagnostics-server activation. |
| src/coreclr/inc/clrconfigvalues.h | Updates the PerfMapStubGranularity description to document the new “disable stub logging” bit. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Backport of #129021 to release/10.0
Fixes#128401
/cc @leculver
Customer Impact
This was reported by customers which found that a service in production would deadlock occasionally when perfmap generation was enabled.
Regression
This was introduced in #113943
Testing
Fix was verified through analysis, and the fix also includes an escape hatch environment variable (DOTNET_PerfMapGranularity=4) which will disable the problematic code entirely.
Risk
Risks:
This fix adjusts a lock so that it will not switch to preemptive mode, and we will run some file I/O while under that lock. This may cause GC latency spikes on some customer workloads. This issue is mitigated by the new switch which can be used to avoid the problem in its entirety at the cost of slightly less accurate profile data for a limited set of scenarios.
IMPORTANT: If this backport is for a servicing release, please verify that:
release/X.0-staging, notrelease/X.0.release/X.0(no-stagingsuffix).Package authoring no longer needed in .NET 9
IMPORTANT: Starting with .NET 9, you no longer need to edit a NuGet package's csproj to enable building and bump the version.
Keep in mind that we still need package authoring in .NET 8 and older versions.