mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
runtime: create initializer for gcControllerState
Now that gcControllerState contains almost all of the pacer state, create an initializer for it instead of haphazardly setting some fields. For #44167. Change-Id: I4ce1d5dd82003cb7c263fa46697851bb22a32544 Reviewed-on: https://go-review.googlesource.com/c/go/+/306601 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>
This commit is contained in:
parent
2d4ba2601b
commit
9bce7b70fd
2 changed files with 18 additions and 13 deletions
|
|
@ -153,22 +153,12 @@ func gcinit() {
|
||||||
if unsafe.Sizeof(workbuf{}) != _WorkbufSize {
|
if unsafe.Sizeof(workbuf{}) != _WorkbufSize {
|
||||||
throw("size of Workbuf is suboptimal")
|
throw("size of Workbuf is suboptimal")
|
||||||
}
|
}
|
||||||
gcController.heapMinimum = defaultHeapMinimum
|
|
||||||
|
|
||||||
// No sweep on the first cycle.
|
// No sweep on the first cycle.
|
||||||
mheap_.sweepDrained = 1
|
mheap_.sweepDrained = 1
|
||||||
|
|
||||||
// Set a reasonable initial GC trigger.
|
// Initialize GC pacer state.
|
||||||
gcController.triggerRatio = 7 / 8.0
|
// Use the environment variable GOGC for the initial gcPercent value.
|
||||||
|
gcController.init(readGOGC())
|
||||||
// Fake a heapMarked value so it looks like a trigger at
|
|
||||||
// heapMinimum is the appropriate growth from heapMarked.
|
|
||||||
// This will go into computing the initial GC goal.
|
|
||||||
gcController.heapMarked = uint64(float64(gcController.heapMinimum) / (1 + gcController.triggerRatio))
|
|
||||||
|
|
||||||
// Set gcPercent from the environment. This will also compute
|
|
||||||
// and set the GC trigger and goal.
|
|
||||||
_ = setGCPercent(readGOGC())
|
|
||||||
|
|
||||||
work.startSema = 1
|
work.startSema = 1
|
||||||
work.markDoneSema = 1
|
work.markDoneSema = 1
|
||||||
|
|
|
||||||
|
|
@ -243,6 +243,21 @@ type gcControllerState struct {
|
||||||
_ cpu.CacheLinePad
|
_ cpu.CacheLinePad
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *gcControllerState) init(gcPercent int32) {
|
||||||
|
c.heapMinimum = defaultHeapMinimum
|
||||||
|
|
||||||
|
// Set a reasonable initial GC trigger.
|
||||||
|
c.triggerRatio = 7 / 8.0
|
||||||
|
|
||||||
|
// Fake a heapMarked value so it looks like a trigger at
|
||||||
|
// heapMinimum is the appropriate growth from heapMarked.
|
||||||
|
// This will go into computing the initial GC goal.
|
||||||
|
c.heapMarked = uint64(float64(c.heapMinimum) / (1 + c.triggerRatio))
|
||||||
|
|
||||||
|
// This will also compute and set the GC trigger and goal.
|
||||||
|
_ = setGCPercent(gcPercent)
|
||||||
|
}
|
||||||
|
|
||||||
// startCycle resets the GC controller's state and computes estimates
|
// startCycle resets the GC controller's state and computes estimates
|
||||||
// for a new GC cycle. The caller must hold worldsema and the world
|
// for a new GC cycle. The caller must hold worldsema and the world
|
||||||
// must be stopped.
|
// must be stopped.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue