aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/malloc.go
diff options
context:
space:
mode:
authorCherry Mui <cherryyz@google.com>2024-10-21 17:45:01 -0400
committerCherry Mui <cherryyz@google.com>2024-10-25 17:13:47 +0000
commit22664f33b7389f1b3df409a831c83213cfbbe6d3 (patch)
tree2239ff9b337717499834139fd5abcf843074b364 /src/runtime/malloc.go
parent0addb2a4ea77b3e8b08a02966e381a812082f58b (diff)
downloadgo-22664f33b7389f1b3df409a831c83213cfbbe6d3.tar.xz
runtime: reserve fewer memory for aligned reservation on sbrk systems
Sometimes the runtime needs to reserve some memory with a large alignment, which the OS usually won't directly satisfy. So, it asks size+align bytes instead, and frees the unaligned portions. On sbrk systems, this doesn't work that well, as freeing the tail portion doesn't really free the memory to the OS. Instead, we could simply round the current break up, then reserve the given size, without wasting the tail portion. Also, don't create heap arena hints on sbrk systems. We can only grow the break sequentially, and reserving specific addresses would not succeed anyway. For #69018. Change-Id: Iadc2c54d62b00ad7befa5bbf71146523483a8c47 Reviewed-on: https://go-review.googlesource.com/c/go/+/621715 Reviewed-by: Michael Knyszek <mknyszek@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Pratt <mpratt@google.com>
Diffstat (limited to 'src/runtime/malloc.go')
-rw-r--r--src/runtime/malloc.go11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/runtime/malloc.go b/src/runtime/malloc.go
index 74decd54c4..0700d0d1cd 100644
--- a/src/runtime/malloc.go
+++ b/src/runtime/malloc.go
@@ -470,7 +470,10 @@ func mallocinit() {
lockInit(&globalAlloc.mutex, lockRankGlobalAlloc)
// Create initial arena growth hints.
- if goarch.PtrSize == 8 {
+ if isSbrkPlatform {
+ // Don't generate hints on sbrk platforms. We can
+ // only grow the break sequentially.
+ } else if goarch.PtrSize == 8 {
// On a 64-bit machine, we pick the following hints
// because:
//
@@ -828,6 +831,12 @@ mapped:
// aligned to align bytes. It may reserve either n or n+align bytes,
// so it returns the size that was reserved.
func sysReserveAligned(v unsafe.Pointer, size, align uintptr) (unsafe.Pointer, uintptr) {
+ if isSbrkPlatform {
+ if v != nil {
+ throw("unexpected heap arena hint on sbrk platform")
+ }
+ return sysReserveAlignedSbrk(size, align)
+ }
// Since the alignment is rather large in uses of this
// function, we're not likely to get it by chance, so we ask
// for a larger region and remove the parts we don't need.