Skip to content

Fix segfault in GC standalone large pages emulation mode (segments path)#127763

Open
cshung wants to merge 1 commit intodotnet:mainfrom
cshung:fix/gc-standalone-largepages-segments
Open

Fix segfault in GC standalone large pages emulation mode (segments path)#127763
cshung wants to merge 1 commit intodotnet:mainfrom
cshung:fix/gc-standalone-largepages-segments

Conversation

@cshung
Copy link
Copy Markdown
Contributor

@cshung cshung commented May 4, 2026

In the non-regions (segments) path, GCLargePages=2 (emulation mode) was not handled by virtual_alloc. The function only had a bool use_large_pages_p parameter, so it could not distinguish between real large pages (VirtualReserveAndCommitLargePages) and emulation mode (which needs VirtualReserve + VirtualCommit). In emulation mode, memory was reserved but never committed, causing a segfault on access.

Fix: Change virtual_alloc to accept an int large_page_config parameter:

  • 0 = no large pages (reserve only)
  • 1 = real large pages (VirtualReserveAndCommitLargePages)
  • 2 = emulation (VirtualReserve + VirtualCommit)

The caller computes large_page_config once and passes it through reserve_initial_memory, eliminating the need for reserve_initial_memory to access the static large_pages_emulation_mode_p field.

The test is updated to use per-object-heap hard limits (GCHeapHardLimitSOH/LOH/POH), which are required for the segments path with large pages since each segment is sized to the full hard limit (soh + loh + poh = 3x limit with a single combined GCHeapHardLimit).

Fixes #127668

@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label May 4, 2026
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

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

Comment thread src/coreclr/gc/regions_segments.cpp Outdated
Comment thread src/coreclr/gc/init.cpp Outdated
Change virtual_alloc to accept an integer large_pages_config parameter
(0=none, 1=real large pages, 2=emulation) instead of a boolean. When
config=2, use VirtualReserve followed by VirtualCommit to emulate large
page behavior without requiring OS large page privileges.

Update the test to use per-object-heap hard limits which are required
for the segments path with large pages.
@cshung cshung force-pushed the fix/gc-standalone-largepages-segments branch from 86e5612 to 0aaa427 Compare May 5, 2026 21:36
@mangod9
Copy link
Copy Markdown
Member

mangod9 commented May 5, 2026

I am not convinced whether we should do this for segments. In fact we should be looking at not shipping clrgc.dll given that regions have been live for 3+ releases already

@cshung
Copy link
Copy Markdown
Contributor Author

cshung commented May 6, 2026

I am not convinced whether we should do this for segments. In fact we should be looking at not shipping clrgc.dll given that regions have been live for 3+ releases already

I think we should still maintain this path for two reasons:

  1. The segments path (#ifndef USE_REGIONS) is not just about standalone GC — it's the codepath 32-bit systems use in production. Standalone GC is currently the mechanism that exercises this path in CI. If we stop maintaining it, we're effectively letting the 32-bit segments codepath rot without any test coverage.

  2. Even setting aside 32-bit, standalone GC provides a valuable vehicle for flexible testing and experimentation. We may not want to ship it, but that doesn't mean it isn't worth keeping functional.

The fix itself is small and straightforward — it passes the large page config as an integer through virtual_alloc so the emulation mode does Reserve+Commit correctly on both the regions and segments paths.

@mangod9
Copy link
Copy Markdown
Member

mangod9 commented May 6, 2026

is the x86 case broken due to the new changes here?

@cshung
Copy link
Copy Markdown
Contributor Author

cshung commented May 6, 2026

is the x86 case broken due to the new changes here?

No, x86 is good:

  • x86 is not broken before this PR (large pages are not supported on x86, anything broken because of large page does not impact x86).
  • x86 is not broken after this PR either (this PR impacts large page only)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-GC-coreclr community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test Failure: GC/API/GC/Collect_Aggressive_LargePages/Collect_Aggressive_LargePages.cmd

3 participants