Skip to content

Commit c8cf3b0

Browse files
authored
Added the hard_limit_exceeded_p back as without it, we won't be retrying another heap to fit the new allocation. (#67724)
* Added the `hard_limit_exceeded_p` back as without it, we will be not retrying another heap. * Added fix for the setting commit_failed_p = TRUE only in the regions case * Addressed feedback for the case where the heap hard limit isn't set for regions * Fix based on feedback: * Using positive directive logic
1 parent cdc0ffd commit c8cf3b0

2 files changed

Lines changed: 26 additions & 6 deletions

File tree

src/coreclr/gc/gc.cpp

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6803,7 +6803,7 @@ bool gc_heap::virtual_alloc_commit_for_heap (void* addr, size_t size, int h_numb
68036803
return GCToOSInterface::VirtualCommit(addr, size);
68046804
}
68056805

6806-
bool gc_heap::virtual_commit (void* address, size_t size, gc_oh_num oh, int h_number)
6806+
bool gc_heap::virtual_commit (void* address, size_t size, gc_oh_num oh, int h_number, bool* hard_limit_exceeded_p)
68076807
{
68086808
#ifndef HOST_64BIT
68096809
assert (heap_hard_limit == 0);
@@ -6841,6 +6841,9 @@ bool gc_heap::virtual_commit (void* address, size_t size, gc_oh_num oh, int h_nu
68416841

68426842
check_commit_cs.Leave();
68436843

6844+
if (hard_limit_exceeded_p)
6845+
*hard_limit_exceeded_p = exceeded_p;
6846+
68446847
if (exceeded_p)
68456848
{
68466849
dprintf (1, ("can't commit %Ix for %Id bytes > HARD LIMIT %Id", (size_t)address, size, heap_hard_limit));
@@ -14217,10 +14220,13 @@ BOOL gc_heap::a_size_fit_p (size_t size, uint8_t* alloc_pointer, uint8_t* alloc_
1421714220
}
1421814221

1421914222
// Grow by committing more pages
14220-
BOOL gc_heap::grow_heap_segment (heap_segment* seg, uint8_t* high_address)
14223+
BOOL gc_heap::grow_heap_segment (heap_segment* seg, uint8_t* high_address, bool* hard_limit_exceeded_p)
1422114224
{
1422214225
assert (high_address <= heap_segment_reserved (seg));
1422314226

14227+
if (hard_limit_exceeded_p)
14228+
*hard_limit_exceeded_p = false;
14229+
1422414230
//return 0 if we are at the end of the segment.
1422514231
if (align_on_page (high_address) > heap_segment_reserved (seg))
1422614232
return FALSE;
@@ -14239,7 +14245,7 @@ BOOL gc_heap::grow_heap_segment (heap_segment* seg, uint8_t* high_address)
1423914245
"Growing heap_segment: %Ix high address: %Ix\n",
1424014246
(size_t)seg, (size_t)high_address);
1424114247

14242-
bool ret = virtual_commit (heap_segment_committed (seg), c_size, heap_segment_oh (seg), heap_number);
14248+
bool ret = virtual_commit (heap_segment_committed (seg), c_size, heap_segment_oh (seg), heap_number, hard_limit_exceeded_p);
1424314249
if (ret)
1424414250
{
1424514251
heap_segment_committed (seg) += c_size;
@@ -16124,6 +16130,7 @@ BOOL gc_heap::a_fit_segment_end_p (int gen_number,
1612416130
{
1612516131
*commit_failed_p = FALSE;
1612616132
size_t limit = 0;
16133+
bool hard_limit_short_seg_end_p = false;
1612716134
#ifdef BACKGROUND_GC
1612816135
int cookie = -1;
1612916136
#endif //BACKGROUND_GC
@@ -16162,13 +16169,26 @@ BOOL gc_heap::a_fit_segment_end_p (int gen_number,
1616216169
(end - allocated),
1616316170
gen_number, align_const);
1616416171

16165-
if (grow_heap_segment (seg, (allocated + limit)))
16172+
if (grow_heap_segment (seg, (allocated + limit), &hard_limit_short_seg_end_p))
1616616173
{
1616716174
goto found_fit;
1616816175
}
16176+
1616916177
else
1617016178
{
16179+
#ifdef USE_REGIONS
1617116180
*commit_failed_p = TRUE;
16181+
#else
16182+
if (!hard_limit_short_seg_end_p)
16183+
{
16184+
dprintf (2, ("can't grow segment, doing a full gc"));
16185+
*commit_failed_p = TRUE;
16186+
}
16187+
else
16188+
{
16189+
assert (heap_hard_limit);
16190+
}
16191+
#endif // USE_REGIONS
1617216192
}
1617316193
}
1617416194

src/coreclr/gc/gcpriv.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2027,7 +2027,7 @@ class gc_heap
20272027
PER_HEAP_ISOLATED
20282028
bool virtual_alloc_commit_for_heap (void* addr, size_t size, int h_number);
20292029
PER_HEAP_ISOLATED
2030-
bool virtual_commit (void* address, size_t size, gc_oh_num oh, int h_number=-1);
2030+
bool virtual_commit (void* address, size_t size, gc_oh_num oh, int h_number=-1, bool* hard_limit_exceeded_p=NULL);
20312031
PER_HEAP_ISOLATED
20322032
bool virtual_decommit (void* address, size_t size, gc_oh_num oh, int h_number=-1);
20332033
PER_HEAP_ISOLATED
@@ -2128,7 +2128,7 @@ class gc_heap
21282128
BOOL find_card (uint32_t* card_table, size_t& card,
21292129
size_t card_word_end, size_t& end_card);
21302130
PER_HEAP
2131-
BOOL grow_heap_segment (heap_segment* seg, uint8_t* high_address);
2131+
BOOL grow_heap_segment (heap_segment* seg, uint8_t* high_address, bool* hard_limit_exceeded_p=NULL);
21322132
PER_HEAP
21332133
int grow_heap_segment (heap_segment* seg, uint8_t* high_address, uint8_t* old_loc, size_t size, BOOL pad_front_p REQD_ALIGN_AND_OFFSET_DCL);
21342134
PER_HEAP

0 commit comments

Comments
 (0)