Skip to content

Commit f10d99f

Browse files
committed
runtime: flush assist credit on goroutine exit
Currently dead goroutines retain their assist credit. This credit can be used if the goroutine gets recycled, but in general this can make assist pacing over-aggressive by hiding an amount of credit proportional to the number of exited (and not reused) goroutines. Fix this "hidden credit" by flushing assist credit to the global credit pool when a goroutine exits. Updates #14812. Change-Id: I65f7f75907ab6395c04aacea2c97aea963b60344 Reviewed-on: https://go-review.googlesource.com/24703 Run-TryBot: Austin Clements <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Rick Hudson <[email protected]>
1 parent 86cd9c1 commit f10d99f

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/runtime/proc.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2671,6 +2671,15 @@ func goexit0(gp *g) {
26712671
gp.labels = nil
26722672
gp.timer = nil
26732673

2674+
if gcBlackenEnabled != 0 && gp.gcAssistBytes > 0 {
2675+
// Flush assist credit to the global pool. This gives
2676+
// better information to pacing if the application is
2677+
// rapidly creating an exiting goroutines.
2678+
scanCredit := int64(gcController.assistWorkPerByte * float64(gp.gcAssistBytes))
2679+
atomic.Xaddint64(&gcController.bgScanCredit, scanCredit)
2680+
gp.gcAssistBytes = 0
2681+
}
2682+
26742683
// Note that gp's stack scan is now "valid" because it has no
26752684
// stack.
26762685
gp.gcscanvalid = true

0 commit comments

Comments
 (0)