[MLton-commit] r5816

Matthew Fluet fluet at mlton.org
Thu Aug 2 19:39:09 PDT 2007


Compute physical memory at uintmax_t (appropriate for 32-bit systems
with >4GB physical memory).  Apply ram-slop to entire physical memory
(i.e., possibly >4GB on 32-bit systems), but cap RAM used by MLton by
SIZE_MAX (i.e., by virtual address space).


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

U   mlton/trunk/runtime/gc/init.c
U   mlton/trunk/runtime/gc/sysvals.h
U   mlton/trunk/runtime/platform/sysconf.c
U   mlton/trunk/runtime/platform/sysctl.c
U   mlton/trunk/runtime/platform.h

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

Modified: mlton/trunk/runtime/gc/init.c
===================================================================
--- mlton/trunk/runtime/gc/init.c	2007-08-02 22:09:29 UTC (rev 5815)
+++ mlton/trunk/runtime/gc/init.c	2007-08-03 02:39:08 UTC (rev 5816)
@@ -283,8 +283,8 @@
   sigemptyset (&s->signalsInfo.signalsHandled);
   sigemptyset (&s->signalsInfo.signalsPending);
   s->startTime = getCurrentTime ();
-  s->sysvals.totalRam = GC_totalRam ();
   s->sysvals.pageSize = GC_pageSize ();
+  s->sysvals.physMem = GC_physMem ();
   s->weaks = NULL;
   s->saveWorldStatus = true;
 
@@ -304,13 +304,16 @@
    * we are using mark-compact by comparing heap size to ram size.  If
    * we didn't round, the size might be slightly off.
    */
