Skip to content

Commit e8ef5b5

Browse files
committed
Revert "Enable GC regions by default (#59283)"
This reverts commit cf91716.
1 parent 126db6d commit e8ef5b5

3 files changed

Lines changed: 44 additions & 98 deletions

File tree

src/coreclr/gc/gc.cpp

Lines changed: 41 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -2522,8 +2522,6 @@ size_t gc_heap::bgc_loh_size_increased = 0;
25222522

25232523
size_t gc_heap::bgc_poh_size_increased = 0;
25242524

2525-
size_t gc_heap::background_soh_size_end_mark = 0;
2526-
25272525
size_t gc_heap::background_soh_alloc_count = 0;
25282526

25292527
size_t gc_heap::background_uoh_alloc_count = 0;
@@ -28894,14 +28892,6 @@ void gc_heap::plan_phase (int condemned_gen_number)
2889428892
{
2889528893
dprintf (2,( "**** Doing Compacting GC ****"));
2889628894

28897-
#if defined(USE_REGIONS) && defined(BACKGROUND_GC)
28898-
if (should_update_end_mark_size())
28899-
{
28900-
background_soh_size_end_mark += generation_end_seg_allocated (older_gen) -
28901-
r_older_gen_end_seg_allocated;
28902-
}
28903-
#endif //USE_REGIONS && BACKGROUND_GC
28904-
2890528895
#ifndef USE_REGIONS
2890628896
if (should_expand)
2890728897
{
@@ -29406,13 +29396,6 @@ void gc_heap::fix_generation_bounds (int condemned_gen_number,
2940629396
}
2940729397
}
2940829398
#endif //MULTIPLE_HEAPS
29409-
29410-
#ifdef BACKGROUND_GC
29411-
if (should_update_end_mark_size())
29412-
{
29413-
background_soh_size_end_mark = generation_size (max_generation);
29414-
}
29415-
#endif //BACKGROUND_GC
2941629399
#endif //!USE_REGIONS
2941729400

2941829401
{
@@ -29631,14 +29614,6 @@ void gc_heap::thread_final_regions (bool compact_p)
2963129614
generation_final_regions[gen_idx].tail = generation_tail_region (gen);
2963229615
}
2963329616

29634-
#ifdef BACKGROUND_GC
29635-
heap_segment* max_gen_tail_region = 0;
29636-
if (should_update_end_mark_size())
29637-
{
29638-
max_gen_tail_region = generation_final_regions[max_generation].tail;
29639-
}
29640-
#endif //BACKGROUND_GC
29641-
2964229617
// Step 2: for each region in the condemned generations, we thread it onto its planned generation
2964329618
// in our generation_final_regions array.
2964429619
for (int gen_idx = condemned_gen_number; gen_idx >= 0; gen_idx--)
@@ -29689,21 +29664,6 @@ void gc_heap::thread_final_regions (bool compact_p)
2968929664
}
2969029665
}
2969129666

29692-
#ifdef BACKGROUND_GC
29693-
if (max_gen_tail_region)
29694-
{
29695-
max_gen_tail_region = heap_segment_next (max_gen_tail_region);
29696-
29697-
while (max_gen_tail_region)
29698-
{
29699-
background_soh_size_end_mark += heap_segment_allocated (max_gen_tail_region) -
29700-
heap_segment_mem (max_gen_tail_region);
29701-
29702-
max_gen_tail_region = heap_segment_next (max_gen_tail_region);
29703-
}
29704-
}
29705-
#endif //BACKGROUND_GC
29706-
2970729667
// Step 4: if a generation doesn't have any regions, we need to get a new one for it;
2970829668
// otherwise we just set the head region as the start region for that generation.
2970929669
for (int gen_idx = 0; gen_idx <= max_generation; gen_idx++)
@@ -32973,11 +32933,6 @@ void gc_heap::decommit_mark_array_by_seg (heap_segment* seg)
3297332933
}
3297432934
}
3297532935

