oom (#26457) (#26983)
authorMaoni Stephens <Maoni0@users.noreply.github.com>
Thu, 3 Oct 2019 19:44:36 +0000 (12:44 -0700)
committerGitHub <noreply@github.com>
Thu, 3 Oct 2019 19:44:36 +0000 (12:44 -0700)
+ 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 7dca41fd36721068e610c537654765e8e42275d7)

src/gc/gc.cpp
src/gc/gcpriv.h

index f493664..ec2b855 100644 (file)
@@ -2611,6 +2611,10 @@ exclusive_sync* gc_heap::bgc_alloc_lock;
 
 oom_history gc_heap::oom_info;
 
+int         gc_heap::oomhist_index_per_heap = 0;
+
+oom_history gc_heap::oomhist_per_heap[max_oom_history_count];
+
 fgm_history gc_heap::fgm_result;
 
 size_t      gc_heap::allocated_since_last_gc = 0;
@@ -10917,6 +10921,8 @@ gc_heap::init_gc_heap (int  h_number)
 
     ephemeral_heap_segment = 0;
 
+    oomhist_index_per_heap = 0;
+
     freeable_large_heap_segment = 0;
 
     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
     return new_limit;
 }
 
+void gc_heap::add_to_oom_history_per_heap()
+{
+    oom_history* current_hist = &oomhist_per_heap[oomhist_index_per_heap];
+    memcpy (current_hist, &oom_info, sizeof (oom_info));
+    oomhist_index_per_heap++;
+    if (oomhist_index_per_heap == max_oom_history_count)
+    {
+        oomhist_index_per_heap = 0;
+    }
+}
+
 void gc_heap::handle_oom (int heap_num, oom_reason reason, size_t alloc_size, 
                           uint8_t* allocated, uint8_t* reserved)
 {
@@ -12175,6 +12192,7 @@ void gc_heap::handle_oom (int heap_num, oom_reason reason, size_t alloc_size,
     oom_info.available_pagefile_mb = fgm_result.available_pagefile_mb;
     oom_info.loh_p = fgm_result.loh_p;
 
+    add_to_oom_history_per_heap();
     fgm_result.fgm = fgm_no_failure;
 
     // Break early - before the more_space_lock is release so no other threads
@@ -13775,7 +13793,8 @@ exit:
     if (loh_alloc_state == a_state_cant_allocate)
     {
         assert (oom_r != oom_no_failure);
-        if (should_retry_other_heap (size))
+
+        if ((oom_r != oom_cant_commit) && should_retry_other_heap (size))
         {
             loh_alloc_state = a_state_retry_allocate;
         }
index c194c54..5099d6c 100644 (file)
@@ -2908,6 +2908,17 @@ public:
 
     // End DAC zone
 
+#define max_oom_history_count 4
+
+    PER_HEAP
+    int oomhist_index_per_heap;
+
+    PER_HEAP
+    oom_history oomhist_per_heap[max_oom_history_count];
+
+    PER_HEAP
+    void add_to_oom_history_per_heap();
+
     PER_HEAP
     BOOL expanded_in_fgc;