Skip to content

Commit 1a6d87d

Browse files
committed
[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>
1 parent 7320506 commit 1a6d87d

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/runtime/malloc.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,10 @@ func (h *mheap) sysAlloc(n uintptr) unsafe.Pointer {
416416
var reserved bool
417417
p := uintptr(sysReserve(unsafe.Pointer(h.arena_end), p_size, &reserved))
418418
if p == 0 {
419-
return nil
419+
// TODO: Try smaller reservation
420+
// growths in case we're in a crowded
421+
// 32-bit address space.
422+
goto reservationFailed
420423
}
421424
// p can be just about anywhere in the address
422425
// space, including before arena_end.
@@ -476,6 +479,7 @@ func (h *mheap) sysAlloc(n uintptr) unsafe.Pointer {
476479
return unsafe.Pointer(p)
477480
}
478481

482+
reservationFailed:
479483
// If using 64-bit, our reservation is all we have.
480484
if sys.PtrSize != 4 {
481485
return nil

0 commit comments

Comments
 (0)