Skip decommit for large pages and add fake large pages test mode#127290
Open
cshung wants to merge 1 commit intodotnet:mainfrom
Open
Skip decommit for large pages and add fake large pages test mode#127290cshung wants to merge 1 commit intodotnet:mainfrom
cshung wants to merge 1 commit intodotnet:mainfrom
Conversation
With large pages, VirtualDecommit is a no-op since large pages cannot be partially decommitted. PR dotnet#126929 fixed the resulting stale data corruption by adding memclr in virtual_decommit, but this approach has downsides: the memory is never returned to the OS, yet we pay for the clearing and produce misleading committed/used bookkeeping. Instead, skip the decommit entirely for large pages: 1. distribute_free_regions: skip the aggressive tail-region decommit (the committed-but-unallocated tail of in-use regions). This was the path that caused the heap corruption in dotnet#126903. 2. decommit_heap_segment: skip the whole-segment decommit used for segment hoarding and BGC segment deletion. Same class of issue: committed/used are lowered but physical memory retains stale data. 3. decommit_region: bypass virtual_decommit and call reduce_committed_bytes directly, since decommit_region already handles large pages correctly by clearing memory itself. 4. virtual_decommit: add an assert that it is never called for heap memory when large pages are on. This catches any future caller that forgets to handle the large pages case. The end_of_data parameter and no-op ternary added by dotnet#126929 are removed. Add GCLargePages=2 mode that simulates large pages using small pages: sets use_large_pages_p=true but reserves with normal pages and commits everything upfront. This exercises all large page GC code paths without requiring OS large page setup or privileges, enabling CI testing. Fix dotnet#126903
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @dotnet/gc |
Member
mangod9
reviewed
Apr 22, 2026
| heap_segment* gc_heap::segment_standby_list; | ||
| #endif //USE_REGIONS | ||
| bool gc_heap::use_large_pages_p = 0; | ||
| bool gc_heap::large_pages_fake_mode_p = 0; |
Member
There was a problem hiding this comment.
probably better to name this large_pages_force_mode or something.
Member
There was a problem hiding this comment.
I'd prefer large_pages_simulation_mode_p or large_pages_emulation_mode_p
mangod9
reviewed
Apr 22, 2026
| { | ||
| memclr ((uint8_t*)address, (uint8_t*)end_of_data - (uint8_t*)address); | ||
| } | ||
| bool decommit_succeeded_p = GCToOSInterface::VirtualDecommit (address, size); |
Member
There was a problem hiding this comment.
think you need a similar fix in gc_heap::decommit_region ?
VSadov
reviewed
Apr 22, 2026
| // VirtualDecommit is a no-op for large pages so skip it and update | ||
| // committed bookkeeping directly. Memory clearing is handled below. | ||
| decommit_succeeded_p = true; | ||
| reduce_committed_bytes (page_start, decommit_size, bucket, h_number, true); |
Member
There was a problem hiding this comment.
If decommit is a noop, why are we reducing comitted bytes?
Member
|
The test fails on x86. Perhaps just make the test incompatible with 32bit? |
This was referenced Apr 22, 2026
Open
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
With large pages, VirtualDecommit is a no-op since large pages cannot be partially decommitted. PR #126929 fixed the resulting stale data corruption by adding memclr in virtual_decommit, but this approach has downsides: the memory is never returned to the OS, yet we pay for the clearing and produce misleading committed/used bookkeeping.
Instead, skip the decommit entirely for large pages:
distribute_free_regions: skip the aggressive tail-region decommit (the committed-but-unallocated tail of in-use regions). This was the path that caused the heap corruption in GC heap corruption with GCLargePages #126903.
decommit_heap_segment: skip the whole-segment decommit used for segment hoarding and BGC segment deletion. Same class of issue: committed/used are lowered but physical memory retains stale data.
decommit_region: bypass virtual_decommit and call reduce_committed_bytes directly, since decommit_region already handles large pages correctly by clearing memory itself.
virtual_decommit: add an assert that it is never called for heap memory when large pages are on. This catches any future caller that forgets to handle the large pages case. The end_of_data parameter and no-op ternary added by fix for largepages with agressive decommit logic #126929 are removed.
Add GCLargePages=2 mode that simulates large pages using small pages: sets use_large_pages_p=true but reserves with normal pages and commits everything upfront. This exercises all large page GC code paths without requiring OS large page setup or privileges, enabling CI testing.
Fix #126903