[MLton] A few changes proposals for MLton

Matthew Fluet fluet at tti-c.org
Tue Nov 18 19:46:48 PST 2008


On Mon, 17 Nov 2008, Nicolas Bertolotti wrote:
> I am also not really sure that the proposed operation:
>> +  maxSize = alignDown(SIZE_MAX, s->sysvals.pageSize);
>> +  maxSize -= sizeofCardMapAndCrossMap(s, maxSize);
> really returns the exact maximum size for a heap. It is not really an 
> issue but you may think of a better way.

True, your operation yields a maxSize that is slightly smaller than 
necessary, because it uses a larger than necessary card/cross map size.
One could write an invertSizeofCardMapAndCrossMap function such that:

   heapSize = invertSizeofCardMapAndCrossMap (s, heapWithMapsSize);

implies

   heapSize + sizeofCardMapAndCrossMap (s, heapSize)
   <= heapWithMapsSize
   < (heapSize + s->sysvals.pageSize)
      + sizeofCardMapAndCrossMap (s, heapSize + s->sysvals.pageSize)

which yields the largest (up to the pageSize) heapSize such that adding 
its card/cross map size requires space less than or equal to the input 
heapWithMapsSize.

According to my calculations, your operation yields:
   maxSize = 4,294,963,200 - 33,554,432
           = 4,261,408,768
with
   sizeofCardMapAndCrossMap(maxSize) = 33,292,288
and
   maxSize + sizeofCardMapAndCrossMap(maxSize) = 4,294,701,056

However, one could take:
   maxSize = 4,261,662,720
with
   sizeofCardMapAndCrossMap(maxSize) = 33,300,480
and
   maxSize + sizeofCardMapAndCrossMap(maxSize) = 4,294,963,200

In practice, though, either of these values for maxSize is well above what 
is available in a contiguous mmap allocation (either with mremap or after 
dumping the heap to disk).

> It could also be slightly more efficient to compute this value only once 
> at the beginning of the execution.

Agreed, although sizeofHeapDesired isn't on a critical path, so I doubt 
that it would have any measurable effect.



More information about the MLton mailing list