[前][次][番号順一覧][スレッド一覧]

ruby-changes:72624

From: Peter <ko1@a...>
Date: Thu, 21 Jul 2022 23:46:48 +0900 (JST)
Subject: [ruby-changes:72624] cdbb9b8555 (master): [Bug #18929] Fix heap creation thrashing in GC

https://git.ruby-lang.org/ruby.git/commit/?id=cdbb9b8555

From cdbb9b8555b4ddcc4c557f25ad785cae6209478d Mon Sep 17 00:00:00 2001
From: Peter Zhu <peter@p...>
Date: Wed, 20 Jul 2022 13:29:34 -0400
Subject: [Bug #18929] Fix heap creation thrashing in GC

Before this commit, if we don't have enough slots after sweeping but
had pages on the tomb heap, then the GC would frequently allocate and
deallocate pages. This is because after sweeping it would set
allocatable pages (since there were not enough slots) but free the
pages on the tomb heap.

This commit reuses pages on the tomb heap if there's not enough slots
after sweeping.
---
 gc.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/gc.c b/gc.c
index 4f92c371be..4b619fd33f 100644
--- a/gc.c
+++ b/gc.c
@@ -5810,6 +5810,19 @@ gc_sweep_finish_size_pool(rb_objspace_t *objspace, rb_size_pool_t *size_pool) https://github.com/ruby/ruby/blob/trunk/gc.c#L5810
         min_free_slots = gc_params.heap_init_slots;
     }
 
+    /* If we don't have enough slots and we have pages on the tomb heap, move
+     * pages from the tomb heap to the eden heap. This may prevent page
+     * creation thrashing (frequently allocating and deallocting pages) and
+     * GC thrashing (running GC more frequently than required). */
+    struct heap_page *resurrected_page;
+    while (swept_slots < min_free_slots &&
+            (resurrected_page = heap_page_resurrect(objspace, size_pool))) {
+        swept_slots += resurrected_page->free_slots;
+
+        heap_add_page(objspace, size_pool, heap, resurrected_page);
+        heap_add_freepage(heap, resurrected_page);
+    }
+
     if (swept_slots < min_free_slots) {
         bool grow_heap = is_full_marking(objspace);
 
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]