@@ -13414,86 +13414,24 @@ void gc_heap::distribute_free_regions()
1341413414 num_huge_region_units_to_consider[kind]));
1341513415
1341613416 // check if the free regions exceed the budget
13417- // if so, put the highest free regions on the decommit list
13417+ // if so, consider putting the highest free regions on the decommit list
1341813418 total_num_free_regions[kind] += num_regions_to_decommit[kind];
1341913419
1342013420 ptrdiff_t balance = total_num_free_regions[kind] + num_huge_region_units_to_consider[kind] - total_budget_in_region_units[kind];
1342113421
13422- // Ignore young huge regions if they are contributing to a surplus.
13423- if (balance > 0)
13424- {
13425- if (balance > static_cast<ptrdiff_t>(num_young_huge_region_units_to_consider[kind]))
13426- {
13427- balance -= num_young_huge_region_units_to_consider[kind];
13428- }
13429- else
13430- {
13431- balance = 0;
13432- }
13433- }
13434-
13435- if (
13422+ if ((balance > 0)
1343613423#ifdef BACKGROUND_GC
13437- ( background_running_p() && (settings.condemned_generation != max_generation)) ||
13424+ && (! background_running_p() || (settings.condemned_generation == max_generation))
1343813425#endif
13439- (balance < 0) )
13426+ )
1344013427 {
13441- dprintf (REGIONS_LOG, ("distributing the %zd %s regions deficit", -balance, kind_name[kind]));
13428+ // Ignore young huge regions if they are contributing to a surplus.
13429+ num_regions_to_decommit[kind] =
13430+ max(static_cast<ptrdiff_t>(0),
13431+ (balance - static_cast<ptrdiff_t>(num_young_huge_region_units_to_consider[kind])));
13432+
13433+ balance -= num_regions_to_decommit[kind];
1344213434
13443- #ifdef MULTIPLE_HEAPS
13444- // we may have a deficit or - if background GC is going on - a surplus.
13445- // adjust the budget per heap accordingly
13446- if (balance != 0)
13447- {
13448- ptrdiff_t curr_balance = 0;
13449- ptrdiff_t rem_balance = 0;
13450- for (int i = 0; i < n_heaps; i++)
13451- {
13452- curr_balance += balance;
13453- ptrdiff_t adjustment_per_heap = curr_balance / n_heaps;
13454- curr_balance -= adjustment_per_heap * n_heaps;
13455- ptrdiff_t new_budget = (ptrdiff_t)heap_budget_in_region_units[i][kind] + adjustment_per_heap;
13456- ptrdiff_t min_budget = (kind == basic_free_region) ? (ptrdiff_t)min_heap_budget_in_region_units[i] : 0;
13457- dprintf (REGIONS_LOG, ("adjusting the budget for heap %d from %zd %s regions by %zd to %zd",
13458- i,
13459- heap_budget_in_region_units[i][kind],
13460- kind_name[kind],
13461- adjustment_per_heap,
13462- max (min_budget, new_budget)));
13463- heap_budget_in_region_units[i][kind] = max (min_budget, new_budget);
13464- rem_balance += new_budget - heap_budget_in_region_units[i][kind];
13465- }
13466- assert (rem_balance <= 0);
13467- dprintf (REGIONS_LOG, ("remaining balance: %zd %s regions", rem_balance, kind_name[kind]));
13468-
13469- // if we have a left over deficit, distribute that to the heaps that still have more than the minimum
13470- while (rem_balance < 0)
13471- {
13472- for (int i = 0; i < n_heaps; i++)
13473- {
13474- size_t min_budget = (kind == basic_free_region) ? min_heap_budget_in_region_units[i] : 0;
13475- if (heap_budget_in_region_units[i][kind] > min_budget)
13476- {
13477- dprintf (REGIONS_LOG, ("adjusting the budget for heap %d from %zd %s regions by %d to %zd",
13478- i,
13479- heap_budget_in_region_units[i][kind],
13480- kind_name[kind],
13481- -1,
13482- heap_budget_in_region_units[i][kind] - 1));
13483-
13484- heap_budget_in_region_units[i][kind] -= 1;
13485- rem_balance += 1;
13486- if (rem_balance == 0)
13487- break;
13488- }
13489- }
13490- }
13491- }
13492- #endif //MULTIPLE_HEAPS
13493- }
13494- else
13495- {
13496- num_regions_to_decommit[kind] = balance;
1349713435 dprintf(REGIONS_LOG, ("distributing the %zd %s regions, removing %zd regions",
1349813436 total_budget_in_region_units[kind],
1349913437 kind_name[kind],
@@ -13527,6 +13465,60 @@ void gc_heap::distribute_free_regions()
1352713465 }
1352813466 }
1352913467 }
13468+
13469+ #ifdef MULTIPLE_HEAPS
13470+ if (balance != 0)
13471+ {
13472+ dprintf (REGIONS_LOG, ("distributing the %zd %s regions deficit", -balance, kind_name[kind]));
13473+
13474+ // we may have a deficit or - if background GC is going on - a surplus.
13475+ // adjust the budget per heap accordingly
13476+
13477+ ptrdiff_t curr_balance = 0;
13478+ ptrdiff_t rem_balance = 0;
13479+ for (int i = 0; i < n_heaps; i++)
13480+ {
13481+ curr_balance += balance;
13482+ ptrdiff_t adjustment_per_heap = curr_balance / n_heaps;
13483+ curr_balance -= adjustment_per_heap * n_heaps;
13484+ ptrdiff_t new_budget = (ptrdiff_t)heap_budget_in_region_units[i][kind] + adjustment_per_heap;
13485+ ptrdiff_t min_budget = (kind == basic_free_region) ? (ptrdiff_t)min_heap_budget_in_region_units[i] : 0;
13486+ dprintf (REGIONS_LOG, ("adjusting the budget for heap %d from %zd %s regions by %zd to %zd",
13487+ i,
13488+ heap_budget_in_region_units[i][kind],
13489+ kind_name[kind],
13490+ adjustment_per_heap,
13491+ max (min_budget, new_budget)));
13492+ heap_budget_in_region_units[i][kind] = max (min_budget, new_budget);
13493+ rem_balance += new_budget - heap_budget_in_region_units[i][kind];
13494+ }
13495+ assert (rem_balance <= 0);
13496+ dprintf (REGIONS_LOG, ("remaining balance: %zd %s regions", rem_balance, kind_name[kind]));
13497+
13498+ // if we have a left over deficit, distribute that to the heaps that still have more than the minimum
13499+ while (rem_balance < 0)
13500+ {
13501+ for (int i = 0; i < n_heaps; i++)
13502+ {
13503+ size_t min_budget = (kind == basic_free_region) ? min_heap_budget_in_region_units[i] : 0;
13504+ if (heap_budget_in_region_units[i][kind] > min_budget)
13505+ {
13506+ dprintf (REGIONS_LOG, ("adjusting the budget for heap %d from %zd %s regions by %d to %zd",
13507+ i,
13508+ heap_budget_in_region_units[i][kind],
13509+ kind_name[kind],
13510+ -1,
13511+ heap_budget_in_region_units[i][kind] - 1));
13512+
13513+ heap_budget_in_region_units[i][kind] -= 1;
13514+ rem_balance += 1;
13515+ if (rem_balance == 0)
13516+ break;
13517+ }
13518+ }
13519+ }
13520+ }
13521+ #endif
1353013522 }
1353113523
1353213524 for (int kind = basic_free_region; kind < kind_count; kind++)
0 commit comments