Skip to content

Commit 3684d19

Browse files
mknyszekgopherbot
authored andcommitted
[release-branch.go1.21] 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. For #64067. Fixes #64073. 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]> (cherry picked from commit 5f08b44) Reviewed-on: https://go-review.googlesource.com/c/go/+/541955 Reviewed-by: Dmitri Shuralyov <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Auto-Submit: Dmitri Shuralyov <[email protected]>
1 parent 9e43850 commit 3684d19

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
@@ -853,6 +853,10 @@ retry:
853853
//
854854
// The heap lock must not be held over this operation, since it will briefly acquire
855855
// the heap lock.
856+
//
857+
// Must be called on the system stack because it acquires the heap lock.
858+
//
859+
//go:systemstack
856860
func (h *mheap) enableMetadataHugePages() {
857861
// Enable huge pages for page structure.
858862
h.pages.enableChunkHugePages()

src/runtime/mgc.go

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

11871187
// Enable huge pages on some metadata if we cross a heap threshold.
11881188
if gcController.heapGoal() > minHeapForMetadataHugePages {
1189-
mheap_.enableMetadataHugePages()
1189+
systemstack(func() {
1190+
mheap_.enableMetadataHugePages()
1191+
})
11901192
}
11911193

11921194
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)