[MLton] A few changes proposals for MLton

Nicolas Bertolotti Nicolas.Bertolotti at mathworks.fr
Mon Nov 17 14:46:51 PST 2008


Fine for me (I just didn't know we had this function available).

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.

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

Nicolas

> -----Original Message-----
> From: Matthew Fluet [mailto:fluet at tti-c.org]
> Sent: Monday, November 17, 2008 8:21 PM
> To: Nicolas Bertolotti
> Cc: mlton at mlton.org
> Subject: Re: [MLton] A few changes proposals for MLton
>
> On Thu, 13 Nov 2008, Nicolas Bertolotti wrote:
> > *   21-prevent-null-heap-size.patch
> >    *   This patch addresses the issue I submitted a few days ago
> >      (Segmentation fault on a 6 GB machine with ram-slop 0.85)
>
> --- mlton-r6698.patched/runtime/gc/heap.c       2008-11-03
> 23:45:47.000000000 +0100
> +++ mlton-r6698/runtime/gc/heap.c       2008-11-05 23:53:54.000000000
> +0100
> @@ -39,6 +39,7 @@
>   size_t sizeofHeapDesired (GC_state s, size_t liveSize, size_t
> currentSize) {
>     size_t liveWithMapsSize;
>     size_t res;
> +  size_t maxSize;
>     float withMapsRatio;
>
>     liveSize = align (liveSize, s->sysvals.pageSize);
> @@ -82,6 +83,9 @@
>       res = s->sysvals.ram;
>     } else { /* Required live ratio. */
>       res = liveSize * s->controls.ratios.markCompact;
> +    /* Avoid overflow */
> +    if (res < liveSize)
> +      res = SIZE_MAX;
>       /* If the current heap is bigger than res, then shrinking always
>        * sounds like a good idea.  However, depending on what pages the
>        * VM keeps around, growing could be very expensive, if it
> @@ -104,6 +108,16 @@
>         die ("Out of memory with max heap size %s.",
>              uintmaxToCommaString(s->controls.maxHeap));
>     }
> +
> +  /* Avoid overflow. */
> +  maxSize = align(SIZE_MAX - s->sysvals.pageSize, s->sysvals.pageSize);
> +  maxSize -= sizeofCardMapAndCrossMap(s, maxSize);
> +  if (res > maxSize)
> +    res = maxSize;
> +  if (res < liveSize)
> +    die ("Out of memory with system max heap size %s.",
> +        uintmaxToCommaString(res));
> +
>     if (DEBUG_RESIZING)
>       fprintf (stderr, "%s = sizeofHeapDesired (%s, %s)\n",
>                uintmaxToCommaString(res),
>
>
> Looks simple and effective.  Equivalent, but perhaps easier to understand
> would be to replace
>
> +  maxSize = align(SIZE_MAX - s->sysvals.pageSize, s->sysvals.pageSize);
>
> with
>
> +  maxSize = alignDown(SIZE_MAX, s->sysvals.pageSize);



More information about the MLton mailing list