Skip to content

Move CoreCLR over to the managed wait subsystem - #117788

Merged
jkoritzinsky merged 68 commits into
dotnet:mainfrom
jkoritzinsky:coreclr-managed-wait
Dec 11, 2025
Merged

Move CoreCLR over to the managed wait subsystem#117788
jkoritzinsky merged 68 commits into
dotnet:mainfrom
jkoritzinsky:coreclr-managed-wait

Conversation

@jkoritzinsky

@jkoritzinskyjkoritzinsky commented Jul 17, 2025

Copy link
Copy Markdown
Member

Use the shared managed wait subsystem for CoreCLR's managed code instead of the Win32 PAL

Also, remove the named mutex support from the CoreCLR PAL as well as Mutex support.

Unblocks #115685

@jkoritzinskyjkoritzinsky added area-System.Threading runtime-coreclr specific to the CoreCLR runtime labels Jul 17, 2025
@jkoritzinskyjkoritzinsky added this to the 11.0.0 milestone Jul 17, 2025
@jkoritzinskyjkoritzinsky added the blocked Issue/PR is blocked on something - see comments label Jul 17, 2025
@jkoritzinsky
jkoritzinskyforce-pushed the coreclr-managed-wait branch 3 times, most recently from 06de3b2 to 63a1aa6CompareJuly 31, 2025 16:44
Comment threadsrc/coreclr/vm/threads.cpp Outdated
Comment threadsrc/coreclr/System.Private.CoreLib/src/System/Threading/Thread.CoreCLR.cs Outdated
Comment threadsrc/libraries/Common/src/Interop/Unix/System.Native/Interop.GetPageSize.cs Outdated
Comment threadsrc/coreclr/vm/threads.cpp Outdated
Comment threadsrc/coreclr/vm/threads.cpp Outdated
@jkoritzinsky

Copy link
Copy Markdown
MemberAuthor

Looks like I need to do some perf work in the wait subsystem. Time to first request is much worse and requests/sec regresses as well.

