[MLton-commit] r4569

Wesley Terpstra MLton@mlton.org
Tue, 23 May 2006 12:19:56 -0700


Implement the new GC_availRam as simply returning all userspace available memory.
I couldn't find a better match for this after about 2-3 hours of googling. :-(

Discovered 'vmmap' which provides a process memory map on osx.
This might also work for BSD in case it needs to be fixed there still.

Finally, grab the pagesize from sysconf for the other new GC method.


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

U   mlton/branches/on-20050822-x86_64-branch/runtime/platform/darwin.c

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

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/platform/darwin.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/platform/darwin.c	2006-05-23 03:17:29 UTC (rev 4568)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/platform/darwin.c	2006-05-23 19:19:54 UTC (rev 4569)
@@ -22,10 +22,9 @@
 }
 
 void GC_displayMem (void) {
-        /* FIXME: this won't actually work. */
         static char buffer[256];
 
-        sprintf (buffer, "/bin/cat /proc/%d/map\n", (int)getpid ());
+        sprintf (buffer, "/usr/bin/vmmap -w -interleaved %d\n", (int)getpid ());
         (void)system (buffer);
 }
 
@@ -40,6 +39,11 @@
         sa->sa_sigaction = (void (*)(int, siginfo_t*, void*))catcher;
 }
 
+size_t GC_pageSize (void) {
+        long int pageSize = sysconf(_SC_PAGESIZE);
+        return (size_t)pageSize;
+}
+
 size_t GC_totalRam (void) {
         int mem;
         size_t len;
@@ -49,3 +53,15 @@
                 diee ("sysctl failed");
         return mem;
 }
+
+// Not quite right... what does 'available' mean anyways?!
+// This returns the number of bytes available to userspace programs.
+size_t GC_availRam (void) {
+        int mem;
+        size_t len;
+
+        len = sizeof (int);
+        if (-1 == sysctlbyname ("hw.usermem", &mem, &len, NULL, 0))
+                diee ("sysctl failed");
+        return mem;
+}