]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: new allocation strategy for amd64
authorRuss Cox <rsc@golang.org>
Wed, 9 Feb 2011 19:38:33 +0000 (14:38 -0500)
committerRuss Cox <rsc@golang.org>
Wed, 9 Feb 2011 19:38:33 +0000 (14:38 -0500)
Do not reserve virtual address space.
Instead, assume it will be there when we need it,
and crash loudly if that assumption is violated.
Reserving the address space gets charged to
ulimit -v, which exceeds commonly set limits.

http://groups.google.com/group/golang-dev/msg/7c477af5f5a8dd2c

R=r, niemeyer
CC=golang-dev
https://golang.org/cl/4148045

src/pkg/runtime/freebsd/mem.c
src/pkg/runtime/linux/mem.c
test/run

index cbae187180d2a4de9a2000d8abd5604cc55d8c7a..f5bbfa6fab875d0a181f389e84cc73b8ecc53893 100644 (file)
@@ -33,6 +33,12 @@ runtime·SysFree(void *v, uintptr n)
 void*
 runtime·SysReserve(void *v, uintptr n)
 {
+       // On 64-bit, people with ulimit -v set complain if we reserve too
+       // much address space.  Instead, assume that the reservation is okay
+       // and check the assumption in SysMap.
+       if(sizeof(void*) == 8)
+               return v;
+       
        return runtime·mmap(v, n, PROT_NONE, MAP_ANON|MAP_PRIVATE, -1, 0);
 }
 
@@ -42,6 +48,17 @@ runtime·SysMap(void *v, uintptr n)
        void *p;
        
        mstats.sys += n;
+
+       // On 64-bit, we don't actually have v reserved, so tread carefully.
+       if(sizeof(void*) == 8) {
+               p = runtime·mmap(v, n, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANON|MAP_PRIVATE, -1, 0);
+               if(p != v) {
+                       runtime·printf("runtime: address space conflict: map(%v) = %v\n", v, p);
+                       runtime·throw("runtime: address space conflict");
+               }
+               return;
+       }
+
        p = runtime·mmap(v, n, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANON|MAP_FIXED|MAP_PRIVATE, -1, 0);
        if(p != v)
                runtime·throw("runtime: cannot map pages in arena address space");
index 3a83e7394b00bcbfcfa2f8cfd3558a6db31b82dc..633ad0c62e5bb81d202be413a854417ffa17e898 100644 (file)
@@ -39,6 +39,12 @@ runtime·SysFree(void *v, uintptr n)
 void*
 runtime·SysReserve(void *v, uintptr n)
 {
+       // On 64-bit, people with ulimit -v set complain if we reserve too
+       // much address space.  Instead, assume that the reservation is okay
+       // and check the assumption in SysMap.
+       if(sizeof(void*) == 8)
+               return v;
+       
        return runtime·mmap(v, n, PROT_NONE, MAP_ANON|MAP_PRIVATE, -1, 0);
 }
 
@@ -48,6 +54,17 @@ runtime·SysMap(void *v, uintptr n)
        void *p;
        
        mstats.sys += n;
+
+       // On 64-bit, we don't actually have v reserved, so tread carefully.
+       if(sizeof(void*) == 8) {
+               p = runtime·mmap(v, n, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANON|MAP_PRIVATE, -1, 0);
+               if(p != v) {
+                       runtime·printf("runtime: address space conflict: map(%v) = %v\n", v, p);
+                       runtime·throw("runtime: address space conflict");
+               }
+               return;
+       }
+
        p = runtime·mmap(v, n, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANON|MAP_FIXED|MAP_PRIVATE, -1, 0);
        if(p != v)
                runtime·throw("runtime: cannot map pages in arena address space");
index ec01952535174e54527d6f4bf54696362093590f..28d0caa0f687a85b87b40f2a6fa1697727aa0e03 100755 (executable)
--- a/test/run
+++ b/test/run
@@ -42,9 +42,7 @@ TMP2FILE=/tmp/gotest2-$$-$USER
 
 # don't run the machine out of memory: limit individual processes to 4GB.
 # on thresher, 3GB suffices to run the tests; with 2GB, peano fails.
-# Linux charges reserved but not mapped addresses to ulimit -v
-# so we have to use ulimit -m.
-ulimit -m 4000000
+ulimit -v 4000000
 
 # no core files please
 ulimit -c 0