32976-
bool gc_heap::should_update_end_mark_size()
32977-
{
32978-
return ((settings.condemned_generation == (max_generation - 1)) && (current_c_gc_state == c_gc_state_planning));
32979-
}
32980-
3298132936
void gc_heap::background_mark_phase ()
3298232937
{
3298332938
verify_mark_array_cleared();
@@ -33052,7 +33007,6 @@ void gc_heap::background_mark_phase ()
3305233007
bgc_begin_poh_size = total_poh_size;
3305333008
bgc_loh_size_increased = 0;
3305433009
bgc_poh_size_increased = 0;
33055-
background_soh_size_end_mark = 0;
3305633010

3305733011
dprintf (GTC_LOG, ("BM: h%d: loh: %Id, soh: %Id, poh: %Id", heap_number, total_loh_size, total_soh_size, total_poh_size));
3305833012

@@ -33533,8 +33487,6 @@ void gc_heap::background_mark_phase ()
3353333487
heap_segment_background_allocated (seg) = heap_segment_allocated (seg);
3353433488
}
3353533489

33536-
background_soh_size_end_mark += heap_segment_background_allocated (seg) - heap_segment_mem (seg);
33537-
3353833490
dprintf (3333, ("h%d gen%d seg %Ix (%Ix) background allocated is %Ix",
3353933491
heap_number, i, (size_t)(seg), heap_segment_mem (seg),
3354033492
heap_segment_background_allocated (seg)));
@@ -45151,11 +45103,11 @@ size_t GCHeap::GetTotalBytesInUse ()
4515145103
for (int i = 0; i < gc_heap::n_heaps; i++)
4515245104
{
4515345105
GCHeap* Hp = gc_heap::g_heaps [i]->vm_heap;
45154-
tot_size += Hp->ApproxTotalBytesInUse();
45106+
tot_size += Hp->ApproxTotalBytesInUse (FALSE);
4515545107
}
4515645108
return tot_size;
4515745109
#else
45158-
return ApproxTotalBytesInUse();
45110+
return ApproxTotalBytesInUse ();
4515945111
#endif //MULTIPLE_HEAPS
4516045112
}
4516145113

@@ -45210,58 +45162,58 @@ size_t GCHeap::ApproxTotalBytesInUse(BOOL small_heap_only)
4521045162
size_t totsize = 0;
4521145163
enter_spin_lock (&pGenGCHeap->gc_lock);
4521245164

45213-
// For gen0 it's a bit complicated because we are currently allocating in it. We get the fragmentation first
45214-
// just so that we don't give a negative number for the resulting size.
45215-
generation* gen = pGenGCHeap->generation_of (0);
45216-
size_t gen0_frag = generation_free_list_space (gen) + generation_free_obj_space (gen);
45217-
uint8_t* current_alloc_allocated = pGenGCHeap->alloc_allocated;
45218-
heap_segment* current_eph_seg = pGenGCHeap->ephemeral_heap_segment;
45219-
size_t gen0_size = 0;
45220-
#ifdef USE_REGIONS
45221-
heap_segment* gen0_seg = generation_start_segment (gen);
45222-
while (gen0_seg)
45165+
// the complication with the following code is that background GC may
45166+
// remove the ephemeral segment while we are iterating
45167+
// if so, we retry a couple times and ultimately may report a slightly wrong result
45168+
for (int tries = 1; tries <= 3; tries++)
4522345169
{
45224-
uint8_t* end = in_range_for_segment (current_alloc_allocated, gen0_seg) ?
45225-
current_alloc_allocated : heap_segment_allocated (gen0_seg);
45226-
gen0_size += end - heap_segment_mem (gen0_seg);
45227-
45228-
if (gen0_seg == current_eph_seg)
45170+
heap_segment* eph_seg = generation_allocation_segment (pGenGCHeap->generation_of (0));
45171+
// Get small block heap size info
45172+
totsize = (pGenGCHeap->alloc_allocated - heap_segment_mem (eph_seg));
45173+
heap_segment* seg1 = generation_start_segment (pGenGCHeap->generation_of (max_generation));
45174+
while ((seg1 != eph_seg) && (seg1 != nullptr)
45175+
#ifdef BACKGROUND_GC
45176+
&& (seg1 != pGenGCHeap->freeable_soh_segment)
45177+
#endif //BACKGROUND_GC
45178+
)
4522945179
{
45230-
break;
45180+
#ifdef BACKGROUND_GC
45181+
if (!heap_segment_decommitted_p (seg1))
45182+
#endif //BACKGROUND_GC
45183+
{
45184+
totsize += heap_segment_allocated (seg1) -
45185+
heap_segment_mem (seg1);
45186+
}
45187+
seg1 = heap_segment_next (seg1);
4523145188
}
45232-
45233-
gen0_seg = heap_segment_next (gen0_seg);
45234-
}
45235-
#else //USE_REGIONS
45236-
// For segments ephemeral seg does not change.
45237-
gen0_size = current_alloc_allocated - heap_segment_mem (current_eph_seg);
45238-
#endif //USE_REGIONS
45239-
45240-
totsize = gen0_size - gen0_frag;
45241-
45242-
int stop_gen_index = max_generation;
45243-
45244-
if (gc_heap::current_c_gc_state == c_gc_state_planning)
45245-
{
45246-
// During BGC sweep since we can be deleting SOH segments, we avoid walking the segment
45247-
// list.
45248-
generation* oldest_gen = pGenGCHeap->generation_of (max_generation);
45249-
totsize = pGenGCHeap->background_soh_size_end_mark - generation_free_list_space (oldest_gen) - generation_free_obj_space (oldest_gen);
45250-
stop_gen_index--;
45189+
if (seg1 == eph_seg)
45190+
break;
4525145191
}
4525245192

