Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 9783827

Browse files
authored
oom (#26457) (#26983)
+ when hardlimit is specified we should only retry when we didn't fail due to commit failure - if commit failed it means we simply didn't have as much memory as what the hardlimit specified. we should throw OOM in this case. + added some diag info around OOM history to help with future diagnostics. (cherry picked from commit 7dca41f)
1 parent e02a3e1 commit 9783827

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/gc/gc.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2611,6 +2611,10 @@ exclusive_sync* gc_heap::bgc_alloc_lock;
26112611

26122612
oom_history gc_heap::oom_info;
26132613

2614+
int gc_heap::oomhist_index_per_heap = 0;
2615+
2616+
oom_history gc_heap::oomhist_per_heap[max_oom_history_count];
2617+
26142618
fgm_history gc_heap::fgm_result;
26152619

26162620
size_t gc_heap::allocated_since_last_gc = 0;
@@ -10917,6 +10921,8 @@ gc_heap::init_gc_heap (int h_number)
1091710921

1091810922
ephemeral_heap_segment = 0;
1091910923

10924+
oomhist_index_per_heap = 0;
10925+
1092010926
freeable_large_heap_segment = 0;
1092110927

1092210928
condemned_generation_num = 0;
@@ -12146,6 +12152,17 @@ size_t gc_heap::limit_from_size (size_t size, uint32_t flags, size_t physical_li
1214612152
return new_limit;
1214712153
}
1214812154

12155+
void gc_heap::add_to_oom_history_per_heap()
12156+
{
12157+
oom_history* current_hist = &oomhist_per_heap[oomhist_index_per_heap];
12158+
memcpy (current_hist, &oom_info, sizeof (oom_info));
12159+
oomhist_index_per_heap++;
12160+
if (oomhist_index_per_heap == max_oom_history_count)
12161+
{
12162+
oomhist_index_per_heap = 0;
12163+
}
12164+
}
12165+
1214912166
void gc_heap::handle_oom (int heap_num, oom_reason reason, size_t alloc_size,
1215012167
uint8_t* allocated, uint8_t* reserved)
1215112168
{
@@ -12175,6 +12192,7 @@ void gc_heap::handle_oom (int heap_num, oom_reason reason, size_t alloc_size,
1217512192
oom_info.available_pagefile_mb = fgm_result.available_pagefile_mb;
1217612193
oom_info.loh_p = fgm_result.loh_p;
1217712194

12195+
add_to_oom_history_per_heap();
1217812196
fgm_result.fgm = fgm_no_failure;
1217912197

1218012198
// Break early - before the more_space_lock is release so no other threads
@@ -13775,7 +13793,8 @@ allocation_state gc_heap::allocate_large (int gen_number,
1377513793
if (loh_alloc_state == a_state_cant_allocate)
1377613794
{
1377713795
assert (oom_r != oom_no_failure);
13778-
if (should_retry_other_heap (size))
13796+
13797+
if ((oom_r != oom_cant_commit) && should_retry_other_heap (size))
1377913798
{
1378013799
loh_alloc_state = a_state_retry_allocate;
1378113800
}

src/gc/gcpriv.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2908,6 +2908,17 @@ class gc_heap
29082908

29092909
// End DAC zone
29102910

2911+
#define max_oom_history_count 4
2912+
2913+
PER_HEAP
2914+
int oomhist_index_per_heap;
2915+
2916+
PER_HEAP
2917+
oom_history oomhist_per_heap[max_oom_history_count];
2918+
2919+
PER_HEAP
2920+
void add_to_oom_history_per_heap();
2921+
29112922
PER_HEAP
29122923
BOOL expanded_in_fgc;
29132924

0 commit comments

Comments
 (0)