diff options
author | Rhys Hiltner <rhys@justin.tv> | 2016-07-22 16:36:30 -0700 |
---|---|---|
committer | Austin Clements <austin@google.com> | 2016-07-27 18:56:04 +0000 |
commit | ccca9c9cc0fa5b6ea6e5c8276a96eee8c27ebd87 (patch) | |
tree | 7f514680dbb9570442db678df2c7b1663f7f43d2 | |
parent | c80e0d374ba3caf8ee32c6fe4a5474fa33928086 (diff) | |
download | go-ccca9c9cc0fa5b6ea6e5c8276a96eee8c27ebd87.tar.gz go-ccca9c9cc0fa5b6ea6e5c8276a96eee8c27ebd87.zip |
runtime: reduce GC assist extra credit
Mutator goroutines that allocate memory during the concurrent mark
phase are required to spend some time assisting the garbage
collector. The magnitude of this mandatory assistance is proportional
to the goroutine's allocation debt and subject to the assistance
ratio as calculated by the pacer.
When assisting the garbage collector, a mutator goroutine will go
beyond paying off its allocation debt. It will build up extra credit
to amortize the overhead of the assist.
In fast-allocating applications with high assist ratios, building up
this credit can take the affected goroutine's entire time slice.
Reduce the penalty on each goroutine being selected to assist the GC
in two ways, to spread the responsibility more evenly.
First, do a consistent amount of extra scan work without regard for
the pacer's assistance ratio. Second, reduce the magnitude of the
extra scan work so it can be completed within a few hundred
microseconds.
Commentary on gcOverAssistWork is by Austin Clements, originally in
https://golang.org/cl/24704
Updates #14812
Fixes #16432
Change-Id: I436f899e778c20daa314f3e9f0e2a1bbd53b43e1
Reviewed-on: https://go-review.googlesource.com/25155
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
Reviewed-by: Rick Hudson <rlh@golang.org>
Reviewed-by: Chris Broadfoot <cbro@golang.org>
-rw-r--r-- | src/runtime/mgc.go | 9 | ||||
-rw-r--r-- | src/runtime/mgcmark.go | 11 |
2 files changed, 12 insertions, 8 deletions
diff --git a/src/runtime/mgc.go b/src/runtime/mgc.go index 1eabf43d6f..3b238cba1c 100644 --- a/src/runtime/mgc.go +++ b/src/runtime/mgc.go @@ -741,11 +741,10 @@ const gcCreditSlack = 2000 // can accumulate on a P before updating gcController.assistTime. const gcAssistTimeSlack = 5000 -// gcOverAssistBytes determines how many extra allocation bytes of -// assist credit a GC assist builds up when an assist happens. This -// amortizes the cost of an assist by pre-paying for this many bytes -// of future allocations. -const gcOverAssistBytes = 1 << 20 +// gcOverAssistWork determines how many extra units of scan work a GC +// assist does when an assist happens. This amortizes the cost of an +// assist by pre-paying for this many bytes of future allocations. +const gcOverAssistWork = 64 << 10 var work struct { full uint64 // lock-free list of full blocks workbuf diff --git a/src/runtime/mgcmark.go b/src/runtime/mgcmark.go index 00b96fd00b..aa7f7a7769 100644 --- a/src/runtime/mgcmark.go +++ b/src/runtime/mgcmark.go @@ -393,10 +393,15 @@ func gcAssistAlloc(gp *g) { } // Compute the amount of scan work we need to do to make the - // balance positive. We over-assist to build up credit for - // future allocations and amortize the cost of assisting. - debtBytes := -gp.gcAssistBytes + gcOverAssistBytes + // balance positive. When the required amount of work is low, + // we over-assist to build up credit for future allocations + // and amortize the cost of assisting. + debtBytes := -gp.gcAssistBytes scanWork := int64(gcController.assistWorkPerByte * float64(debtBytes)) + if scanWork < gcOverAssistWork { + scanWork = gcOverAssistWork + debtBytes = int64(gcController.assistBytesPerWork * float64(scanWork)) + } retry: // Steal as much credit as we can from the background GC's |