Skip to content

Conversation

@mangod9
Copy link
Member

@mangod9 mangod9 commented Aug 8, 2025

this will work better for scenarios where multiple NativeAOT libraries are used within a process.

This will alleviate GC initialization for certain scenarios, but manual configuration might be needed. Perhaps we can improve the error message when we fail to reserve the regions_range.

Copilot AI review requested due to automatic review settings August 8, 2025 06:04
Copy link
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

This PR modifies the garbage collector initialization in NativeAOT to use a more conservative memory reservation strategy. Instead of using the larger of 256GB or 2x physical memory, NativeAOT will now only reserve 2x physical memory for its regions range.

  • Reduces memory reservation footprint for NativeAOT applications
  • Better accommodates scenarios with multiple NativeAOT libraries in a single process
  • Maintains existing behavior for non-NativeAOT runtimes
Comments suppressed due to low confidence (1)

@dotnet-policy-service
Copy link
Contributor

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

Copy link
Member

@MichalStrehovsky MichalStrehovsky left a comment

Choose a reason for hiding this comment

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

The comment at #118433 (comment) makes it appear this might cause performance issues that we do not understand. I would prefer not having a native AOT specific configuration that causes perf issues we do not understand.

@jkotas
Copy link
Member

jkotas commented Aug 8, 2025

I agree with Michal that it is not desirable to have diverging GC defaults between regular CoreCLR and NativeAOT, in particular if we believe that it causes performance issues.

Our test strategy for NativeAOT assumes that NativeAOT is identical to regular CoreCLR as much as possible. If we were to start diverging NativeAOT and CoreCLR behavior with GC defaults, we would need to introduce duplicated test and perf coverage for NativeAOT.

@mangod9
Copy link
Member Author

mangod9 commented Aug 8, 2025

We were considering whether we can make the change globally for WKS, but that needs more thought (so perhaps in 11). We can look into a better message when GC is unable to reserve space.

@mangod9
Copy link
Member Author

mangod9 commented Aug 8, 2025

@Maoni0, was chatting with @agocke today and wondering if extending the 2x physical_mem reservation for WKS is going to be a risky behavior change? Are you aware of cases where that would lead to functional and/or perf issues?

@Maoni0
Copy link
Member

Maoni0 commented Aug 8, 2025

I think it's fine to make the change for WKS but you'd want to do some perf runs. note that on large machines this can of course mean more than 256GB reserved. and if you anticipate nativeaot apps to run on large systems (like a little service running along side large server apps), you'd probably want to put a cap on that so you'd want min (2x physical mem, some cap) (ie, the reverse of what we are doing now).

@agocke
Copy link
Member

agocke commented Aug 9, 2025

min (2x physical mem, 256gb) seems like a reasonable starting point

Copy link
Member

@agocke agocke left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@jkotas
Copy link
Member

jkotas commented Aug 15, 2025

@MichalStrehovsky Could you please clear your "changes requested" if this change looks reasonable to you?

@MichalStrehovsky MichalStrehovsky dismissed their stale review August 15, 2025 04:40

The change is no longer native AOT specific

@mangod9
Copy link
Member Author

mangod9 commented Aug 15, 2025

we are doing some perf validation to ensure there aren't any regressions in GCPerfSim scenarios.

@mangod9 mangod9 merged commit d96d77e into dotnet:main Aug 28, 2025
96 of 98 checks passed
@mangod9
Copy link
Member Author

mangod9 commented Aug 28, 2025

/backport to release/10.0

@github-actions
Copy link
Contributor

Started backporting to release/10.0: https://github.com/dotnet/runtime/actions/runs/17307393837

@github-actions github-actions bot locked and limited conversation to collaborators Sep 28, 2025
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.

5 participants