Imported Upstream version 4.8.1
[platform/upstream/gcc48.git] / libgo / runtime / mem.c
index 9df4c87..e606bdd 100644 (file)
 #endif
 #endif
 
+#ifndef MAP_NORESERVE
+#define MAP_NORESERVE 0
+#endif
+
 #ifdef USE_DEV_ZERO
 static int dev_zero = -1;
 #endif
@@ -81,6 +85,10 @@ runtime_SysAlloc(uintptr n)
                        runtime_printf("if you're running SELinux, enable execmem for this process.\n");
                        exit(2);
                }
+               if(errno == EAGAIN) {
+                       runtime_printf("runtime: mmap: too much locked memory (check 'ulimit -l').\n");
+                       runtime_exit(2);
+               }
                return nil;
        }
        return p;
@@ -130,7 +138,11 @@ runtime_SysReserve(void *v, uintptr n)
                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;