From 227fff2ea4f21ec357eebe27324cc04b7c9919c7 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Tue, 4 Apr 2017 13:26:28 -0400 Subject: runtime/debug: don't trigger a GC on SetGCPercent Currently SetGCPercent forces a GC in order to recompute GC pacing. Since we can now recompute pacing on the fly using gcSetTriggerRatio, change SetGCPercent (really runtime.setGCPercent) to go through gcSetTriggerRatio and not trigger a GC. Fixes #19076. Change-Id: Ib30d7ab1bb3b55219535b9f238108f3d45a1b522 Reviewed-on: https://go-review.googlesource.com/39835 Run-TryBot: Austin Clements Reviewed-by: Rick Hudson --- src/runtime/debug/garbage.go | 6 +----- src/runtime/debug/garbage_test.go | 2 ++ 2 files changed, 3 insertions(+), 5 deletions(-) (limited to 'src/runtime/debug') diff --git a/src/runtime/debug/garbage.go b/src/runtime/debug/garbage.go index 27adc70fd3..785e9d4598 100644 --- a/src/runtime/debug/garbage.go +++ b/src/runtime/debug/garbage.go @@ -89,11 +89,7 @@ func ReadGCStats(stats *GCStats) { // at startup, or 100 if the variable is not set. // A negative percentage disables garbage collection. func SetGCPercent(percent int) int { - old := setGCPercent(int32(percent)) - if percent >= 0 { - runtime.GC() - } - return int(old) + return int(setGCPercent(int32(percent))) } // FreeOSMemory forces a garbage collection followed by an diff --git a/src/runtime/debug/garbage_test.go b/src/runtime/debug/garbage_test.go index 37417aca2c..acc781ebdc 100644 --- a/src/runtime/debug/garbage_test.go +++ b/src/runtime/debug/garbage_test.go @@ -160,6 +160,8 @@ func TestSetGCPercent(t *testing.T) { runtime.ReadMemStats(&ms) ngc1 := ms.NumGC SetGCPercent(10) + // It may require an allocation to actually force the GC. + setGCPercentSink = make([]byte, 1<<20) runtime.ReadMemStats(&ms) ngc2 := ms.NumGC if ngc1 == ngc2 { -- cgit v1.3