Revision: 29b742a2ed37
Branch: default
Author: Janne Snabb <
sn...@epipe.com>
Date: Fri Feb 15 10:54:51 2013
Log: runtime: Do not reserve huge amount of swap on 32 bit
architectures.
The mmap() call which reserves the arena should have MAP_NORESERVE
flag as in typical cases this memory will never be (fully) needed.
This matters in environments which do not do Linux style memory
overcommit, such as OpenIndiana/OpenSolaris/Solaris.
The MAP_NORESERVE flag does not exist on all operating systems
(for example FreeBSD). Therefore we define it to zero value in
case it does not exist.
Fixes issue 21.
R=golang-dev,
minux.ma, iant, dave
CC=gofrontend-dev, golang-dev
https://codereview.appspot.com/7310094
Committer: Ian Lance Taylor <
ia...@golang.org>
http://code.google.com/p/gofrontend/source/detail?r=29b742a2ed37
Modified:
/libgo/runtime/mem.c
=======================================
--- /libgo/runtime/mem.c Tue Jan 29 10:59:14 2013
+++ /libgo/runtime/mem.c Fri Feb 15 10:54:51 2013
@@ -18,6 +18,10 @@
#endif
#endif
+#ifndef MAP_NORESERVE
+#define MAP_NORESERVE 0
+#endif
+
#ifdef USE_DEV_ZERO
static int dev_zero = -1;
#endif
@@ -134,7 +138,11 @@
return v;
}
- p = runtime_mmap(v, n, PROT_NONE, MAP_ANON|MAP_PRIVATE, fd, 0);
+ // Use the MAP_NORESERVE mmap() flag here because typically most of
+ // this reservation will never be used. It does not make sense
+ // reserve a huge amount of unneeded swap space. This is important on
+ // systems which do not overcommit memory by default.
+ p = runtime_mmap(v, n, PROT_NONE, MAP_ANON|MAP_PRIVATE|MAP_NORESERVE, fd,
0);
if(p == MAP_FAILED)
return nil;
return p;