Redo GC heap size fix in heavily pinning scenarios#126043
Open
janvorli wants to merge 5 commits intodotnet:mainfrom
Open
Redo GC heap size fix in heavily pinning scenarios#126043janvorli wants to merge 5 commits intodotnet:mainfrom
janvorli wants to merge 5 commits intodotnet:mainfrom
Conversation
This changes puts back the recently reverted change to fix regression of GC heap size with regions when there is heavy pinning. The original fix had a bug that resulted in a hang due to an infinite loop in the allocate_in_condemned_generations. This change also fixes that issue. The issue was caused by a plug with size 0x3FFFD0 (that was with 4MB regions). The problem was caused by the fact that an attempt to relocate that plug into a new plug could never succeed in that code, as at that point, the new region has always added padding at the front and that padding reduces the size so that such a large plug cannot fit into even completely empty region. The fix is to prevent adding the padding in case the plug is so large that it would not fit in with the padding, as the padding is only necessary for short plugs.
Contributor
|
Tagging subscribers to this area: @agocke, @dotnet/gc |
Contributor
There was a problem hiding this comment.
Pull request overview
Reintroduces and corrects a previously reverted GC regions planning change intended to fix heap size regressions under heavy pinning, addressing an additional hang caused by an infinite retry scenario during relocation/plan allocation.
Changes:
- Adds logic to conditionally promote remaining gen1 pins (especially for “gen1 due to cards” cases) instead of always demoting.
- Refactors and centralizes pinned-allocation accounting via new helper(s).
- Prevents front padding from being applied when relocating near-region-sized plugs that cannot fit with padding, avoiding infinite retry/hang.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/coreclr/gc/plan_phase.cpp | Updates pin demotion/promotion decision flow for regions and non-regions; refactors pinned allocation attribution and adds additional diagnostics. |
| src/coreclr/gc/gcpriv.h | Extends GC heap API surface with helper declarations and replaces demote_gen1_p with decide_promote_gen1_pins_p. |
| src/coreclr/gc/gc.cpp | Adjusts thresholds/defines and adds storage for the new single-GC state flag. |
| src/coreclr/gc/allocation.cpp | Introduces helpers for gen1 pin promotion decisions and pinned allocation attribution; adds padding-suppression logic for near-region-sized plugs. |
janvorli
commented
Mar 24, 2026
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Jan Vorlicek <jan.vorlicek@volny.cz>
src/tests/GC/Regressions/Github/Runtime_126043/Runtime_126043.cs
Outdated
Show resolved
Hide resolved
src/tests/GC/Regressions/Github/Runtime_126043/Runtime_126043.cs
Outdated
Show resolved
Hide resolved
src/tests/GC/Regressions/Github/Runtime_126043/Runtime_126043.cs
Outdated
Show resolved
Hide resolved
VSadov
reviewed
Mar 26, 2026
VSadov
reviewed
Mar 26, 2026
* Comments * Add explicit GC region size setting to the test
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.
This changes puts back the recently reverted change to fix regression of
GC heap size with regions when there is heavy pinning.
The original fix had a bug that resulted in a hang due to an infinite
loop in the
allocate_in_condemned_generations.This change also fixes that issue. The issue was caused by a plug with
size 0x3FFFD0 (that was with 4MB regions). The problem was caused by the
fact that an attempt to relocate that plug into a new plug could never
succeed in that code, as at that point, the new region has always added
padding at the front and that padding reduces the size so that such a
large plug cannot fit into even completely empty region.
The fix is to prevent adding the padding in case the plug is so large
that it would not fit in with the padding, as the padding is only
necessary for short plugs.