Skip to content

Redo GC heap size fix in heavily pinning scenarios#126043

Open
janvorli wants to merge 5 commits intodotnet:mainfrom
janvorli:redo-pinning-fix
Open

Redo GC heap size fix in heavily pinning scenarios#126043
janvorli wants to merge 5 commits intodotnet:mainfrom
janvorli:redo-pinning-fix

Conversation

@janvorli
Copy link
Copy Markdown
Member

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.

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.
@janvorli janvorli added this to the 11.0.0 milestone Mar 24, 2026
@janvorli janvorli self-assigned this Mar 24, 2026
Copilot AI review requested due to automatic review settings March 24, 2026 17:33
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke, @dotnet/gc
See info in area-owners.md if you want to be subscribed.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Jan Vorlicek <jan.vorlicek@volny.cz>
Copilot AI review requested due to automatic review settings March 24, 2026 18:24
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Copy link
Copy Markdown
Member

@VSadov VSadov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

* Comments
* Add explicit GC region size setting to the test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants