aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/malloc.go
diff options
context:
space:
mode:
authorMichael Anthony Knyszek <mknyszek@google.com>2022-11-11 22:16:20 +0000
committerGopher Robot <gobot@golang.org>2023-04-05 21:45:22 +0000
commit96e8e62821ddb862e947fc9a1609e8e5b713cf14 (patch)
tree49719658a02d9243d938ff4b07a8599cab607a61 /src/runtime/malloc.go
parent84eaceaba706f55ed750149fcfbd6e59c78d60d8 (diff)
downloadgo-96e8e62821ddb862e947fc9a1609e8e5b713cf14.tar.xz
runtime: initialize the memory limit in mallocinit
Currently the memory limit is left uninitialized before gcinit, and allocations may happen. The result is that the span allocation path might try to scavenge memory unnecessarily. Prevent this by setting the memory limit up early to its default value. Change-Id: I886d9a8fa645861e4f88e0d54af793418426f520 Reviewed-on: https://go-review.googlesource.com/c/go/+/450736 Run-TryBot: Michael Knyszek <mknyszek@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Michael Knyszek <mknyszek@google.com> Reviewed-by: Michael Pratt <mpratt@google.com>
Diffstat (limited to 'src/runtime/malloc.go')
-rw-r--r--src/runtime/malloc.go3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/runtime/malloc.go b/src/runtime/malloc.go
index 7ff2190876..bababe042e 100644
--- a/src/runtime/malloc.go
+++ b/src/runtime/malloc.go
@@ -571,6 +571,9 @@ func mallocinit() {
userArenaHint.addr = p
userArenaHint.next, mheap_.userArena.arenaHints = mheap_.userArena.arenaHints, userArenaHint
}
+ // Initialize the memory limit here because the allocator is going to look at it
+ // but we haven't called gcinit yet and we're definitely going to allocate memory before then.
+ gcController.memoryLimit.Store(maxInt64)
}
// sysAlloc allocates heap arena space for at least n bytes. The