mirror of
https://github.com/golang/go
synced 2024-11-14 05:50:27 -07:00
runtime: recompute assistG before and after malloc
This change stops tracking assistG across malloc to reduce number of slots the compiler must keep track of in mallocgc, which adds to register pressure. It also makes the call to deductAssistCredit only happen if the GC is running. This is a microoptimization that on its own changes very little, but together with other optimizations and a breaking up of the various malloc paths will matter all together ("death by a thousand cuts"). Change-Id: I4cfac7f3e8e873ba66ff3b553072737a4707e2c2 Reviewed-on: https://go-review.googlesource.com/c/go/+/617876 Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Keith Randall <khr@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Michael Knyszek <mknyszek@google.com>
This commit is contained in:
parent
d8997c8c1f
commit
8df6413e11
@ -1042,9 +1042,10 @@ func mallocgc(size uintptr, typ *_type, needzero bool) unsafe.Pointer {
|
||||
}
|
||||
}
|
||||
|
||||
// assistG is the G to charge for this allocation, or nil if
|
||||
// GC is not currently active.
|
||||
assistG := deductAssistCredit(size)
|
||||
// Assist the GC if needed.
|
||||
if gcBlackenEnabled != 0 {
|
||||
deductAssistCredit(size)
|
||||
}
|
||||
|
||||
// Set mp.mallocing to keep from being preempted by GC.
|
||||
mp := acquirem()
|
||||
@ -1298,13 +1299,11 @@ func mallocgc(size uintptr, typ *_type, needzero bool) unsafe.Pointer {
|
||||
}
|
||||
}
|
||||
|
||||
if assistG != nil {
|
||||
// Account for internal fragmentation in the assist
|
||||
// debt now that we know it.
|
||||
//
|
||||
// N.B. Use the full size because that's how the rest
|
||||
// of the GC accounts for bytes marked.
|
||||
assistG.gcAssistBytes -= int64(fullSize - dataSize)
|
||||
// Adjust our GC assist debt to account for internal fragmentation.
|
||||
if gcBlackenEnabled != 0 {
|
||||
if assistG := getg().m.curg; assistG != nil {
|
||||
assistG.gcAssistBytes -= int64(fullSize - size)
|
||||
}
|
||||
}
|
||||
|
||||
if shouldhelpgc {
|
||||
@ -1338,11 +1337,9 @@ func mallocgc(size uintptr, typ *_type, needzero bool) unsafe.Pointer {
|
||||
// Caller must be preemptible.
|
||||
//
|
||||
// Returns the G for which the assist credit was accounted.
|
||||
func deductAssistCredit(size uintptr) *g {
|
||||
var assistG *g
|
||||
if gcBlackenEnabled != 0 {
|
||||
func deductAssistCredit(size uintptr) {
|
||||
// Charge the current user G for this allocation.
|
||||
assistG = getg()
|
||||
assistG := getg()
|
||||
if assistG.m.curg != nil {
|
||||
assistG = assistG.m.curg
|
||||
}
|
||||
@ -1356,8 +1353,6 @@ func deductAssistCredit(size uintptr) *g {
|
||||
// before disabling preemption.
|
||||
gcAssistAlloc(assistG)
|
||||
}
|
||||
}
|
||||
return assistG
|
||||
}
|
||||
|
||||
// memclrNoHeapPointersChunked repeatedly calls memclrNoHeapPointers
|
||||
|
Loading…
Reference in New Issue
Block a user