[MLton-commit] r7047

Matthew Fluet fluet at mlton.org
Wed Apr 8 05:31:11 PDT 2009


Avoid very large writes/reads.
----------------------------------------------------------------------

U   mlton/trunk/runtime/platform/diskBack.unix.c

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

Modified: mlton/trunk/runtime/platform/diskBack.unix.c
===================================================================
--- mlton/trunk/runtime/platform/diskBack.unix.c	2009-04-08 12:31:07 UTC (rev 7046)
+++ mlton/trunk/runtime/platform/diskBack.unix.c	2009-04-08 12:31:09 UTC (rev 7047)
@@ -34,9 +34,21 @@
 void GC_diskBack_read (void *data, pointer buf, size_t size) {
   FILE *f;
 
+  const size_t READ_CHUNK_SIZE = 0x2000000; /* 32M */
+
   f = ((WriteToDiskData)data)->f;
   fseek_safe (f, 0, SEEK_SET);
-  fread_safe (buf, 1, size, f);
+  /* fread (_, 1, size, _) succeeds
+   * with size >= 2^31
+   * for a 32-bit executable on 64-bit linux.
+   * Nonetheless, match GC_diskBack_write.
+   */
+  while (size > 0) {
+    size_t s = min (READ_CHUNK_SIZE, size);
+    fread_safe (buf, 1, s, f);
+    buf += s;
+    size -= s;
+  }
 }
 
 void GC_diskBack_close (void *data) {
@@ -51,8 +63,20 @@
   FILE *f;
   WriteToDiskData d;
 
+  const size_t WRITE_CHUNK_SIZE = 0x2000000; /* 32M */
+
   f = tempFileDes ();
-  fwrite_safe (buf, 1, size, f);
+  /* fwrite (_, 1, size, _) fails
+   * (with no helpful error conditions!)
+   * with size >= 2^31
+   * on x86-linux.
+   */
+  while (size > 0) {
+    size_t s = min (WRITE_CHUNK_SIZE, size);
+    fwrite_safe (buf, 1, s, f);
+    buf += s;
+    size -= s;
+  }
   d = (WriteToDiskData)(malloc_safe (sizeof(*d)));
   d->f = f;
   return d;




More information about the MLton-commit mailing list