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

fix for excessive gen0 in high memory load situation #61884

Merged
merged 2 commits into from
Nov 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
33 changes: 18 additions & 15 deletions src/coreclr/gc/gc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7151,7 +7151,6 @@ void gc_mechanisms::init_mechanisms()
found_finalizers = FALSE;
#ifdef BACKGROUND_GC
background_p = gc_heap::background_running_p() != FALSE;
allocations_allowed = TRUE;
Maoni0 marked this conversation as resolved.
Show resolved Hide resolved
#endif //BACKGROUND_GC

entry_memory_load = 0;
Expand Down Expand Up @@ -7444,15 +7443,6 @@ void gc_heap::reset_allocation_pointers (generation* gen, uint8_t* start)

bool gc_heap::new_allocation_allowed (int gen_number)
{
#ifdef BACKGROUND_GC
//TODO BACKGROUND_GC this is for test only
if (!settings.allocations_allowed)
{
dprintf (2, ("new allocation not allowed"));
return FALSE;
}
#endif //BACKGROUND_GC

if (dd_new_allocation (dynamic_data_of (gen_number)) < 0)
{
if (gen_number != 0)
Expand Down Expand Up @@ -16071,18 +16061,22 @@ void gc_heap::wait_for_background (alloc_wait_reason awr, bool loh_p)
add_saved_spinlock_info (loh_p, me_acquire, mt_wait_bgc);
}

void gc_heap::wait_for_bgc_high_memory (alloc_wait_reason awr, bool loh_p)
bool gc_heap::wait_for_bgc_high_memory (alloc_wait_reason awr, bool loh_p)
{
bool wait_p = false;
if (gc_heap::background_running_p())
{
uint32_t memory_load;
get_memory_info (&memory_load);
if (memory_load >= m_high_memory_load_th)
{
wait_p = true;
dprintf (GTC_LOG, ("high mem - wait for BGC to finish, wait reason: %d", awr));
wait_for_background (awr, loh_p);
}
}

return wait_p;
}

#endif //BACKGROUND_GC
Expand Down Expand Up @@ -17190,18 +17184,27 @@ allocation_state gc_heap::try_allocate_more_space (alloc_context* acontext, size
}

#ifdef BACKGROUND_GC
wait_for_bgc_high_memory (awr_gen0_alloc, loh_p);
bool recheck_p = wait_for_bgc_high_memory (awr_gen0_alloc, loh_p);
#endif //BACKGROUND_GC

#ifdef SYNCHRONIZATION_STATS
bad_suspension++;
#endif //SYNCHRONIZATION_STATS
dprintf (2, ("h%d running out of budget on gen%d, gc", heap_number, gen_number));

if (!settings.concurrent || (gen_number == 0))
#ifdef BACKGROUND_GC
bool trigger_gc_p = true;
if (recheck_p)
trigger_gc_p = !(new_allocation_allowed (gen_number));
Maoni0 marked this conversation as resolved.
Show resolved Hide resolved

if (trigger_gc_p)
#endif //BACKGROUND_GC
{
trigger_gc_for_alloc (0, ((gen_number == 0) ? reason_alloc_soh : reason_alloc_loh),
msl, loh_p, mt_try_budget);
if (!settings.concurrent || (gen_number == 0))
{
trigger_gc_for_alloc (0, ((gen_number == 0) ? reason_alloc_soh : reason_alloc_loh),
msl, loh_p, mt_try_budget);
}
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/coreclr/gc/gcpriv.h
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,6 @@ class gc_mechanisms
#ifdef BACKGROUND_GC
BOOL background_p;
bgc_state b_state;
BOOL allocations_allowed;
#endif //BACKGROUND_GC

#ifdef STRESS_HEAP
Expand Down Expand Up @@ -1791,7 +1790,7 @@ class gc_heap
void wait_for_background (alloc_wait_reason awr, bool loh_p);

PER_HEAP
void wait_for_bgc_high_memory (alloc_wait_reason awr, bool loh_p);
bool wait_for_bgc_high_memory (alloc_wait_reason awr, bool loh_p);

PER_HEAP
void bgc_uoh_alloc_clr (uint8_t* alloc_start,
Expand Down