From: Michael Anthony Knyszek Date: Fri, 11 Nov 2022 22:16:20 +0000 (+0000) Subject: runtime: initialize the memory limit in mallocinit X-Git-Tag: go1.21rc1~1024 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=96e8e62821ddb862e947fc9a1609e8e5b713cf14;p=gostls13.git 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 TryBot-Result: Gopher Robot Auto-Submit: Michael Knyszek Reviewed-by: Michael Pratt --- 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