[MLton] callcc and space use

Vesa Karvonen vesa.a.j.k at gmail.com
Thu Feb 21 09:02:38 PST 2008


On Thu, Feb 21, 2008 at 12:40 PM, Matthew Fluet <fluet at tti-c.org> wrote:
> On Wed, 20 Feb 2008, Vesa Karvonen wrote:
>  > On Thu, Feb 14, 2008 at 5:09 PM, Matthew Fluet <fluet at tti-c.org> wrote:
[...]
>  > I think that just a hard limit of 4*used wouldn't be enough, because
>  > then long lived paused threads would never be minimized.
>
>  O.k.  But, that is a stronger property than simply ensuring that the
> reserved stack space is not more than a constant factor of the used
>  space.

Well, in some sense it is, although it doesn't change the asymptotic
upper bounds.  I was mainly thinking of applications that use lots and
lots of threads.  In such a case, it would be likely that most of the
threads would be paused most of the time.  So, reserving space for
them could waste a lot of memory.

>  I sketched out the following as a possible resizing policy, which gives
>  some more controls while trying to maintain the current behavior of
>  single-threaded programs:
[...]
>          reservedShrink =
>            (stackReserved <= reservedPermit)
>            ? stack->reserved
>            : (size_t)(s->controls.ratios.stackCurrentShrink * stack->used);

I guess the above should use stack->reserved rather than stack->used.
Otherwise this looks good to me.

Hmm... What about overflows when multiplying with ratios much greater
than 1.0?  It might make sense to do the computations in floating
point and only convert the final result to a size_t value.

>  with the following defaults:
>
>    s->controls.ratios.stackCurrentGrow = 2.0;
>    s->controls.ratios.stackCurrentMaxReserved = 32.0;
>    s->controls.ratios.stackCurrentPermitReserved = 4.0;
>    s->controls.ratios.stackCurrentShrink = 0.5;
>    s->controls.ratios.stackMaxReserved = 8.0;
>    s->controls.ratios.stackShrink = 0.5;
>
>  The difference from the current policy is that both the current and paused
>  stacks have a maximum reserved size that is a ratio of the used size.
>  The other difference is that a lot more ratios can be set by runtime
>  options.

So, if I understand the resizing policy sketch, you can turn off the
shrinking (beyond the stackMaxReserved limit) just by setting
stackShrink = 1.0.  Also, setting the MaxReserved ratios high, you can
get almost the old behavior (just shrinking gradually as if there was
no limit).

-Vesa Karvonen



More information about the MLton mailing list