45253-
for (int i = (max_generation - 1); i <= stop_gen_index; i++)
45193+
//discount the fragmentation
45194+
for (int i = 0; i <= max_generation; i++)
4525445195
{
4525545196
generation* gen = pGenGCHeap->generation_of (i);
45256-
totsize += pGenGCHeap->generation_size (i) - generation_free_list_space (gen) - generation_free_obj_space (gen);
45197+
totsize -= (generation_free_list_space (gen) + generation_free_obj_space (gen));
4525745198
}
4525845199

4525945200
if (!small_heap_only)
4526045201
{
4526145202
for (int i = uoh_start_generation; i < total_generation_count; i++)
4526245203
{
45263-
generation* gen = pGenGCHeap->generation_of (i);
45264-
totsize += pGenGCHeap->generation_size (i) - generation_free_list_space (gen) - generation_free_obj_space (gen);
45204+
heap_segment* seg2 = generation_start_segment (pGenGCHeap->generation_of (i));
45205+
45206+
while (seg2 != 0)
45207+
{
45208+
totsize += heap_segment_allocated (seg2) -
45209+
heap_segment_mem (seg2);
45210+
seg2 = heap_segment_next (seg2);
45211+
}
45212+
45213+
//discount the fragmentation
45214+
generation* uoh_gen = pGenGCHeap->generation_of (i);
45215+
size_t frag = generation_free_list_space (uoh_gen) + generation_free_obj_space (uoh_gen);
45216+
totsize -= frag;
4526545217
}
4526645218
}
4526745219
leave_spin_lock (&pGenGCHeap->gc_lock);

src/coreclr/gc/gcpriv.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ inline void FATAL_GC_ERROR()
5151
//
5252
// This means any empty regions can be freely used for any generation. For
5353
// Server GC we will balance regions between heaps.
54-
// For now disable regions StandAlone GC builds
55-
#if defined (HOST_64BIT) && !defined (BUILD_AS_STANDALONE)
54+
// For now enable regions by default for only StandAlone GC builds
55+
#if defined (HOST_64BIT) && defined (BUILD_AS_STANDALONE)
5656
#define USE_REGIONS
5757
#endif //HOST_64BIT && BUILD_AS_STANDALONE
5858

@@ -3440,9 +3440,6 @@ class gc_heap
34403440
PER_HEAP
34413441
void decommit_mark_array_by_seg (heap_segment* seg);
34423442

3443-
PER_HEAP_ISOLATED
3444-
bool should_update_end_mark_size();
3445-
34463443
PER_HEAP
34473444
void background_mark_phase();
34483445

@@ -4271,9 +4268,6 @@ class gc_heap
42714268
PER_HEAP
42724269
size_t bgc_poh_size_increased;
42734270

4274-
PER_HEAP
4275-
size_t background_soh_size_end_mark;
4276-
42774271
PER_HEAP
42784272
size_t background_soh_alloc_count;
42794273

src/coreclr/nativeaot/Runtime/gcrhenv.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,7 @@ void GCToEEInterface::DisablePreemptiveGC()
923923
Thread* GCToEEInterface::GetThread()
924924
{
925925
#ifndef DACCESS_COMPILE
926-
return ThreadStore::GetCurrentThreadIfAvailable();
926+
return ThreadStore::GetCurrentThread();
927927
#else
928928
return NULL;
929929
#endif

0 commit comments

Comments
 (0)