@@ -255,7 +255,7 @@ func (c *gcControllerState) init(gcPercent int32) {
255
255
c .heapMarked = uint64 (float64 (c .heapMinimum ) / (1 + c .triggerRatio ))
256
256
257
257
// This will also compute and set the GC trigger and goal.
258
- _ = setGCPercent (gcPercent )
258
+ c . setGCPercent (gcPercent )
259
259
}
260
260
261
261
// startCycle resets the GC controller's state and computes estimates
@@ -784,19 +784,31 @@ func gcEffectiveGrowthRatio() float64 {
784
784
return egogc
785
785
}
786
786
787
+ // setGCPercent updates gcPercent and all related pacer state.
788
+ // Returns the old value of gcPercent.
789
+ //
790
+ // The world must be stopped, or mheap_.lock must be held.
791
+ func (c * gcControllerState ) setGCPercent (in int32 ) int32 {
792
+ assertWorldStoppedOrLockHeld (& mheap_ .lock )
793
+
794
+ out := c .gcPercent
795
+ if in < 0 {
796
+ in = - 1
797
+ }
798
+ c .gcPercent = in
799
+ c .heapMinimum = defaultHeapMinimum * uint64 (c .gcPercent ) / 100
800
+ // Update pacing in response to gcPercent change.
801
+ c .commit (c .triggerRatio )
802
+
803
+ return out
804
+ }
805
+
787
806
//go:linkname setGCPercent runtime/debug.setGCPercent
788
807
func setGCPercent (in int32 ) (out int32 ) {
789
808
// Run on the system stack since we grab the heap lock.
790
809
systemstack (func () {
791
810
lock (& mheap_ .lock )
792
- out = gcController .gcPercent
793
- if in < 0 {
794
- in = - 1
795
- }
796
- gcController .gcPercent = in
797
- gcController .heapMinimum = defaultHeapMinimum * uint64 (gcController .gcPercent ) / 100
798
- // Update pacing in response to gcPercent change.
799
- gcController .commit (gcController .triggerRatio )
811
+ out = gcController .setGCPercent (in )
800
812
unlock (& mheap_ .lock )
801
813
})
802
814
0 commit comments