]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: initialize the memory limit in mallocinit
authorMichael Anthony Knyszek <mknyszek@google.com>
Fri, 11 Nov 2022 22:16:20 +0000 (22:16 +0000)
committerGopher Robot <gobot@golang.org>
Wed, 5 Apr 2023 21:45:22 +0000 (21:45 +0000)
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>
src/runtime/malloc.go

index 7ff2190876dd1bc803146e6280bb980dbc3434fa..bababe042e222bf575a30f511b346df509a4b968 100644 (file)
@@ -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