From 9e4c9d0a4cd95d10dfded5458694ecbe1125dc97 Mon Sep 17 00:00:00 2001
From: Raymond Toy <toy.raymond@gmail.com>
Date: Sun, 28 Feb 2016 21:12:18 -0800
Subject: [PATCH] Reduce maximum heap size for Linux.

According to the message from Chisheng Huang on cmucl-help,
2016-02-27, 32-bit Ubuntu 11.10 (in VirtualBox) cannot use the full
heap space.  There's something already allocated at address 0xb7b82000,
so limit the max heap to address 0xb7b80000, for a total of 1530 MB
instead of 1632 MB.

(It would be nice to be able to detect this somehow.)
---
 src/lisp/x86-validate-linux.h | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/lisp/x86-validate-linux.h b/src/lisp/x86-validate-linux.h
index 4a0e46cb3..032d7aab1 100644
--- a/src/lisp/x86-validate-linux.h
+++ b/src/lisp/x86-validate-linux.h
@@ -22,12 +22,21 @@
  *	0x38000000->0x40000000  128M Control stack growing down.
  *	0x40000000->0x48000000  128M Reserved for shared libraries.
  *      0x58000000->0x58100000   16M Foreign Linkage Table
- *	0x58100000->0xBE000000 1631M Dynamic Space.
- *      0xBFFF0000->0xC0000000       Unknown Linux mapping
+ *	0x58100000->0xB7B00000 1530M Dynamic Space.
+ *      0xB7B82000->0xC0000000       Unknown Linux mapping, including stack
  *
+ *     
  *      (Note: 0x58000000 allows us to run on a Linux system on an AMD
  *      x86-64.  Hence we have a gap of unused memory starting at
  *      0x48000000.)
+ *
+ * It appears as if the actual upper limit depends on the particular
+ * Linux distribution.  Ubuntu 11.10 (32-bit) appears to have
+ * something mapped at 0xb78b2000, so we can't allocate the dynamic
+ * space past that.  That results in a max heap size of 1530 MB.
+ * However, Fedora 22 ther appears to be nothing mapped there.  In
+ * fact it appears to be free all the way to 0xf7c1b000.  That would
+ * allow a heap of size 2555 MB.
  */
 
 #define READ_ONLY_SPACE_START   (SpaceStart_TargetReadOnly)
@@ -48,7 +57,7 @@
 #define DYNAMIC_0_SPACE_START	(SpaceStart_TargetDynamic)
 
 #ifdef GENCGC
-#define DYNAMIC_SPACE_SIZE	(0x66000000)	/* 1.632GB */
+#define DYNAMIC_SPACE_SIZE	(0x5FA00000)	/* 1.530GB */
 #else
 #define DYNAMIC_SPACE_SIZE	(0x04000000)	/* 64MB */
 #endif
-- 
GitLab