diff options
author | Michael Anthony Knyszek <mknyszek@google.com> | 2020-05-12 16:08:50 +0000 |
---|---|---|
committer | Michael Knyszek <mknyszek@google.com> | 2020-05-14 16:20:19 +0000 |
commit | 796786cd0cc1ed71da65fe9f1760b390b189c5cd (patch) | |
tree | afc30d5e46518025a2596b2ac679b5bd24107c70 /src/runtime/mheap.go | |
parent | 364a05e2feab48611bb5e4f26f47a02b9b49a988 (diff) | |
download | go-796786cd0cc1ed71da65fe9f1760b390b189c5cd.tar.gz go-796786cd0cc1ed71da65fe9f1760b390b189c5cd.zip |
runtime: make maxOffAddr reflect the actual address space upper bound
Currently maxOffAddr is defined in terms of the whole 64-bit address
space, assuming that it's all supported, by using ^uintptr(0) as the
maximal address in the offset space. In reality, the maximal address in
the offset space is (1<<heapAddrBits)-1 because we don't have more than
that actually available to us on a given platform.
On most platforms this is fine, because arenaBaseOffset is just
connecting two segments of address space, but on AIX we use it as an
actual offset for the starting address of the available address space,
which is limited. This means using ^uintptr(0) as the maximal address in
the offset address space causes wrap-around, especially when we just
want to represent a range approximately like [addr, infinity), which
today we do by using maxOffAddr.
To fix this, we define maxOffAddr more appropriately, in terms of
(1<<heapAddrBits)-1.
This change also redefines arenaBaseOffset to not be the negation of the
virtual address corresponding to address zero in the virtual address
space, but instead directly as the virtual address corresponding to
zero. This matches the existing documentation more closely and makes the
logic around arenaBaseOffset decidedly simpler, especially when trying
to reason about its use on AIX.
Fixes #38966.
Change-Id: I1336e5036a39de846f64cc2d253e8536dee57611
Reviewed-on: https://go-review.googlesource.com/c/go/+/233497
Run-TryBot: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Austin Clements <austin@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Diffstat (limited to 'src/runtime/mheap.go')
-rw-r--r-- | src/runtime/mheap.go | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/runtime/mheap.go b/src/runtime/mheap.go index 3f57b0b6e9..6f7dc6eaa6 100644 --- a/src/runtime/mheap.go +++ b/src/runtime/mheap.go @@ -576,13 +576,13 @@ func (sc spanClass) noscan() bool { // //go:nosplit func arenaIndex(p uintptr) arenaIdx { - return arenaIdx((p + arenaBaseOffset) / heapArenaBytes) + return arenaIdx((p - arenaBaseOffset) / heapArenaBytes) } // arenaBase returns the low address of the region covered by heap // arena i. func arenaBase(i arenaIdx) uintptr { - return uintptr(i)*heapArenaBytes - arenaBaseOffset + return uintptr(i)*heapArenaBytes + arenaBaseOffset } type arenaIdx uint |