-  s->sysvals.ram = align ((size_t)(s->controls.ratios.ramSlop * s->sysvals.totalRam), 
-                          s->sysvals.pageSize);
+  uintmax_t ram;
+  ram = alignMax ((uintmax_t)(s->controls.ratios.ramSlop * s->sysvals.physMem), 
+                  (uintmax_t)(s->sysvals.pageSize));
+  ram = min (ram, (uintmax_t)SIZE_MAX);
+  s->sysvals.ram = (size_t)ram;
   if (DEBUG or DEBUG_RESIZING or s->controls.messages)
     fprintf (stderr, "[GC: Found %s bytes of RAM; using %s bytes (%.1f%% of RAM).]\n",
-             uintmaxToCommaString(s->sysvals.totalRam),
+             uintmaxToCommaString(s->sysvals.physMem),
              uintmaxToCommaString(s->sysvals.ram),
-             100.0 * s->controls.ratios.ramSlop);
+             100.0 * ((double)ram / (double)(s->sysvals.physMem)));
   if (DEBUG_SOURCES or DEBUG_PROFILE) {
     uint32_t i;
     for (i = 0; i < s->sourceMaps.frameSourcesLength; i++) {

Modified: mlton/trunk/runtime/gc/sysvals.h
===================================================================
--- mlton/trunk/runtime/gc/sysvals.h	2007-08-02 22:09:29 UTC (rev 5815)
+++ mlton/trunk/runtime/gc/sysvals.h	2007-08-03 02:39:08 UTC (rev 5816)
@@ -10,8 +10,8 @@
 
 struct GC_sysvals {
   size_t ram;
-  size_t totalRam;
   size_t pageSize;
+  uintmax_t physMem;
 };
 
 #endif /* (defined (MLTON_GC_INTERNAL_TYPES)) */

Modified: mlton/trunk/runtime/platform/sysconf.c
===================================================================
--- mlton/trunk/runtime/platform/sysconf.c	2007-08-02 22:09:29 UTC (rev 5815)
+++ mlton/trunk/runtime/platform/sysconf.c	2007-08-03 02:39:08 UTC (rev 5816)
@@ -5,17 +5,12 @@
   return (size_t)pageSize;
 }
 
-size_t GC_totalRam (void) {
+uintmax_t GC_physMem (void) {
   size_t pageSize = GC_pageSize ();
   long int physPages;
-  uintmax_t totalRam;
+  uintmax_t physMem;
 
   physPages = sysconf (_SC_PHYS_PAGES);
-  totalRam = (uintmax_t)pageSize * (uintmax_t)physPages;
-  if (sizeof(size_t) >= sizeof(uintmax_t)) {
-    return (uintmax_t)totalRam;
-  } else {
-    totalRam = min(totalRam, (uintmax_t)SIZE_MAX);
-    return (size_t)totalRam;
-  }
+  physMem = (uintmax_t)pageSize * (uintmax_t)physPages;
+  return physMem;
 }

Modified: mlton/trunk/runtime/platform/sysctl.c
===================================================================
--- mlton/trunk/runtime/platform/sysctl.c	2007-08-02 22:09:29 UTC (rev 5815)
+++ mlton/trunk/runtime/platform/sysctl.c	2007-08-03 02:39:08 UTC (rev 5816)
@@ -11,32 +11,17 @@
     unsigned long long int pageSize;
     if (-1 == sysctl (mib, 2, &pageSize, &len, NULL, 0))
       diee ("sysctl failed");
-    if (sizeof(size_t) >= sizeof(unsigned long long int)) {
-      return (size_t)pageSize;
-    } else {
-      pageSize = min(pageSize, (unsigned long long int)SIZE_MAX);
-      return (size_t)pageSize;
-    }
+    return (size_t)pageSize;
   } else if (len == sizeof(unsigned long int)) {
     unsigned long int pageSize;
     if (-1 == sysctl (mib, 2, &pageSize, &len, NULL, 0))
       diee ("sysctl failed");
-    if (sizeof(size_t) >= sizeof(unsigned long int)) {
-      return (size_t)pageSize;
-    } else {
-      pageSize = min(pageSize, (unsigned long int)SIZE_MAX);
-      return (size_t)pageSize;
-    }
+    return (size_t)pageSize;
   } else if (len == sizeof(unsigned int)) {
     unsigned int pageSize;
     if (-1 == sysctl (mib, 2, &pageSize, &len, NULL, 0))
       diee ("sysctl failed");
-    if (sizeof(size_t) >= sizeof(unsigned int)) {
-      return (size_t)pageSize;
-    } else {
-      pageSize = min(pageSize, (unsigned int)SIZE_MAX);
-      return (size_t)pageSize;
-    }
+    return (size_t)pageSize;
   } else {
     die ("GC_pageSize");
   }
@@ -63,32 +48,17 @@
     unsigned long long int physMem;
     if (-1 == sysctl (mib, 2, &physMem, &len, NULL, 0))
       diee ("sysctl failed");
-    if (sizeof(size_t) >= sizeof(unsigned long long int)) {
-      return (size_t)physMem;
-    } else {
-      physMem = min(physMem, (unsigned long long int)SIZE_MAX);
-      return (size_t)physMem;
-    }
+    return (uintmax_t)physMem;
   } else if (len == sizeof(unsigned long int)) {
     unsigned long int physMem;
     if (-1 == sysctl (mib, 2, &physMem, &len, NULL, 0))
       diee ("sysctl failed");
-    if (sizeof(size_t) >= sizeof(unsigned long int)) {
-      return (size_t)physMem;
-    } else {
-      physMem = min(physMem, (unsigned long int)SIZE_MAX);
-      return (size_t)physMem;
-    }
+    return (uintmax_t)physMem;
   } else if (len == sizeof(unsigned int)) {
     unsigned int physMem;
     if (-1 == sysctl (mib, 2, &physMem, &len, NULL, 0))
       diee ("sysctl failed");
-    if (sizeof(size_t) >= sizeof(unsigned int)) {
-      return (size_t)physMem;
-    } else {
-      physMem = min(physMem, (unsigned int)SIZE_MAX);
-      return (size_t)physMem;
-    }
+    return (uintmax_t)physMem;
   } else {
     die ("GC_totalRam");
   }

Modified: mlton/trunk/runtime/platform.h
===================================================================
--- mlton/trunk/runtime/platform.h	2007-08-02 22:09:29 UTC (rev 5815)
+++ mlton/trunk/runtime/platform.h	2007-08-03 02:39:08 UTC (rev 5816)
@@ -159,7 +159,7 @@
 void GC_decommit (void *base, size_t length);
 
 size_t GC_pageSize (void);
-size_t GC_totalRam (void);
+uintmax_t GC_physMem (void);
 
 void GC_setCygwinUseMmap (bool b);
 




More information about the MLton-commit mailing list