mheap_.pagesSweptBasis.Store(pagesSwept)
}
}
-
- gcPaceScavenger()
}
// effectiveGrowthRatio returns the current effective heap growth
// setGCPercent updates gcPercent and all related pacer state.
// Returns the old value of gcPercent.
//
+// Calls gcControllerState.commit.
+//
// The world must be stopped, or mheap_.lock must be held.
func (c *gcControllerState) setGCPercent(in int32) int32 {
assertWorldStoppedOrLockHeld(&mheap_.lock)
systemstack(func() {
lock(&mheap_.lock)
out = gcController.setGCPercent(in)
+ gcPaceScavenger(gcController.heapGoal, gcController.lastHeapGoal)
unlock(&mheap_.lock)
})
}
// gcPaceScavenger updates the scavenger's pacing, particularly
-// its rate and RSS goal.
+// its rate and RSS goal. For this, it requires the current heapGoal,
+// and the heapGoal for the previous GC cycle.
//
// The RSS goal is based on the current heap goal with a small overhead
// to accommodate non-determinism in the allocator.
// The pacing is based on scavengePageRate, which applies to both regular and
// huge pages. See that constant for more information.
//
+// Must be called whenever GC pacing is updated.
+//
// mheap_.lock must be held or the world must be stopped.
-func gcPaceScavenger() {
+func gcPaceScavenger(heapGoal, lastHeapGoal uint64) {
+ assertWorldStoppedOrLockHeld(&mheap_.lock)
+
// If we're called before the first GC completed, disable scavenging.
// We never scavenge before the 2nd GC cycle anyway (we don't have enough
// information about the heap yet) so this is fine, and avoids a fault
// or garbage data later.
- if gcController.lastHeapGoal == 0 {
+ if lastHeapGoal == 0 {
mheap_.scavengeGoal = ^uint64(0)
return
}
// Compute our scavenging goal.
- goalRatio := float64(atomic.Load64(&gcController.heapGoal)) / float64(gcController.lastHeapGoal)
+ goalRatio := float64(heapGoal) / float64(lastHeapGoal)
retainedGoal := uint64(float64(memstats.last_heap_inuse) * goalRatio)
// Add retainExtraPercent overhead to retainedGoal. This calculation
// looks strange but the purpose is to arrive at an integer division