rts: Set default maximum stack size to 80% of physical memory
authorBen Gamari <bgamari.foss@gmail.com>
Fri, 13 Sep 2013 03:20:06 +0000 (23:20 -0400)
committerAustin Seipp <austin@well-typed.com>
Fri, 25 Oct 2013 14:14:29 +0000 (09:14 -0500)
rts/RtsFlags.c

index bf924c2..12bb44c 100644 (file)
@@ -13,6 +13,7 @@
 #include "RtsUtils.h"
 #include "Profiling.h"
 #include "RtsFlags.h"
+#include "sm/OSMem.h"
 
 #ifdef HAVE_CTYPE_H
 #include <ctype.h>
@@ -93,10 +94,15 @@ static void errorRtsOptsDisabled(HsBool is_hs_main, const char *s);
 
 void initRtsFlagsDefaults(void)
 {
+    StgWord64 maxStkSize = 8 * getPhysicalMemorySize() / 10;
+    // if getPhysicalMemorySize fails just move along with an 8MB limit
+    if (maxStkSize == 0)
+        maxStkSize = (8 * 1024 * 1024) / sizeof(W_);
+
     RtsFlags.GcFlags.statsFile         = NULL;
     RtsFlags.GcFlags.giveStats         = NO_GC_STATS;
 
-    RtsFlags.GcFlags.maxStkSize                = (8 * 1024 * 1024) / sizeof(W_);
+    RtsFlags.GcFlags.maxStkSize                = maxStkSize;
     RtsFlags.GcFlags.initialStkSize    = 1024 / sizeof(W_);
     RtsFlags.GcFlags.stkChunkSize       = (32 * 1024) / sizeof(W_);
     RtsFlags.GcFlags.stkChunkBufferSize = (1 * 1024) / sizeof(W_);