Skip to content

[mono] Prevent redundant scanning of major objects during nursery bridge processing - #137047

Open
BrzVlad wants to merge 1 commit into
dotnet:mainfrom
BrzVlad:fix-sgen-concurrent-tarjan
Open

BrzVlad wants to merge 1 commit into
dotnet:mainfrom
BrzVlad:fix-sgen-concurrent-tarjan

Conversation

@BrzVlad

@BrzVlad BrzVlad commented Nov 5, 2026

Copy link
Copy Markdown
Member

During bridge processing we collect the set of bridge objects that are eligible for collection. We then build the graph of references between these objects, by going through dead objects. For nursery collections, it makes no sense to visit major objects, since these objects are logically alive during the current collection. Any bridge object that they will end up referencing would have been alive during this collection so visiting them doesn't make sense. I believe this scanning was accidental, likely meant to ensure that we visit the current set of bridge objects (which were previously promoted so they live now in the major heap).

The problem with this scanning is not only a performance problem, but bridge processing will tag the vtable and store the ScanData* in the lock word. If we are doing this mutation for live objects, this can interfere with the scanning done by the concurrent mark (since it does an untagged access of the vtable to obtain the gc descriptor and other info), leading to random crashes.

…dge processing

During bridge processing we collect the set of bridge objects that are eligible for collection. We then build the graph of references between these objects, by going through dead objects. For nursery collections, it makes no sense to visit major objects, since these objects are logically alive during the current collection. Any bridge object that they will end up referencing would have been alive during this collection so visiting them doesn't make sense. I believe this scanning was accidental, likely meant to ensure that we visit the current set of bridge objects (which were previously promoted so they live now in the major heap).

The problem with this scanning is not only a performance problem, but bridge processing will tag the vtable and store the `ScanData*` in the lock word. If we are doing this mutation for live objects, this can interfere with the scanning done by the concurrent mark (since it does an untagged access of the vtable to obtain the gc descriptor and other info), leading to random crashes.
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
12 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: @BrzVlad
See info in area-owners.md if you want to be subscribed.

@BrzVlad

BrzVlad commented Nov 5, 2026

Copy link
Copy Markdown
Member Author

This now matches the behavior that is used for the CoreCLR gc bridge. This can have significant perf impact for the gen0 pauses since we avoid redundantly scanning objects from the major heap. This fixes a bad interaction between gc bridge and concurrent collector. We have had plenty of reports that concurrent mark leads to random crashes on android and many users are using the serial collector as a workaround, which has longer pauses.

It is still unclear to me whether we should backport it, I believe it would be good to have it readily available in case we do need to do it for a customer.

This branch has not been deployed

No deployments
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.

1 participant