From 543ce4f4bef4e84c7b1cda7247f6a1e9db04b772 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Wed, 28 Jul 2021 21:57:48 -0400 Subject: [PATCH] Initiate major GC after a huge heap allocation This allows us to reclaim the memory faster and keep memory usage lower. --- CHANGELOG.md | 3 +++ gc.c | 11 +++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f140b51d..70f6b75a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## TBD +Features + +- Initiate major garbage collections faster after allocating a huge object (more than 500K). This allows the system to reclaim the memory faster and keep overall memory usage low for certain workloads. ## 0.31.0 - July 27, 2021 diff --git a/gc.c b/gc.c index 9483d019..ef18187c 100644 --- a/gc.c +++ b/gc.c @@ -1447,9 +1447,16 @@ fprintf(stderr, "slowest alloc of %p\n", result); #endif if (result) { // We had to allocate memory, start a major collection ASAP! - if (heap_type != HEAP_HUGE) { + // + // Huge heaps are a special case because we always allocate a new page + // for them. However, we still initiate a collection for them, giving + // us a convenient way to handle short-lived HUGE objects. In practice + // this makes a BIG difference in memory usage for the array1 benchmark. + // Longer-term there may be a better way to deal with huge objects. + // + //if (heap_type != HEAP_HUGE) { gc_start_major_collection(thd); - } + //} } else { fprintf(stderr, "out of memory error allocating %zu bytes\n", size); fprintf(stderr, "Heap type %d diagnostics:\n", heap_type);