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

Optimize region count #56471

Merged
merged 2 commits into from
Jul 30, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions src/coreclr/gc/gc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2297,6 +2297,7 @@ bool affinity_config_specified_p = false;
#ifdef USE_REGIONS
region_allocator global_region_allocator;
uint8_t*(*initial_regions)[total_generation_count][2] = nullptr;
size_t gc_heap::region_count = 0;
#endif //USE_REGIONS

#ifdef BACKGROUND_GC
Expand Down Expand Up @@ -3512,12 +3513,6 @@ size_t get_basic_region_index_for_address (uint8_t* address)
return (basic_region_index - ((size_t)g_gc_lowest_address >> gc_heap::min_segment_size_shr));
}

inline
size_t get_total_region_count()
{
return (get_basic_region_index_for_address (g_gc_highest_address) + 1);
}

// Go from a random address to its region info. The random address could be
// in one of the basic regions of a larger region so we need to check for that.
inline
Expand Down Expand Up @@ -9741,7 +9736,6 @@ size_t gc_heap::sort_mark_list()

#ifdef USE_REGIONS
// first set the pieces for all regions to empty
size_t region_count = get_total_region_count();
assert (g_mark_list_piece_size >= region_count);
for (size_t region_index = 0; region_index < region_count; region_index++)
{
Expand Down Expand Up @@ -21138,7 +21132,6 @@ size_t gc_heap::get_promoted_bytes()
}

dprintf (3, ("h%d getting surv", heap_number));
size_t region_count = get_total_region_count();
size_t promoted = 0;
for (size_t i = 0; i < region_count; i++)
{
Expand Down Expand Up @@ -23934,6 +23927,7 @@ void gc_heap::mark_phase (int condemned_gen_number, BOOL mark_only_p)

#ifdef USE_REGIONS
special_sweep_p = false;
region_count = global_region_allocator.get_used_region_count();
grow_mark_list_piece();
#endif //USE_REGIONS

Expand Down Expand Up @@ -24002,7 +23996,7 @@ void gc_heap::mark_phase (int condemned_gen_number, BOOL mark_only_p)
#endif //MULTIPLE_HEAPS
survived_per_region = (size_t*)&g_mark_list_piece[heap_number * 2 * g_mark_list_piece_size];
old_card_survived_per_region = (size_t*)&survived_per_region[g_mark_list_piece_size];
size_t region_info_to_clear = get_total_region_count() * sizeof (size_t);
size_t region_info_to_clear = region_count * sizeof (size_t);
memset (survived_per_region, 0, region_info_to_clear);
memset (old_card_survived_per_region, 0, region_info_to_clear);
}
Expand Down Expand Up @@ -26213,7 +26207,6 @@ void gc_heap::process_remaining_regions (int current_plan_gen_num, generation* c

void gc_heap::grow_mark_list_piece()
{
size_t region_count = get_total_region_count();
if (g_mark_list_piece_size < region_count)
{
delete[] g_mark_list_piece;
Expand All @@ -26238,11 +26231,10 @@ void gc_heap::save_current_survived()
{
if (!survived_per_region) return;

size_t region_info_to_copy = get_total_region_count() * sizeof (size_t);
size_t region_info_to_copy = region_count * sizeof (size_t);
memcpy (old_card_survived_per_region, survived_per_region, region_info_to_copy);

#ifdef _DEBUG
size_t region_count = get_total_region_count();
for (size_t region_index = 0; region_index < region_count; region_index++)
{
if (survived_per_region[region_index] != 0)
Expand All @@ -26259,7 +26251,6 @@ void gc_heap::update_old_card_survived()
{
if (!survived_per_region) return;

size_t region_count = get_total_region_count();
for (size_t region_index = 0; region_index < region_count; region_index++)
{
old_card_survived_per_region[region_index] = survived_per_region[region_index] -
Expand Down
8 changes: 8 additions & 0 deletions src/coreclr/gc/gcpriv.h
Original file line number Diff line number Diff line change
Expand Up @@ -3585,6 +3585,8 @@ class gc_heap
size_t* survived_per_region;
PER_HEAP
size_t* old_card_survived_per_region;
PER_HEAP_ISOLATED
size_t region_count;
#endif //USE_REGIONS

#define max_oom_history_count 4
Expand Down Expand Up @@ -5694,6 +5696,12 @@ class region_allocator
size_t get_free() { return (total_free_units * region_alignment) ; }
size_t get_region_alignment () { return region_alignment; }
size_t get_large_region_alignment () { return large_region_alignment; }
size_t get_used_region_count()
{
return ((region_map_right_start == region_map_right_end)
? (region_map_left_end - region_map_left_start)
: (region_map_right_end - region_map_left_start));
Copy link
Member

Choose a reason for hiding this comment

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

actually I do think we don't need to care about the region_map_right case... since it's not used at all and the way we were thinking of using it will make this calculation incorrect anyway. so for now we can assume we don't need to worry about it at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, perhaps put an assert instead of the ?:

Copy link
Member

Choose a reason for hiding this comment

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

sounds good to me.

}
};
#endif //USE_REGIONS

Expand Down