summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTeo Camarasu <teofilcamarasu@gmail.com>2022-08-02 15:45:27 +0100
committerTeo Camarasu <teofilcamarasu@gmail.com>2022-10-15 18:09:24 +0100
commit29bb90db7e0756cd7dda96d9a61c3ab0abe769c2 (patch)
treea64bdd6fa2ba3c85e6598c22d71dc251c914f8e3
parent54e41b164f79ad74c33f556fc82d042441ed3bfb (diff)
downloadhaskell-29bb90db7e0756cd7dda96d9a61c3ab0abe769c2.tar.gz
rts: trigger a major collection if megablock usage exceeds maxHeapSize
When the heap is suffering from block fragmentation, live bytes might be low while megablock usage is high. If megablock usage exceeds maxHeapSize, we want to trigger a major GC to try to recover some memory otherwise we will die from a heapOverflow at the end of the GC. Fixes #21927
-rw-r--r--rts/Schedule.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/rts/Schedule.c b/rts/Schedule.c
index 028578d6dc..76ce2b7567 100644
--- a/rts/Schedule.c
+++ b/rts/Schedule.c
@@ -1592,9 +1592,13 @@ scheduleDoGC (Capability **pcap, Task *task USED_IF_THREADS,
heap_census = scheduleNeedHeapProfile(true);
+ // We force a major collection if the size of the heap exceeds maxHeapSize.
+ // We will either return memory until we are below maxHeapSize or trigger heapOverflow.
+ bool mblock_overflow = RtsFlags.GcFlags.maxHeapSize != 0 && mblocks_allocated > BLOCKS_TO_MBLOCKS(RtsFlags.GcFlags.maxHeapSize);
+
// Figure out which generation we are collecting, so that we can
// decide whether this is a parallel GC or not.
- collect_gen = calcNeeded(force_major || heap_census, NULL);
+ collect_gen = calcNeeded(force_major || heap_census || mblock_overflow , NULL);
major_gc = (collect_gen == RtsFlags.GcFlags.generations-1);
#if defined(THREADED_RTS)