aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/runtime
diff options
context:
space:
mode:
authorDmitriy Vyukov <dvyukov@google.com>2013-06-12 18:47:16 +0400
committerDmitriy Vyukov <dvyukov@google.com>2013-06-12 18:47:16 +0400
commita8ad859c30c8d4c30c38ac41d858c9030d025ddd (patch)
tree1f826dc7513960f88c0a28222e4a5e2c91de1823 /src/pkg/runtime
parentdbcfed93e75b91819bd01eb228996073b18c8196 (diff)
downloadgo-a8ad859c30c8d4c30c38ac41d858c9030d025ddd.tar.xz
runtime: more flexible heap memory mapping on 64-bits
Fixes #5641. R=golang-dev, dave, daniel.morsing, iant CC=golang-dev, kcc https://golang.org/cl/10126044
Diffstat (limited to 'src/pkg/runtime')
-rw-r--r--src/pkg/runtime/malloc.goc18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/pkg/runtime/malloc.goc b/src/pkg/runtime/malloc.goc
index a1db66e1ad..f85a582bb8 100644
--- a/src/pkg/runtime/malloc.goc
+++ b/src/pkg/runtime/malloc.goc
@@ -303,6 +303,7 @@ runtime·mallocinit(void)
extern byte end[];
byte *want;
uintptr limit;
+ uint64 i;
p = nil;
arena_size = 0;
@@ -330,15 +331,17 @@ runtime·mallocinit(void)
// 128 GB (MaxMem) should be big enough for now.
//
// The code will work with the reservation at any address, but ask
- // SysReserve to use 0x000000c000000000 if possible.
+ // SysReserve to use 0x0000XXc000000000 if possible (XX=00...7f).
// Allocating a 128 GB region takes away 37 bits, and the amd64
// doesn't let us choose the top 17 bits, so that leaves the 11 bits
// in the middle of 0x00c0 for us to choose. Choosing 0x00c0 means
- // that the valid memory addresses will begin 0x00c0, 0x00c1, ..., 0x0x00df.
+ // that the valid memory addresses will begin 0x00c0, 0x00c1, ..., 0x00df.
// In little-endian, that's c0 00, c1 00, ..., df 00. None of those are valid
// UTF-8 sequences, and they are otherwise as far away from
- // ff (likely a common byte) as possible. An earlier attempt to use 0x11f8
- // caused out of memory errors on OS X during thread allocations.
+ // ff (likely a common byte) as possible. If that fails, we try other 0xXXc0
+ // addresses. An earlier attempt to use 0x11f8 caused out of memory errors
+ // on OS X during thread allocations. 0x00c0 causes conflicts with
+ // AddressSanitizer which reserves all memory up to 0x0100.
// These choices are both for debuggability and to reduce the
// odds of the conservative garbage collector not collecting memory
// because some non-pointer block of memory had a bit pattern
@@ -353,7 +356,12 @@ runtime·mallocinit(void)
spans_size = arena_size / PageSize * sizeof(runtime·mheap.spans[0]);
// round spans_size to pages
spans_size = (spans_size + ((1<<PageShift) - 1)) & ~((1<<PageShift) - 1);
- p = runtime·SysReserve((void*)(0x00c0ULL<<32), bitmap_size + spans_size + arena_size);
+ for(i = 0; i <= 0x7f; i++) {
+ p = (void*)(i<<40 | 0x00c0ULL<<32);
+ p = runtime·SysReserve(p, bitmap_size + spans_size + arena_size);
+ if(p != nil)
+ break;
+ }
}
if (p == nil) {
// On a 32-bit machine, we can't typically get away