From f12399ef7dfdf792c1bc0782a49e18a3c2bce632 Mon Sep 17 00:00:00 2001 From: Andy Wingo Date: Fri, 23 May 2025 09:38:36 +0200 Subject: [PATCH] mmc: Only add headroom to unfragmentable heaps if no progress --- src/mmc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/mmc.c b/src/mmc.c index cd5b93be7..b35fd58b1 100644 --- a/src/mmc.c +++ b/src/mmc.c @@ -586,9 +586,11 @@ grow_heap_if_necessary(struct gc_heap *heap, struct nofl_space *nofl = heap_nofl_space(heap); size_t pending = nofl_space_shrink(nofl, 0); + // If we cannot defragment and are making no progress but have a + // growable heap, expand by 25% to add some headroom. size_t needed_headroom = GC_CONSERVATIVE_TRACE - ? nofl_active_block_count (nofl) * NOFL_BLOCK_SIZE / 16 + ? (progress ? 0 : nofl_active_block_count (nofl) * NOFL_BLOCK_SIZE / 4) : 0; size_t headroom = nofl_empty_block_count(nofl) * NOFL_BLOCK_SIZE;