[MLton] Crash fread(...) failed (only read 0) (Cannot allocate memory) during deepFlatten with MLton 20070826

Nicolas Bertolotti Nicolas.Bertolotti at mathworks.fr
Tue Apr 22 15:37:35 PDT 2008


> > One thing I notice is that when writing the heap to disk, we do not
> > release the card/cross maps.  Although with a 1.6G heap, these are only
> > 12.8M, if they happen to fall in the middle of the virtual address
> space,
> > then it may not be possible to find the requested 1.6G heap.
> >
> > You could try the attached patch, which releases the card/cross maps
> after
> > writing the heap to disk.

I could notice that, when the heap is copied to the disk and createHeap() is called to allocate a new heap, there are multiple iterations of the "backoff" loop before mmap() succeeds. As a consequence, the newly allocated heap is not as big as what the GC algorithm would normally expect.

Using your latest patch (still combined with mine), I could notice that we don't loop anymore and the new heap size corresponds to what the GC algorithm expects (Then, I guess it will also make it possible to run more instructions without entering GC again).

So, it really seems that releasing the card/cross map before allocating the heap is a good way to reduce memory fragmentation.

It might be interesting to release and rebuild the card/cross map in other circumstances in order to achieve better performances:
- if remapHeap() fails, we could retry after releasing the card/cross map before deciding to create a new heap and copy the existing one.
- if createHeap() fails, we could retry after releasing the card/cross map before deciding to back up the existing heap to the disk.

... it depends on what the cost of rebuilding the card/cross map is (for the 2nd option, I guess it is certainly much less than transferring 1.5 Gb to disk).

What do you think?

Nicolas

P.S.: the compilation no longer crashes on my 2 Gb machine so it seems that the initial issue has now been fully fixed.

Unfortunately, the compilation swaps a lot (really a lot) during deepFlatten and I'm afraid it has become impossible to build the product using a machine that has less than 3 Gb of RAM. Any idea about what we could do to limit the memory consumption during this phase?




More information about the MLton mailing list