[MLton-devel] cvs commit: mremap

Stephen Weeks sweeks@users.sourceforge.net
Sun, 25 Aug 2002 02:58:07 -0700


sweeks      02/08/25 02:58:07

  Modified:    runtime  gc.c
  Log:
  Use mremap to grow the heap.

Revision  Changes    Path
1.83      +71 -21    mlton/runtime/gc.c

Index: gc.c
===================================================================
RCS file: /cvsroot/mlton/mlton/runtime/gc.c,v
retrieving revision 1.82
retrieving revision 1.83
diff -u -r1.82 -r1.83
--- gc.c	24 Aug 2002 22:24:07 -0000	1.82
+++ gc.c	25 Aug 2002 09:58:07 -0000	1.83
@@ -1261,8 +1261,7 @@
  * is unable.  If a reasonable size to space is already there, then heapCreate
  * leaves it.
  */
-static bool heapCreate (GC_state s, GC_heap h, 
-				W32 desiredSize, W32 minSize) {
+static bool heapCreate (GC_state s, GC_heap h, W32 desiredSize, W32 minSize) {
 	W32 backoff;
 
 	if (DEBUG)
@@ -1272,7 +1271,7 @@
 	assert (heapIsInit (h));
 	if (desiredSize < minSize)
 		desiredSize = minSize;
-	desiredSize = align (desiredSize, s->pageSize);
+ 	desiredSize = align (desiredSize, s->pageSize);
 	assert (0 == h->size and NULL == h->start);
 	backoff = (desiredSize - minSize) / 20;
 	if (0 == backoff)
@@ -2102,7 +2101,7 @@
 	}
 	assert (FALSE);
 done:
-	s->bytesLive = front - gap - s->heap.start;
+	s->oldGenSize = front - gap - s->heap.start;
 	if (DEBUG_MARK_COMPACT)
 		fprintf (stderr, "bytesLive = %u\n", s->bytesLive);
 	return;
@@ -2127,6 +2126,10 @@
 		fprintf (stderr, "Major mark-compact GC done.\n");
 }
 
+/* ---------------------------------------------------------------- */
+/*                          translateHeap                           */
+/* ---------------------------------------------------------------- */
+
 static void translatePointer (GC_state s, pointer *p) {
 	if (s->translateUp)
 		*p += s->translateDiff;
@@ -2160,6 +2163,40 @@
 }
 
 /* ---------------------------------------------------------------- */
+/*                            heapRemap                             */
+/* ---------------------------------------------------------------- */
+
+#include <linux/mman.h>
+static bool heapRemap (GC_state s, GC_heap h, W32 desired, W32 minSize) {
+	W32 backoff;
+	W32 size;
+
+	assert (desired >= h->size);
+	desired = align (desired, s->pageSize);
+	backoff = (desired - minSize) / 20;
+	if (0 == backoff)
+		backoff = 1; /* enough to terminate the loop below */
+	backoff = align (backoff, s->pageSize);
+	for (size = desired; size >= minSize; size -= backoff) {
+		pointer new;
+
+		new = mremap (h->start, h->size, size, MREMAP_MAYMOVE);
+		unless ((void*)-1 == new) {
+			if (DEBUG_RESIZING)
+				fprintf (stderr, "Remapping heap at 0x%08x of size %s to heap at 0x%08x of size %s.\n",
+					(uint)h->start,
+					uintToCommaString (h->size),
+					(uint)new,
+					uintToCommaString (size));
+			h->start = new;
+			h->size = size;
+			return TRUE;
+		}
+	}
+	return FALSE;
+}
+
+/* ---------------------------------------------------------------- */
 /*                             heapGrow                             */
 /* ---------------------------------------------------------------- */
 
@@ -2179,6 +2216,8 @@
 	old = s->heap.start;
 	size = s->oldGenSize;
 	assert (size <= h->size);
+	if (heapRemap (s, h, desired, minSize))
+		goto done;
 	heapShrink (s, h, size);
 	heapInit (&h2);
 	/* Allocate a space of the desired size. */
@@ -2227,8 +2266,33 @@
 				uintToCommaString (minSize));
 		}
 	}
-	translateHeap (s, old, s->heap.start, s->oldGenSize);
-	setCardMapForMutator (s);
+done:
+	unless (old == s->heap.start) {
+		translateHeap (s, old, s->heap.start, s->oldGenSize);
+		setCardMapForMutator (s);
+	}
+}
+
+
+/* ---------------------------------------------------------------- */
+/*                     resizeCardMapAndCrossMap                     */
+/* ---------------------------------------------------------------- */
+
+static void resizeCardMapAndCrossMap (GC_state s) {
+	if (s->mutatorMarksCards 
+		and s->cardMapSize != 
+			align (divCardSize (s, s->heap.size), s->pageSize)) {
+		pointer oldCrossMap;
+		uint oldCrossMapSize;
+
+		smunmap (s->cardMap, s->cardMapSize);
+		oldCrossMap = s->crossMap;
+		oldCrossMapSize = s->crossMapSize;
+		createCardMapAndCrossMap (s);
+		copy (oldCrossMap, s->crossMap,
+			min (s->crossMapSize, oldCrossMapSize));
+		smunmap (oldCrossMap, oldCrossMapSize);
+	}
 }
 
 /* ---------------------------------------------------------------- */
@@ -2252,21 +2316,7 @@
 		heapRelease (s, &s->heap2);
 		growHeap (s, desired, need);
 	}
-	/* Resize card map and cross map. */
-	if (s->mutatorMarksCards 
-		and s->cardMapSize != 
-			align (divCardSize (s, s->heap.size), s->pageSize)) {
-		pointer oldCrossMap;
-		uint oldCrossMapSize;
-
-		smunmap (s->cardMap, s->cardMapSize);
-		oldCrossMap = s->crossMap;
-		oldCrossMapSize = s->crossMapSize;
-		createCardMapAndCrossMap (s);
-		copy (oldCrossMap, s->crossMap,
-			min (s->crossMapSize, oldCrossMapSize));
-		smunmap (oldCrossMap, oldCrossMapSize);
-	}
+	resizeCardMapAndCrossMap (s);
 	assert (s->heap.size >= need);
 }
 





-------------------------------------------------------
This sf.net email is sponsored by: OSDN - Tired of that same old
cell phone?  Get a new here for FREE!
https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390
_______________________________________________
MLton-devel mailing list
MLton-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mlton-devel