JSON benchmark results | application | PR | Main | | --------------------------------------- | --------------------------------- | --------------------------------- | | Max Process CPU Usage (%) | 90 | 90 | | Max Cores usage (%) | 5,030 | 5,036 | | Max Working Set (MB) | 115 | 119 | | Max Private Memory (MB) | 894 | 897 | | Build Time (ms) | 8,267 | 9,119 | | Start Time (ms) | 470 | 280 | | Published Size (KB) | 109,039 | 109,039 | | Symbols Size (KB) | 34 | 34 | | .NET Core SDK Version | 10.0.100-rtm.25513.102 | 10.0.100-rtm.25513.102 | | ASP.NET Core Version | 10.0.0-rtm.25513.102+b502b6eeec0d | 10.0.0-rtm.25513.102+b502b6eeec0d | | .NET Runtime Version | 10.0.0-rtm.25513.102+b502b6eeec0d | 10.0.0-rtm.25513.102+b502b6eeec0d | | Max Global CPU Usage (%) | 90 | 92 | | Max CPU Usage (%) | 89 | 90 | | Max Working Set (MB) | 121 | 123 | | Max GC Heap Size (MB) | 19 | 18 | | Size of committed memory by the GC (MB) | 27 | 31 | | Max Number of Gen 0 GCs / sec | 32.00 | 29.00 | | Max Number of Gen 1 GCs / sec | 1.00 | 2.00 | | Max Number of Gen 2 GCs / sec | 1.00 | 1.00 | | Max Gen 0 GC Budget (MB) | 33 | 15 | | Max Time in GC (%) | 17.00 | 2.00 | | Max Gen 0 Size (B) | 560 | 1,248 | | Max Gen 1 Size (B) | 2,608,768 | 963,760 | | Max Gen 2 Size (B) | 5,856,456 | 5,710,120 | | Max LOH Size (B) | 88,680 | 88,680 | | Max POH Size (B) | 1,606,608 | 1,594,248 | | Max Allocation Rate (B/sec) | 275,062,672 | 277,456,832 | | Max GC Heap Fragmentation (%) | 1,352% | 340% | | # of Assemblies Loaded | 107 | 101 | | Max Exceptions (#/s) | 458 | 442 | | Max Lock Contention (#/s) | 973 | 1,022 | | Max ThreadPool Threads Count | 76 | 76 | | Max ThreadPool Queue Length | 104 | 68 | | Max ThreadPool Items (#/s) | 2,574,119 | 2,593,353 | | Max Active Timers | 1 | 1 | | IL Jitted (B) | 541,472 | 367,434 | | Methods Jitted | 7,263 | 3,974 | | Load Working Set - P90 (MB) | 115 | 118 | | Load CPU Usage - P90 (%) | 85 | 88 |
loadPRMain
Max Process CPU Usage (%)3737
Max Cores usage (%)2,0582,087
Max Working Set (MB)4445
Max Private Memory (MB)358358
Build Time (ms)6,7827,261
Start Time (ms)00
Published Size (KB)72,28072,280
Symbols Size (KB)00
.NET Core SDK Version8.0.4168.0.416
ASP.NET Core Version8.0.22+ee41747993328.0.22+ee4174799332
.NET Runtime Version8.0.22+a2266c728f638.0.22+a2266c728f63
Max Global CPU Usage (%)5655
First Request (ms)422279
Requests/sec1,699,5661,708,722
Requests25,663,55325,800,351
Mean latency (ms)0.160.16
Max latency (ms)6.786.91
Bad responses00
Socket errors00
Read throughput (MB/s)301.47303.10
Latency 50th (ms)0.130.13
Latency 75th (ms)0.180.18
Latency 90th (ms)0.250.25
Latency 99th (ms)0.810.81
Plaintext benchmark results
applicationPRMain
Max Process CPU Usage (%)9996
Max Cores usage (%)5,5285,393
Max Working Set (MB)97102
Max Private Memory (MB)847847
Build Time (ms)9,1088,750
Start Time (ms)468276
Published Size (KB)109,039109,039
Symbols Size (KB)3434
.NET Core SDK Version10.0.100-rtm.25513.10210.0.100-rtm.25513.102
ASP.NET Core Version10.0.0-rtm.25513.102+b502b6eeec0d10.0.0-rtm.25513.102+b502b6eeec0d
.NET Runtime Version10.0.0-rtm.25513.102+b502b6eeec0d10.0.0-rtm.25513.102+b502b6eeec0d
Max Global CPU Usage (%)10098
Max CPU Usage (%)9996
Max Working Set (MB)101106
Max GC Heap Size (MB)1010
Size of committed memory by the GC (MB)88
Max Number of Gen 0 GCs / sec2.002.00
Max Number of Gen 1 GCs / sec1.001.00
Max Number of Gen 2 GCs / sec0.000.00
Max Gen 0 GC Budget (MB)1313
Max Time in GC (%)17.0012.00
Max Gen 0 Size (B)00
Max Gen 1 Size (B)2,621,6802,621,680
Max Gen 2 Size (B)1,100,2241,145,040
Max LOH Size (B)88,68088,680
Max POH Size (B)1,639,5681,672,528
Max Allocation Rate (B/sec)5,522,2805,932,352
Max GC Heap Fragmentation (%)953%863%
# of Assemblies Loaded107101
Max Exceptions (#/s)472454
Max Lock Contention (#/s)10,64511,487
Max ThreadPool Threads Count7676
Max ThreadPool Queue Length188172
Max ThreadPool Items (#/s)742,071745,110
Max Active Timers11
IL Jitted (B)529,015358,353
Methods Jitted7,1803,913
Load Working Set - P90 (MB)97102
Load CPU Usage - P90 (%)9194
loadPRMain
Max Process CPU Usage (%)2927
Max Cores usage (%)1,5971,539
Max Working Set (MB)4342
Max Private Memory (MB)360360
Build Time (ms)7,3266,503
Start Time (ms)11
Published Size (KB)72,28072,280
Symbols Size (KB)00
.NET Core SDK Version8.0.4168.0.416
ASP.NET Core Version8.0.22+ee41747993328.0.22+ee4174799332
.NET Runtime Version8.0.22+a2266c728f638.0.22+a2266c728f63
Max Global CPU Usage (%)6565
First Request (ms)410269
Requests/sec8,294,5368,490,340
Requests125,248,638128,203,039
Mean latency (ms)0.360.35
Max latency (ms)11.0911.75
Bad responses00
Socket errors00
Read throughput (MB/s)1,300.481,331.20
Latency 50th (ms)0.340.32
Latency 75th (ms)0.600.56
Latency 90th (ms)2.261.44
Latency 99th (ms)0.000.00

@VSadov

Copy link
Copy Markdown
Member

Time to first request is much worse

I see the Methods Jitted almost doubled. If that is included in the time, it might be one of the reasons.
Something was not crossgenned?

…ith a comment stating that we know that this can cause deadlocks for users that write bad code.
@jkoritzinsky

Copy link
Copy Markdown
MemberAuthor

I'm rerunning now to grab a trace and see if I can figure out why methods jitted is so high.

Might just be R2R major version differences between the aspnetcore version I used (pulled from .NET 10) and the .NET runtime version (where we've already bumped the min R2R major version twice) causing all of the R2R code for aspnetcore to be thrown out.

@sebastienros

sebastienros commented Dec 10, 2025

Copy link
Copy Markdown
Member

For this reason we usually suggest to benchmark the two locally built versions. You only have to build baseline once. Apples to apples.

@jkoritzinsky

Copy link
Copy Markdown
MemberAuthor

That's a tomorrow problem :)

@jkoritzinsky

Copy link
Copy Markdown
MemberAuthor

Here's the results after doing an apples-to-apples comparison (Main is locally built from the last merge point into the PR branch)

JSON benchmark results
applicationPRMain
Max Process CPU Usage (%)9090
Max Cores usage (%)5,0305,015
Max Working Set (MB)115112
Max Private Memory (MB)894927
Build Time (ms)8,2679,039
Start Time (ms)470472
Published Size (KB)109,039109,039
Symbols Size (KB)3434
.NET Core SDK Version10.0.100-rtm.25513.10210.0.100-rtm.25513.102
ASP.NET Core Version10.0.0-rtm.25513.102+b502b6eeec0d10.0.0-rtm.25513.102+b502b6eeec0d
.NET Runtime Version10.0.0-rtm.25513.102+b502b6eeec0d10.0.0-rtm.25513.102+b502b6eeec0d
Max Global CPU Usage (%)9092
Max CPU Usage (%)8990
Max Working Set (MB)121121
Max GC Heap Size (MB)1917
Size of committed memory by the GC (MB)2730
Max Number of Gen 0 GCs / sec32.0028.00
Max Number of Gen 1 GCs / sec1.001.00
Max Number of Gen 2 GCs / sec1.001.00
Max Gen 0 GC Budget (MB)3319
Max Time in GC (%)17.006.00
Max Gen 0 Size (B)560126,688
Max Gen 1 Size (B)2,608,7685,333,680
Max Gen 2 Size (B)5,856,4561,099,664
Max LOH Size (B)88,68088,680
Max POH Size (B)1,606,6081,577,768
Max Allocation Rate (B/sec)275,062,672276,387,088
Max GC Heap Fragmentation (%)1,352%3,580%
# of Assemblies Loaded107107
Max Exceptions (#/s)458450
Max Lock Contention (#/s)9731,118
Max ThreadPool Threads Count7676
Max ThreadPool Queue Length104100
Max ThreadPool Items (#/s)2,574,1192,637,707
Max Active Timers11
IL Jitted (B)541,472538,849
Methods Jitted7,2637,229
Load Working Set - P90 (MB)115108
Load CPU Usage - P90 (%)8587
loadPRMain
Max Process CPU Usage (%)3737
Max Cores usage (%)2,0582,045
Max Working Set (MB)4444
Max Private Memory (MB)358358
Build Time (ms)6,7826,964
Start Time (ms)00
Published Size (KB)72,28072,280
Symbols Size (KB)00
.NET Core SDK Version8.0.4168.0.416
ASP.NET Core Version8.0.22+ee41747993328.0.22+ee4174799332
.NET Runtime Version8.0.22+a2266c728f638.0.22+a2266c728f63
Max Global CPU Usage (%)5655
First Request (ms)422421
Requests/sec1,699,5661,697,701
Requests25,663,55325,633,992
Mean latency (ms)0.160.16
Max latency (ms)6.785.82
Bad responses00
Socket errors00
Read throughput (MB/s)301.47301.14
Latency 50th (ms)0.130.13
Latency 75th (ms)0.180.18
Latency 90th (ms)0.250.25
Latency 99th (ms)0.810.85
Plaintext benchmark results
applicationPRMain
Max Process CPU Usage (%)99100
Max Cores usage (%)5,5285,573
Max Working Set (MB)9798
Max Private Memory (MB)847847
Build Time (ms)9,1089,189
Start Time (ms)468469
Published Size (KB)109,039109,039
Symbols Size (KB)3434
.NET Core SDK Version10.0.100-rtm.25513.10210.0.100-rtm.25513.102
ASP.NET Core Version10.0.0-rtm.25513.102+b502b6eeec0d10.0.0-rtm.25513.102+b502b6eeec0d
.NET Runtime Version10.0.0-rtm.25513.102+b502b6eeec0d10.0.0-rtm.25513.102+b502b6eeec0d
Max Global CPU Usage (%)100100
Max CPU Usage (%)9999
Max Working Set (MB)101102
Max GC Heap Size (MB)1010
Size of committed memory by the GC (MB)88
Max Number of Gen 0 GCs / sec2.002.00
Max Number of Gen 1 GCs / sec1.001.00
Max Number of Gen 2 GCs / sec0.000.00
Max Gen 0 GC Budget (MB)1313
Max Time in GC (%)17.005.00
Max Gen 0 Size (B)00
Max Gen 1 Size (B)2,621,6802,621,568
Max Gen 2 Size (B)1,100,2241,092,184
Max LOH Size (B)88,68088,680
Max POH Size (B)1,639,5681,598,368
Max Allocation Rate (B/sec)5,522,2805,859,776
Max GC Heap Fragmentation (%)953%1,177%
# of Assemblies Loaded107107
Max Exceptions (#/s)472466
Max Lock Contention (#/s)10,64511,844
Max ThreadPool Threads Count7676
Max ThreadPool Queue Length188135
Max ThreadPool Items (#/s)742,071758,176
Max Active Timers11
IL Jitted (B)529,015526,490
Methods Jitted7,1807,151
Load Working Set - P90 (MB)9798
Load CPU Usage - P90 (%)9195
loadPRMain
Max Process CPU Usage (%)2927
Max Cores usage (%)1,5971,499
Max Working Set (MB)4343
Max Private Memory (MB)360360
Build Time (ms)7,3267,535
Start Time (ms)11
Published Size (KB)72,28072,280
Symbols Size (KB)00
.NET Core SDK Version8.0.4168.0.416
ASP.NET Core Version8.0.22+ee41747993328.0.22+ee4174799332
.NET Runtime Version8.0.22+a2266c728f638.0.22+a2266c728f63
Max Global CPU Usage (%)6565
First Request (ms)410422
Requests/sec8,294,5368,280,244
Requests125,248,638125,029,739
Mean latency (ms)0.360.35
Max latency (ms)11.099.61
Bad responses00
Socket errors00
Read throughput (MB/s)1,300.481,300.48
Latency 50th (ms)0.340.32
Latency 75th (ms)0.600.56
Latency 90th (ms)2.261.14
Latency 99th (ms)0.000.00

With an apples-to-apples comparison, the difference in First Request (ms) goes away (lending credit to the R2R rejection hypothesis) and the PR actually has an improved Requests/sec instead of a slight regression!

@jkoritzinsky
jkoritzinsky marked this pull request as ready for review December 10, 2025 19:35
CopilotAI review requested due to automatic review settings December 10, 2025 19:35

CopilotAI 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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@jkotasjkotas 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.

Thank you! Great work!

@jkoritzinsky
jkoritzinsky enabled auto-merge (squash) December 10, 2025 21:21
@jkoritzinsky

Copy link
Copy Markdown
MemberAuthor

/ba-g WBT failures and a spurious infra problem

@jkoritzinsky
jkoritzinsky merged commit 421445e into dotnet:mainDec 11, 2025
159 of 164 checks passed
@jkoritzinsky
jkoritzinsky deleted the coreclr-managed-wait branch December 11, 2025 12:06
@github-actionsgithub-actionsBot locked and limited conversation to collaborators Jan 11, 2026
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-System.Threadingruntime-coreclrspecific to the CoreCLR runtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants

@jkoritzinsky@risc-vv@jkotas@MihuBot@MihaZupan@VSadov@am11@sebastienros@teo-tsirpanis