Skip to content
Merged
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
Next Next commit
Make distributing free regions more precise so we know that each heap…
… has between budget-1 and budget regions.
  • Loading branch information
PeterSolMS authored and github-actions committed Sep 29, 2022
commit 303b6d5a6df603ae930a85acb9234c04395add56
40 changes: 33 additions & 7 deletions src/coreclr/gc/gc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12749,7 +12749,15 @@ void gc_heap::distribute_free_regions()

// we may have a deficit or - if background GC is going on - a surplus.
// adjust the budget per heap accordingly
ptrdiff_t adjustment_per_heap = (balance + (n_heaps - 1)) / n_heaps;
ptrdiff_t adjustment_per_heap;
if (balance < 0)
{
adjustment_per_heap = balance / n_heaps;
}
else
{
adjustment_per_heap = (balance + (n_heaps - 1)) / n_heaps;
}

#ifdef MULTIPLE_HEAPS
for (int i = 0; i < n_heaps; i++)
Expand Down Expand Up @@ -12805,35 +12813,53 @@ void gc_heap::distribute_free_regions()
{
gc_heap* hp = g_heaps[i];

if (hp->free_regions[kind].get_num_free_regions() > heap_budget_in_region_units[i][kind])
if (hp->free_regions[kind].get_num_free_regions() >= heap_budget_in_region_units[i][kind])
{
dprintf (REGIONS_LOG, ("removing %Id %s regions from heap %d with %Id regions",
hp->free_regions[kind].get_num_free_regions() - heap_budget_in_region_units[i][kind],
hp->free_regions[kind].get_num_free_regions() - heap_budget_in_region_units[i][kind] + 1,
kind_name[kind],
i,
hp->free_regions[kind].get_num_free_regions()));

remove_surplus_regions (&hp->free_regions[kind], &surplus_regions[kind], heap_budget_in_region_units[i][kind]);
remove_surplus_regions (&hp->free_regions[kind], &surplus_regions[kind], heap_budget_in_region_units[i][kind]-1);
}
}
// finally go through all the heaps and distribute any surplus regions to heaps having too few free regions
for (int i = 0; i < n_heaps; i++)
{
gc_heap* hp = g_heaps[i];

// first pass: fill all the regions having less than budget - 1
if (hp->free_regions[kind].get_num_free_regions() + 1 < heap_budget_in_region_units[i][kind])
{
int64_t num_added_regions = add_regions (&hp->free_regions[kind], &surplus_regions[kind], heap_budget_in_region_units[i][kind] - 1);
dprintf (REGIONS_LOG, ("added %Id %s regions to heap %d - now has %Id, budget is %Id",
num_added_regions,
kind_name[kind],
i,
hp->free_regions[kind].get_num_free_regions(),
heap_budget_in_region_units[i][kind]));
}
}
for (int i = 0; i < n_heaps; i++)
{
gc_heap* hp = g_heaps[i];
#else //MULTIPLE_HEAPS
{
gc_heap* hp = pGenGCHeap;
const int i = 0;
#endif //MULTIPLE_HEAPS

// second pass: fill all the regions having less than budget
if (hp->free_regions[kind].get_num_free_regions() < heap_budget_in_region_units[i][kind])
{
int64_t num_added_regions = add_regions (&hp->free_regions[kind], &surplus_regions[kind], heap_budget_in_region_units[i][kind]);
dprintf (REGIONS_LOG, ("added %Id %s regions to heap %d - now has %Id",
dprintf (REGIONS_LOG, ("added %Id %s regions to heap %d - now has %Id, budget is %Id",
num_added_regions,
kind_name[kind],
i,
hp->free_regions[kind].get_num_free_regions()));
hp->free_regions[kind].get_num_free_regions(),
heap_budget_in_region_units[i][kind]));
}
hp->free_regions[kind].sort_by_committed_and_age();
}
Expand Down Expand Up @@ -45079,7 +45105,7 @@ HRESULT GCHeap::Initialize()
gc_heap* hp = gc_heap::g_heaps[0];

dynamic_data* gen0_dd = hp->dynamic_data_of (0);
gc_heap::min_gen0_balance_delta = (dd_min_size (gen0_dd) >> 3);
gc_heap::min_gen0_balance_delta = (dd_min_size (gen0_dd) >> 6);

bool can_use_cpu_groups = GCToOSInterface::CanEnableGCCPUGroups();
GCConfig::SetGCCpuGroup(can_use_cpu_groups);
Expand Down