aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAustin Clements <austin@google.com>2017-07-28 18:06:03 -0400
committerAustin Clements <austin@google.com>2017-07-31 17:45:59 +0000
commit1a6d87d4bfefe315b2112c5342913801ecd22b34 (patch)
tree231429336aea7b40c74df2a6ed5badbfa105607d
parent7320506bc58d3a55eff2c67b2ec65cfa94f7b0a7 (diff)
downloadgo-1a6d87d4bfefe315b2112c5342913801ecd22b34.tar.gz
go-1a6d87d4bfefe315b2112c5342913801ecd22b34.zip
[release-branch.go1.9] runtime: fall back to small mmaps if we fail to grow reservation
Right now, if it's possible to grow the arena reservation but mheap.sysAlloc fails to get 256MB more of memory, it simply fails. However, on 32-bit we have a fallback path that uses much smaller mmaps that could take in this situation, but fail to. This commit fixes mheap.sysAlloc to use a common failure path in case it can't grow the reservation. On 32-bit, this path includes the fallback. Ideally, mheap.sysAlloc would attempt smaller reservation growths first, but taking the fallback path is a simple change for Go 1.9. Updates #21044 (fixes one of two issues). Cherry-pick of CL 51713. Updates #21234. Change-Id: I1e0035ffba986c3551479d5742809e43da5e7c73 Reviewed-on: https://go-review.googlesource.com/52190 Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
-rw-r--r--src/runtime/malloc.go6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/runtime/malloc.go b/src/runtime/malloc.go
index 8850659748..0ebd2c0ab2 100644
--- a/src/runtime/malloc.go
+++ b/src/runtime/malloc.go
@@ -416,7 +416,10 @@ func (h *mheap) sysAlloc(n uintptr) unsafe.Pointer {
var reserved bool
p := uintptr(sysReserve(unsafe.Pointer(h.arena_end), p_size, &reserved))
if p == 0 {
- return nil
+ // TODO: Try smaller reservation
+ // growths in case we're in a crowded
+ // 32-bit address space.
+ goto reservationFailed
}
// p can be just about anywhere in the address
// space, including before arena_end.
@@ -476,6 +479,7 @@ func (h *mheap) sysAlloc(n uintptr) unsafe.Pointer {
return unsafe.Pointer(p)
}
+reservationFailed:
// If using 64-bit, our reservation is all we have.
if sys.PtrSize != 4 {
return nil