mirror of
https://github.com/golang/go
synced 2024-11-11 22:40:22 -07:00
runtime: create setGCPercent method for gcControllerState
This change breaks out the computations done by setGCPercent into a method on gcControllerState for easier testing later. It leaves behind the global implementation details. For #44167. Change-Id: I3b0cf1475b032fcd4ebbd01cf4e80de0b55ce7b0 Reviewed-on: https://go-review.googlesource.com/c/go/+/306602 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
9bce7b70fd
commit
e7ab1a5ba8
@ -255,7 +255,7 @@ func (c *gcControllerState) init(gcPercent int32) {
|
|||||||
c.heapMarked = uint64(float64(c.heapMinimum) / (1 + c.triggerRatio))
|
c.heapMarked = uint64(float64(c.heapMinimum) / (1 + c.triggerRatio))
|
||||||
|
|
||||||
// This will also compute and set the GC trigger and goal.
|
// This will also compute and set the GC trigger and goal.
|
||||||
_ = setGCPercent(gcPercent)
|
c.setGCPercent(gcPercent)
|
||||||
}
|
}
|
||||||
|
|
||||||
// startCycle resets the GC controller's state and computes estimates
|
// startCycle resets the GC controller's state and computes estimates
|
||||||
@ -784,19 +784,31 @@ func gcEffectiveGrowthRatio() float64 {
|
|||||||
return egogc
|
return egogc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// setGCPercent updates gcPercent and all related pacer state.
|
||||||
|
// Returns the old value of gcPercent.
|
||||||
|
//
|
||||||
|
// The world must be stopped, or mheap_.lock must be held.
|
||||||
|
func (c *gcControllerState) setGCPercent(in int32) int32 {
|
||||||
|
assertWorldStoppedOrLockHeld(&mheap_.lock)
|
||||||
|
|
||||||
|
out := c.gcPercent
|
||||||
|
if in < 0 {
|
||||||
|
in = -1
|
||||||
|
}
|
||||||
|
c.gcPercent = in
|
||||||
|
c.heapMinimum = defaultHeapMinimum * uint64(c.gcPercent) / 100
|
||||||
|
// Update pacing in response to gcPercent change.
|
||||||
|
c.commit(c.triggerRatio)
|
||||||
|
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
//go:linkname setGCPercent runtime/debug.setGCPercent
|
//go:linkname setGCPercent runtime/debug.setGCPercent
|
||||||
func setGCPercent(in int32) (out int32) {
|
func setGCPercent(in int32) (out int32) {
|
||||||
// Run on the system stack since we grab the heap lock.
|
// Run on the system stack since we grab the heap lock.
|
||||||
systemstack(func() {
|
systemstack(func() {
|
||||||
lock(&mheap_.lock)
|
lock(&mheap_.lock)
|
||||||
out = gcController.gcPercent
|
out = gcController.setGCPercent(in)
|
||||||
if in < 0 {
|
|
||||||
in = -1
|
|
||||||
}
|
|
||||||
gcController.gcPercent = in
|
|
||||||
gcController.heapMinimum = defaultHeapMinimum * uint64(gcController.gcPercent) / 100
|
|
||||||
// Update pacing in response to gcPercent change.
|
|
||||||
gcController.commit(gcController.triggerRatio)
|
|
||||||
unlock(&mheap_.lock)
|
unlock(&mheap_.lock)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user