src/runtime/export_test.go | 14 +++++++++++++- src/runtime/malloc.go | 20 +++++++++++++------- src/runtime/mgcscavenge_test.go | 5 ++++- src/runtime/mpagealloc_32bit.go | 10 ++-------- src/runtime/mpagealloc_64bit.go | 6 ++---- src/runtime/mpagealloc_test.go | 9 +++++++-- src/runtime/mpagecache_test.go | 5 ++++- diff --git a/src/runtime/export_test.go b/src/runtime/export_test.go index c8d01fbb1574de6b78faff16ed63b8d8c7362d52..b49bc50f97d594fde94121c027ea5afa38c79f3a 100644 --- a/src/runtime/export_test.go +++ b/src/runtime/export_test.go @@ -1066,7 +1066,19 @@ // between the two. // // This should not be higher than 0x100*pallocChunkBytes to support // mips and mipsle, which only have 31-bit address spaces. -var BaseChunkIdx = ChunkIdx(chunkIndex(((0xc000*pageAlloc64Bit + 0x100*pageAlloc32Bit) * pallocChunkBytes) + arenaBaseOffset*sys.GoosAix)) +var BaseChunkIdx = func() ChunkIdx { + var prefix uintptr + if pageAlloc64Bit != 0 { + prefix = 0xc000 + } else { + prefix = 0x100 + } + baseAddr := prefix * pallocChunkBytes + if sys.GoosAix != 0 { + baseAddr += arenaBaseOffset + } + return ChunkIdx(chunkIndex(baseAddr)) +}() // PageBase returns an address given a chunk index and a page index // relative to that chunk. diff --git a/src/runtime/malloc.go b/src/runtime/malloc.go index cc22b0f276597e94b5e6138a4fcddb8d5e20bb5b..0341bf2c1c81e622345f18cfcb6b7c0c49f7fa70 100644 --- a/src/runtime/malloc.go +++ b/src/runtime/malloc.go @@ -199,15 +199,21 @@ // mips32 only has access to the low 2GB of virtual memory, so // we further limit it to 31 bits. // // On ios/arm64, although 64-bit pointers are presumably - // available, pointers are truncated to 33 bits. Furthermore, - // only the top 4 GiB of the address space are actually available - // to the application, but we allow the whole 33 bits anyway for - // simplicity. - // TODO(mknyszek): Consider limiting it to 32 bits and using - // arenaBaseOffset to offset into the top 4 GiB. + // available, pointers are truncated to 33 bits in iOS <14. + // Furthermore, only the top 4 GiB of the address space are + // actually available to the application. In iOS >=14, more + // of the address space is available, and the OS can now + // provide addresses outside of those 33 bits. Pick 40 bits + // as a reasonable balance between address space usage by the + // page allocator, and flexibility for what mmap'd regions + // we'll accept for the heap. We can't just move to the full + // 48 bits because this uses too much address space for older + // iOS versions. + // TODO(mknyszek): Once iOS <14 is deprecated, promote ios/arm64 + // to a 48-bit address space like every other arm64 platform. // // WebAssembly currently has a limit of 4GB linear memory. - heapAddrBits = (_64bit*(1-sys.GoarchWasm)*(1-sys.GoosIos*sys.GoarchArm64))*48 + (1-_64bit+sys.GoarchWasm)*(32-(sys.GoarchMips+sys.GoarchMipsle)) + 33*sys.GoosIos*sys.GoarchArm64 + heapAddrBits = (_64bit*(1-sys.GoarchWasm)*(1-sys.GoosIos*sys.GoarchArm64))*48 + (1-_64bit+sys.GoarchWasm)*(32-(sys.GoarchMips+sys.GoarchMipsle)) + 40*sys.GoosIos*sys.GoarchArm64 // maxAlloc is the maximum size of an allocation. On 64-bit, // it's theoretically possible to allocate 1<