Initiate major GC after a huge heap allocation

This allows us to reclaim the memory faster and keep memory usage lower.
This commit is contained in:
Justin Ethier 2021-07-28 21:57:48 -04:00
parent b76b6974b2
commit 543ce4f4be
2 changed files with 12 additions and 2 deletions

View file

@ -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

11
gc.c
View file

@ -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);