diff options
author | Michael Anthony Knyszek <mknyszek@google.com> | 2021-04-11 18:29:03 +0000 |
---|---|---|
committer | Michael Knyszek <mknyszek@google.com> | 2021-10-29 18:35:01 +0000 |
commit | 8e112a7c2a814de9156f68dc8b167e4ef8c98c52 (patch) | |
tree | 37fc705a72ea7aad45efff0fe3951013bbd6ee75 /src/runtime/mgcpacer.go | |
parent | 4a5d78ff8b7e777d70b18a61698b1ac07bbd623d (diff) | |
download | go-8e112a7c2a814de9156f68dc8b167e4ef8c98c52.tar.gz go-8e112a7c2a814de9156f68dc8b167e4ef8c98c52.zip |
runtime: move heapLive and heapScan updates into a method
This change moves heapLive and heapScan updates on gcController into a
method for better testability. It's also less error-prone because code
that updates these fields needs to remember to emit traces and/or call
gcController.revise; this method now handles those cases.
For #44167.
Change-Id: I3d6f2e7abb22def27c93feacff50162b0b074da2
Reviewed-on: https://go-review.googlesource.com/c/go/+/309275
Trust: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Michael Pratt <mpratt@google.com>
Diffstat (limited to 'src/runtime/mgcpacer.go')
-rw-r--r-- | src/runtime/mgcpacer.go | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/runtime/mgcpacer.go b/src/runtime/mgcpacer.go index 503b8110b3..094dcc701a 100644 --- a/src/runtime/mgcpacer.go +++ b/src/runtime/mgcpacer.go @@ -669,6 +669,23 @@ func (c *gcControllerState) logWorkTime(mode gcMarkWorkerMode, duration int64) { } } +func (c *gcControllerState) update(dHeapLive, dHeapScan int64) { + if dHeapLive != 0 { + atomic.Xadd64(&gcController.heapLive, dHeapLive) + if trace.enabled { + // gcController.heapLive changed. + traceHeapAlloc() + } + } + if dHeapScan != 0 { + atomic.Xadd64(&gcController.heapScan, dHeapScan) + } + if gcBlackenEnabled != 0 { + // gcController.heapLive and heapScan changed. + c.revise() + } +} + // commit sets the trigger ratio and updates everything // derived from it: the absolute trigger, the heap goal, mark pacing, // and sweep pacing. |