Skip to content

Fix background GC zeroing of arrays larger than 4 GiB - #135797

Merged
janvorli merged 1 commit into
dotnet:mainfrom
janvorli:fix-bgc-large-array-zeroing
Oct 19, 2026
Merged

janvorli merged 1 commit into
dotnet:mainfrom
janvorli:fix-bgc-large-array-zeroing

Conversation

@janvorli

@janvorli janvorli commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

When a UOH allocation overlaps a background GC, make_unused_array temporarily represents the allocation as free objects. Allocations larger than 4 GiB can require multiple pieces. On fresh memory, clearing their headers leaves the PREV_EMPTY free-list marker in later pieces, violating the zero-initialization guarantee.

Pass the object size to UnsetFree and clear the previous free-list pointer when the piece is large enough to contain it. clear_unused_array already walks every temporary piece, so each piece's metadata is cleared before the allocation is returned.

Add a process-isolated, long-running GC regression test that checks all elements of 4, 6, and 8 GiB arrays allocated during background GC. The test excludes WASM and 32-bit architectures, disables Mono builds, and requires at least 16 GiB of available GC memory.

Resolves #135791

Note

This PR description and the code changes were generated with GitHub Copilot.

Clear free-list metadata from every temporary free object before returning a background UOH allocation. Add large-memory regression coverage for 4, 6, and 8 GiB arrays.

Co-authored-by: Copilot <[email protected]>

Copilot-Session: 8776c79b-0b1a-4d72-b132-7531e8cb2b73
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

@janvorli
janvorli merged commit f25130a into dotnet:main Oct 19, 2026
109 of 111 checks passed
@janvorli
janvorli deleted the fix-bgc-large-array-zeroing branch October 19, 2026 15:49
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 19, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GC: a ≥ 4 GB array allocated during a background GC can contain a stray 0x01 byte (PREV_EMPTY left by make_unused_array)

2 participants