Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New GC decommit strategy for large/huge regions #109431

Merged
merged 6 commits into from
Feb 7, 2025
Merged

Conversation

markples
Copy link
Contributor

@markples markples commented Oct 31, 2024

  • Use age rather than budget for determining whether large and huge regions should be decommitted
    • Combine new age logic with previous age logic for basic regions
    • Simply add aged regions to decommit list. In the future, this can be combined with move_highest_free_regions with age swapping to optimize which regions are decommitted
    • Factor modified portions of distribute_free_regions into helper functions
    • Simplify distribute_free_regions when logic now only applies to basic regions
  • Add logic to more aggressively decommit in high-memory-usage situations
  • Call distribute_free_regions during BGC (or during ephemeral "pre-GC" to a BGC if one occurs)

@markples markples added this to the 10.0.0 milestone Oct 31, 2024
@markples markples self-assigned this Oct 31, 2024
Copy link
Contributor

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

@markples markples changed the title [draft] New decommit strategy for large/huge regions New GC decommit strategy for large/huge regions Nov 19, 2024
@markples markples marked this pull request as ready for review November 19, 2024 10:54
@@ -53336,6 +53465,7 @@ bool gc_heap::compute_memory_settings(bool is_initialization, uint32_t& nhp, uin
}

m_high_memory_load_th = min ((high_memory_load_th + 5), v_high_memory_load_th);
almost_high_memory_load_th = max((high_memory_load_th - 5), 1u);

Copy link
Member

Choose a reason for hiding this comment

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

since this can be set by a config it can be smaller than 5 so this can't be an unsigned number.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch, thanks - note also that ~25 lines up there was a possibility for overflow

Copy link
Member

@Maoni0 Maoni0 left a comment

Choose a reason for hiding this comment

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

Mark and I talked about the following couple of changes that he'll do but in general this looks good and we've gone through the perf results -

  1. make sure we are doing the right check for when we want to decommit (in distribute_surplus_p) called at the beginning of a BGC mark phase
  2. add a comment that talks about the policies and operations on the global and local lists (I've written an example for him)
  3. the calc of almost_high_memory_load_th in the comment above
  4. a couple of nit changes for naming

@markples
Copy link
Contributor Author

markples commented Nov 28, 2024

Done but (2)

  1. make sure we are doing the right check for when we want to decommit (in distribute_surplus_p) called at the beginning of a BGC mark phase

I believe this is correct. Previously we never called distribute_free_regions at this point, but we could call it during an ephemeral gc that is triggered at the start of BGC. In that case, we would choose to decommit a positive balance (background_running_p() is false). We want BGC behavior to match this possible ephemeral GC (as the ephemeral GC is optional (a policy choice) but we don't want distribute_free_regions behaving differently based on this decision). We have distribute_surplus_p return true if (settings.condemned_generation != max_generation), which means it returns false if condemned generation is 2 (BGC, not a foreground GC during BGC). Returning false means we don't distribute but instead decommit, which is what we want.

This will go in the comments.

  1. add a comment that talks about the policies and operations on the global and local lists (I've written an example for him)
  2. the calc of almost_high_memory_load_th in the comment above

fixed this and a nearby similar problem

  1. a couple of nit changes for naming

done

@markples
Copy link
Contributor Author

markples commented Dec 2, 2024

Comment added for (2)

@markples
Copy link
Contributor Author

markples commented Dec 2, 2024

I manually built a new commit with all of these changes as rebase operations to squash some commits together were retriggering old merge conflicts. To see the most recent changes separately, see my backup branch https://github.com/markples/runtime/tree/new-dfr-backup or the specific commits:

fix underflow possibility and nearby overflow one
decide_on_decommit_strategy
dst -> dest to match majority of file
Rename remove_surplus_regions->trim_region_list and add_regions->grow_region_list.
dfr comment

or those 5 squashed in https://github.com/markples/runtime/tree/new-dfr-backup-squash at 3eef23b

// - aged_regions
// - surplus_regions
//
// For reason_induced_aggressive GCs, we decommit all regions. Therefore, the below description is
Copy link
Contributor Author

Choose a reason for hiding this comment

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

all region

that we can

// a. A negative balance (deficit) for SOH (basic) will be distributed it means we expect to use
// more memory than we have on the free lists. A negative balance for LOH (large) isn't possible
// for LOH since the budgets start at zero.
// b. For SOH (basic), we will decommit surplus regions unless we are in a foreground GC during BGC.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this matches old policy. if not decommit then we distribute evenly. "foreground GC" is enough (means during BGC)

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