-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Skip decommit for large pages and add fake large pages test mode #127290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
janvorli
merged 3 commits into
dotnet:main
from
cshung:fix/gc-largepages-skip-tail-decommit
Apr 28, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using System.Collections.Concurrent; | ||
| using System.Runtime.CompilerServices; | ||
| using System.Threading; | ||
| using Xunit; | ||
|
|
||
| // Regression test for https://github.com/dotnet/runtime/issues/126903 | ||
| // Verifies that aggressive GC does not corrupt the heap under emulated large pages. | ||
| // The large pages emulation mode (DOTNET_GCLargePages=2) exercises the same | ||
| // GC code paths as real large pages without requiring OS-level large page setup. | ||
| public class AggressiveCollectLargePages | ||
| { | ||
| const int DurationMs = 3000; | ||
| const int WriterCount = 4; | ||
|
|
||
| [Fact] | ||
| public static int TestEntryPoint() | ||
| { | ||
| var dict = new ConcurrentDictionary<int, byte[]>(); | ||
| var cts = new CancellationTokenSource(DurationMs); | ||
| var token = cts.Token; | ||
| int errors = 0; | ||
|
|
||
| Thread[] writers = new Thread[WriterCount]; | ||
| for (int t = 0; t < WriterCount; t++) | ||
| { | ||
| int tid = t; | ||
| writers[t] = new Thread(() => | ||
| { | ||
| try | ||
| { | ||
| int i = tid * 1_000_000; | ||
| while (!token.IsCancellationRequested) | ||
| { | ||
| dict[i] = new byte[100]; | ||
| i++; | ||
| if ((i % 1000) == 0) | ||
| { | ||
| dict.Clear(); | ||
| } | ||
| } | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| Console.WriteLine($"Writer {tid} caught: {ex.GetType().Name}: {ex.Message}"); | ||
| Interlocked.Increment(ref errors); | ||
| } | ||
| }); | ||
| writers[t].IsBackground = true; | ||
| writers[t].Start(); | ||
| } | ||
|
|
||
| Thread gcThread = new Thread(() => | ||
| { | ||
| while (!token.IsCancellationRequested) | ||
| { | ||
| CreateGarbage(); | ||
| GC.Collect(2, GCCollectionMode.Aggressive, blocking: true, compacting: true); | ||
| Thread.Sleep(50); | ||
| } | ||
| }); | ||
| gcThread.IsBackground = true; | ||
| gcThread.Start(); | ||
|
|
||
| gcThread.Join(); | ||
| for (int t = 0; t < WriterCount; t++) | ||
| { | ||
| writers[t].Join(); | ||
| } | ||
|
|
||
| if (errors > 0) | ||
| { | ||
| Console.WriteLine($"FAIL: {errors} writer(s) hit exceptions (heap corruption)."); | ||
| return 101; | ||
| } | ||
|
|
||
| Console.WriteLine("PASS: No heap corruption detected."); | ||
| return 100; | ||
| } | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| static void CreateGarbage() | ||
| { | ||
| byte[][] small = new byte[500][]; | ||
| for (int i = 0; i < small.Length; i++) | ||
| { | ||
| small[i] = new byte[4000]; | ||
| } | ||
| byte[] large = new byte[8 * 1024 * 1024]; | ||
| GC.KeepAlive(small); | ||
| GC.KeepAlive(large); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <!-- Needed for CLRTestEnvironmentVariable --> | ||
| <RequiresProcessIsolation>true</RequiresProcessIsolation> | ||
| <CLRTestTargetUnsupported Condition="'$(RuntimeFlavor)' != 'coreclr'">true</CLRTestTargetUnsupported> | ||
| <!-- Large pages and GCHeapHardLimit=0xC0000000 are not supported on 32-bit --> | ||
|
janvorli marked this conversation as resolved.
|
||
| <CLRTestTargetUnsupported Condition="'$(TargetBits)' == '32'">true</CLRTestTargetUnsupported> | ||
| <CLRTestPriority>0</CLRTestPriority> | ||
| </PropertyGroup> | ||
| <PropertyGroup> | ||
| <DebugType>PdbOnly</DebugType> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <Compile Include="Collect_Aggressive_LargePages.cs" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <CLRTestEnvironmentVariable Include="DOTNET_GCLargePages" Value="2" /> | ||
| <CLRTestEnvironmentVariable Include="DOTNET_GCHeapHardLimit" Value="0xC0000000" /> | ||
| </ItemGroup> | ||
| </Project> | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.