[MLton-commit] r6553

Matthew Fluet fluet at mlton.org
Mon Apr 7 11:55:18 PDT 2008


Add thread-max-reserved-ratio runtime option.

----------------------------------------------------------------------

U   mlton/trunk/runtime/gc/controls.h
U   mlton/trunk/runtime/gc/forward.c
U   mlton/trunk/runtime/gc/garbage-collection.c
U   mlton/trunk/runtime/gc/init.c

----------------------------------------------------------------------

Modified: mlton/trunk/runtime/gc/controls.h
===================================================================
--- mlton/trunk/runtime/gc/controls.h	2008-04-07 18:55:14 UTC (rev 6552)
+++ mlton/trunk/runtime/gc/controls.h	2008-04-07 18:55:17 UTC (rev 6553)
@@ -32,6 +32,7 @@
   float nursery; 
   float ramSlop;
   float threadGrow;
+  float threadMaxReserved;
   float threadShrink;
 };
 

Modified: mlton/trunk/runtime/gc/forward.c
===================================================================
--- mlton/trunk/runtime/gc/forward.c	2008-04-07 18:55:14 UTC (rev 6552)
+++ mlton/trunk/runtime/gc/forward.c	2008-04-07 18:55:17 UTC (rev 6553)
@@ -89,13 +89,24 @@
         }
       } else {
         /* Shrink heap stacks. */
-        stack->reserved =
+        size_t reservedMax =
+          (size_t)(s->controls.ratios.threadMaxReserved * s->used);
+        size_t reservedShrink =
+          (size_t)(s->controls.ratios.threadShrink * s->reserved);
+        size_t reservedMin=
+          (getStackCurrentObjptr(s) == op)
+          ? sizeofStackMinimumReserved (s, stack)
+          : s->used;
+        size_t reservedNew =
           alignStackReserved
-          (s, max((size_t)(s->controls.ratios.threadShrink * stack->reserved),
-                  stack->used));
-        if (DEBUG_STACKS)
-          fprintf (stderr, "Shrinking stack to size %s.\n",
-                   uintmaxToCommaString(stack->reserved));
+          (s, max(min(reservedMax,reservedShrink),reservedMin));
+        assert (reservedNew <= s->reserved);
+        if (reservedNew < stack->reserved) {
+          stack->reserved = reservedNew;
+          if (DEBUG_STACKS)
+            fprintf (stderr, "Shrinking stack to size %s.\n",
+                     uintmaxToCommaString(stack->reserved));
+        }
       }
       objectBytes = sizeof (struct GC_stack) + stack->used;
       skip = stack->reserved - stack->used;

Modified: mlton/trunk/runtime/gc/garbage-collection.c
===================================================================
--- mlton/trunk/runtime/gc/garbage-collection.c	2008-04-07 18:55:14 UTC (rev 6552)
+++ mlton/trunk/runtime/gc/garbage-collection.c	2008-04-07 18:55:17 UTC (rev 6553)
@@ -55,7 +55,7 @@
   if (DEBUG_STACKS or s->controls.messages)
     fprintf (stderr, 
              "[GC: Growing stack to size %s bytes.]\n",
-             uintmaxToCommaString(sizeofStackWithHeaderAligned (s, size)));
+             uintmaxToCommaString(alignStackReserved (s, size)));
   assert (hasHeapBytesFree (s, sizeofStackWithHeaderAligned (s, size), 0));
   stack = newStack (s, size, TRUE);
   copyStack (s, getStackCurrent(s), stack);

Modified: mlton/trunk/runtime/gc/init.c
===================================================================
--- mlton/trunk/runtime/gc/init.c	2008-04-07 18:55:14 UTC (rev 6552)
+++ mlton/trunk/runtime/gc/init.c	2008-04-07 18:55:17 UTC (rev 6553)
@@ -198,6 +198,13 @@
           s->controls.ratios.threadGrow = stringToFloat (argv[i++]);
           unless (1.0 < s->controls.ratios.threadGrow)
             die ("@MLton thread-grow-ratio argument must greater than 1.0.");
+        } else if (0 == strcmp (arg, "thread-max-reserved-ratio")) {
+          i++;
+          if (i == argc)
+            die ("@MLton thread-max-reserved-ratio missing argument.");
+          s->controls.ratios.threadMaxReserved = stringToFloat (argv[i++]);
+          unless (1.0 < s->controls.ratios.threadGrow)
+            die ("@MLton thread-max-reserved-ratio argument must greater than 1.0.");
         } else if (0 == strcmp (arg, "thread-shrink-ratio")) {
           i++;
           if (i == argc)
@@ -253,6 +260,7 @@
   s->controls.ratios.nursery = 10.0;
   s->controls.ratios.ramSlop = 0.5;
   s->controls.ratios.threadGrow = 2.0;
+  s->controls.ratios.maxReserved = 4.0;
   s->controls.ratios.threadShrink = 0.5;
   s->controls.summary = FALSE;
   s->cumulativeStatistics.bytesAllocated = 0;




More information about the MLton-commit mailing list