Create a RTS API function that zeros out all unused memory
I'd like to create a RTS API function that zeros out all unused memory on the heap.
The main use case is for the wasm backend. It's possible to create a wasm module, initialize the RTS state, run some Haskell computation, then snapshot the entire memory state into a new wasm module. This allows the module to be deployed without any initialization overhead, especially when the initialization logic may involve some expensive computation. However, when snapshotting the memory state, some garbage data will be snapshotted as well, since the RTS doesn't zero out the freed blocks. This is a source of unnecessary code bloat.
There's the -DZ
debug option that enables RtsFlags.DebugFlags.zero_on_gc
, but we can't use that since it's intended for the debug RTS only, and it actually fills 0xAA instead of zero.
Hence the proposal here: a single RTS API function that traverses the block allocator free list and zeros out all unused memory. It doesn't impact other platforms in any way.