Skip to content

Commit eb96f8a

Browse files
committed
runtime: scavenge on growth instead of inline with allocation
Inline scavenging causes significant performance regressions in tail latency for k8s and has relatively little benefit for RSS footprint. We disabled inline scavenging in Go 1.12.5 (CL 174102) as well, but we thought other changes in Go 1.13 had mitigated the issues with inline scavenging. Apparently we were wrong. This CL switches back to only doing foreground scavenging on heap growth, rather than doing it when allocation tries to allocate from scavenged space. Fixes #32828. Change-Id: I1f5df44046091f0b4f89fec73c2cde98bf9448cb Reviewed-on: https://go-review.googlesource.com/c/go/+/183857 Run-TryBot: Austin Clements <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Michael Knyszek <[email protected]>
1 parent f18109d commit eb96f8a

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

src/runtime/mheap.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,16 +1226,6 @@ HaveSpan:
12261226
// heap_released since we already did so earlier.
12271227
sysUsed(unsafe.Pointer(s.base()), s.npages<<_PageShift)
12281228
s.scavenged = false
1229-
1230-
// Since we allocated out of a scavenged span, we just
1231-
// grew the RSS. Mitigate this by scavenging enough free
1232-
// space to make up for it but only if we need to.
1233-
//
1234-
// scavengeLocked may cause coalescing, so prevent
1235-
// coalescing with s by temporarily changing its state.
1236-
s.state = mSpanManual
1237-
h.scavengeIfNeededLocked(s.npages * pageSize)
1238-
s.state = mSpanFree
12391229
}
12401230

12411231
h.setSpans(s.base(), npage, s)
@@ -1311,6 +1301,10 @@ func (h *mheap) grow(npage uintptr) bool {
13111301
//
13121302
// h must be locked.
13131303
func (h *mheap) growAddSpan(v unsafe.Pointer, size uintptr) {
1304+
// Scavenge some pages to make up for the virtual memory space
1305+
// we just allocated, but only if we need to.
1306+
h.scavengeIfNeededLocked(size)
1307+
13141308
s := (*mspan)(h.spanalloc.alloc())
13151309
s.init(uintptr(v), size/pageSize)
13161310
h.setSpans(s.base(), s.npages, s)

0 commit comments

Comments
 (0)