aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/mem_plan9.go
diff options
context:
space:
mode:
authorRichard Miller <miller.research@gmail.com>2018-02-16 15:20:04 +0000
committerDavid du Colombier <0intro@gmail.com>2018-02-16 16:50:14 +0000
commitb1dbce31d7bbd7c3fdff1679d6f08c107d0be9a5 (patch)
tree7d8a0ea23ff806c60827764d48b0866b11e3e3c5 /src/runtime/mem_plan9.go
parent07f0f0956355266dafc36aadb66928e7450210ea (diff)
downloadgo-b1dbce31d7bbd7c3fdff1679d6f08c107d0be9a5.tar.gz
go-b1dbce31d7bbd7c3fdff1679d6f08c107d0be9a5.zip
runtime: don't ignore address hint for sysReserve in Plan 9
On Plan 9, sysReserve was ignoring the address hint and allocating memory wherever it is available. This causes the new TestArenaCollision test to fail on 32-bit Plan 9. We now use the address hint in the specific case where sysReserve is extending the process address space at its end, and similarly we contract the address space in the case where sysFree is releasing memory at the end. Fixes #23860 Change-Id: Ia5254779ba8f1698c999832720a88de400b5f91a Reviewed-on: https://go-review.googlesource.com/94776 Reviewed-by: Austin Clements <austin@google.com> Reviewed-by: David du Colombier <0intro@gmail.com>
Diffstat (limited to 'src/runtime/mem_plan9.go')
-rw-r--r--src/runtime/mem_plan9.go23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/runtime/mem_plan9.go b/src/runtime/mem_plan9.go
index ca8c437d1a..b80d030b24 100644
--- a/src/runtime/mem_plan9.go
+++ b/src/runtime/mem_plan9.go
@@ -149,8 +149,15 @@ func sysAlloc(n uintptr, sysStat *uint64) unsafe.Pointer {
func sysFree(v unsafe.Pointer, n uintptr, sysStat *uint64) {
mSysStatDec(sysStat, n)
lock(&memlock)
- memFree(v, n)
- memCheck()
+ if uintptr(v)+n == bloc {
+ // address range being freed is at the end of memory,
+ // so shrink the address space
+ bloc -= n
+ brk_(unsafe.Pointer(bloc))
+ } else {
+ memFree(v, n)
+ memCheck()
+ }
unlock(&memlock)
}
@@ -171,8 +178,16 @@ func sysFault(v unsafe.Pointer, n uintptr) {
func sysReserve(v unsafe.Pointer, n uintptr) unsafe.Pointer {
lock(&memlock)
- p := memAlloc(n)
- memCheck()
+ var p unsafe.Pointer
+ if uintptr(v) == bloc {
+ // address hint is the current end of memory,
+ // so try to extend the address space
+ p = sbrk(n)
+ }
+ if p == nil {
+ p = memAlloc(n)
+ memCheck()
+ }
unlock(&memlock)
return p
}