aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/mgcpacer.go
diff options
context:
space:
mode:
authorMichael Knyszek <mknyszek@google.com>2021-10-01 15:07:45 -0400
committerMichael Knyszek <mknyszek@google.com>2021-10-29 18:35:59 +0000
commit5ec2427357f4917d0aad40cffddeea73e580129e (patch)
treea63abe5328886352bdaf6201ab0ae850f0721e03 /src/runtime/mgcpacer.go
parent9da64156a62e4661fb5b0e64a2f196f253ce0dc5 (diff)
downloadgo-5ec2427357f4917d0aad40cffddeea73e580129e.tar.gz
go-5ec2427357f4917d0aad40cffddeea73e580129e.zip
runtime: pass nanotime and gomaxprocs into startCycle and endCycle explicitly
This is to facilitate testing of the pacer, since otherwise this is accessing global state, which is impossible to stub out properly. For #44167. Change-Id: I52c3b51fc0ffff38e3bbe534bd66e5761c0003a8 Reviewed-on: https://go-review.googlesource.com/c/go/+/353353 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.go14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/runtime/mgcpacer.go b/src/runtime/mgcpacer.go
index ad7c4bb840..160383db43 100644
--- a/src/runtime/mgcpacer.go
+++ b/src/runtime/mgcpacer.go
@@ -290,7 +290,7 @@ func (c *gcControllerState) init(gcPercent int32) {
// startCycle resets the GC controller's state and computes estimates
// for a new GC cycle. The caller must hold worldsema and the world
// must be stopped.
-func (c *gcControllerState) startCycle(markStartTime int64) {
+func (c *gcControllerState) startCycle(markStartTime int64, procs int) {
c.scanWork = 0
c.bgScanCredit = 0
c.assistTime = 0
@@ -316,7 +316,7 @@ func (c *gcControllerState) startCycle(markStartTime int64) {
// dedicated workers so that the utilization is closest to
// 25%. For small GOMAXPROCS, this would introduce too much
// error, so we add fractional workers in that case.
- totalUtilizationGoal := float64(gomaxprocs) * gcBackgroundUtilization
+ totalUtilizationGoal := float64(procs) * gcBackgroundUtilization
c.dedicatedMarkWorkersNeeded = int64(totalUtilizationGoal + 0.5)
utilError := float64(c.dedicatedMarkWorkersNeeded)/totalUtilizationGoal - 1
const maxUtilError = 0.3
@@ -329,14 +329,14 @@ func (c *gcControllerState) startCycle(markStartTime int64) {
// Too many dedicated workers.
c.dedicatedMarkWorkersNeeded--
}
- c.fractionalUtilizationGoal = (totalUtilizationGoal - float64(c.dedicatedMarkWorkersNeeded)) / float64(gomaxprocs)
+ c.fractionalUtilizationGoal = (totalUtilizationGoal - float64(c.dedicatedMarkWorkersNeeded)) / float64(procs)
} else {
c.fractionalUtilizationGoal = 0
}
// In STW mode, we just want dedicated workers.
if debug.gcstoptheworld > 0 {
- c.dedicatedMarkWorkersNeeded = int64(gomaxprocs)
+ c.dedicatedMarkWorkersNeeded = int64(procs)
c.fractionalUtilizationGoal = 0
}
@@ -464,7 +464,7 @@ func (c *gcControllerState) revise() {
// endCycle computes the trigger ratio for the next cycle.
// userForced indicates whether the current GC cycle was forced
// by the application.
-func (c *gcControllerState) endCycle(userForced bool) float64 {
+func (c *gcControllerState) endCycle(now int64, procs int, userForced bool) float64 {
// Record last heap goal for the scavenger.
// We'll be updating the heap goal soon.
gcController.lastHeapGoal = gcController.heapGoal
@@ -495,13 +495,13 @@ func (c *gcControllerState) endCycle(userForced bool) float64 {
// heap growth is the error.
goalGrowthRatio := c.effectiveGrowthRatio()
actualGrowthRatio := float64(c.heapLive)/float64(c.heapMarked) - 1
- assistDuration := nanotime() - c.markStartTime
+ assistDuration := now - c.markStartTime
// Assume background mark hit its utilization goal.
utilization := gcBackgroundUtilization
// Add assist utilization; avoid divide by zero.
if assistDuration > 0 {
- utilization += float64(c.assistTime) / float64(assistDuration*int64(gomaxprocs))
+ utilization += float64(c.assistTime) / float64(assistDuration*int64(procs))
}
triggerError := goalGrowthRatio - c.triggerRatio - utilization/gcGoalUtilization*(actualGrowthRatio-c.triggerRatio)