diff options
author | Teo Camarasu <teofilcamarasu@gmail.com> | 2022-08-02 15:40:02 +0100 |
---|---|---|
committer | Teo Camarasu <teofilcamarasu@gmail.com> | 2022-10-15 18:09:24 +0100 |
commit | 54e41b164f79ad74c33f556fc82d042441ed3bfb (patch) | |
tree | 1a63d3bb8eecc2ca7f6300fd2384a8ca89006d8d /rts | |
parent | 62a550010ed94e1969c96150f2781854a0802766 (diff) | |
download | haskell-54e41b164f79ad74c33f556fc82d042441ed3bfb.tar.gz |
rts: ensure we are below maxHeapSize after returning megablocks
When the heap is heavily block fragmented the live byte size might be
low while the memory usage is high. We want to ensure that heap overflow
triggers in these cases.
We do so by checking that we can return enough megablocks to
under maxHeapSize at the end of GC.
Diffstat (limited to 'rts')
-rw-r--r-- | rts/sm/GC.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/rts/sm/GC.c b/rts/sm/GC.c index e60fb314d8..e1930c224b 100644 --- a/rts/sm/GC.c +++ b/rts/sm/GC.c @@ -1061,6 +1061,13 @@ GarbageCollect (uint32_t collect_gen, returned = returnMemoryToOS(got - need); } traceEventMemReturn(cap, got, need, returned); + + // Ensure that we've returned enough mblocks to place us under maxHeapSize. + // This may fail for instance due to block fragmentation. + W_ after = got - returned; + if (RtsFlags.GcFlags.maxHeapSize != 0 && after > BLOCKS_TO_MBLOCKS(RtsFlags.GcFlags.maxHeapSize)) { + heapOverflow(); + } } // extra GC trace info |