Skip to content

Commit 96e8e62

Browse files
mknyszekgopherbot
authored andcommitted
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 <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Auto-Submit: Michael Knyszek <[email protected]> Reviewed-by: Michael Pratt <[email protected]>
1 parent 84eacea commit 96e8e62

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/runtime/malloc.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,9 @@ func mallocinit() {
571571
userArenaHint.addr = p
572572
userArenaHint.next, mheap_.userArena.arenaHints = mheap_.userArena.arenaHints, userArenaHint
573573
}
574+
// Initialize the memory limit here because the allocator is going to look at it
575+
// but we haven't called gcinit yet and we're definitely going to allocate memory before then.
576+
gcController.memoryLimit.Store(maxInt64)
574577
}
575578

576579
// sysAlloc allocates heap arena space for at least n bytes. The

0 commit comments

Comments
 (0)