Skip to content

Commit 5f08b44

Browse files
mknyszekgopherbot
authored andcommitted
runtime: call enableMetadataHugePages and its callees on the systemstack
These functions acquire the heap lock. If they're not called on the systemstack, a stack growth could cause a self-deadlock since stack growth may allocate memory from the page heap. This has been a problem for a while. If this is what's plaguing the ppc64 port right now, it's very surprising (and probably just coincidental) that it's showing up now. For #64050. For #64062. Fixes #64067. Change-Id: I2b95dc134d17be63b9fe8f7a3370fe5b5438682f Reviewed-on: https://go-review.googlesource.com/c/go/+/541635 LUCI-TryBot-Result: Go LUCI <[email protected]> Run-TryBot: Michael Knyszek <[email protected]> Auto-Submit: Michael Knyszek <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Michael Pratt <[email protected]> Reviewed-by: Paul Murphy <[email protected]>
1 parent 8da6405 commit 5f08b44

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

src/runtime/malloc.go

+4
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,10 @@ retry:
872872
//
873873
// The heap lock must not be held over this operation, since it will briefly acquire
874874
// the heap lock.
875+
//
876+
// Must be called on the system stack because it acquires the heap lock.
877+
//
878+
//go:systemstack
875879
func (h *mheap) enableMetadataHugePages() {
876880
// Enable huge pages for page structure.
877881
h.pages.enableChunkHugePages()

src/runtime/mgc.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -1190,7 +1190,9 @@ func gcMarkTermination() {
11901190

11911191
// Enable huge pages on some metadata if we cross a heap threshold.
11921192
if gcController.heapGoal() > minHeapForMetadataHugePages {
1193-
mheap_.enableMetadataHugePages()
1193+
systemstack(func() {
1194+
mheap_.enableMetadataHugePages()
1195+
})
11941196
}
11951197

11961198
semrelease(&worldsema)

src/runtime/mpagealloc.go

+4
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,10 @@ func (p *pageAlloc) grow(base, size uintptr) {
437437
//
438438
// The heap lock must not be held over this operation, since it will briefly acquire
439439
// the heap lock.
440+
//
441+
// Must be called on the system stack because it acquires the heap lock.
442+
//
443+
//go:systemstack
440444
func (p *pageAlloc) enableChunkHugePages() {
441445
// Grab the heap lock to turn on huge pages for new chunks and clone the current
442446
// heap address space ranges.

0 commit comments

Comments
 (0)