Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtime: GC attempted every 10ms when GC is off #19247

aclements opened this issue Feb 23, 2017 · 1 comment


None yet
2 participants
Copy link

commented Feb 23, 2017

The logic to trigger periodic GC is such that if GC is disabled but at least one GC cycle has ever happened (e.g., GC was disabled at runtime by SetGCPercent(-1) or runtime.GC() was called), then once the periodic GC period has elapsed (2 minutes by default), sysmon will attempt to trigger a GC every 10ms. This GC will be a no-op, but it still goes through the motions of waking the goroutine and prints a gctrace line.

The following program demonstrates this:

package main

import "runtime"

func main() {
	for {

func fib(n int) int {
	if n <= 2 {
		return 1
	return fib(n-1) + fib(n-2)

If run with GODEBUG=gctrace=1 GOGC=off ./test, then after two minutes the runtime will print GC forced every 10ms. (If you don't want to wait two minutes, add forcegcperiod = 10 * 1e9 to sysmon.)

AFAIK this isn't happening in the wild. I found this while reworking the triggering logic.

/cc @RLH

@aclements aclements added this to the Go1.9 milestone Feb 23, 2017

@aclements aclements self-assigned this Feb 23, 2017


This comment has been minimized.

Copy link

commented Feb 27, 2017

CL mentions this issue.

@gopherbot gopherbot closed this in 640cd3b Mar 31, 2017

lparth added a commit to lparth/go that referenced this issue Apr 13, 2017

runtime: check transition condition before triggering periodic GC
Currently sysmon triggers periodic GC if GC is not currently running
and it's been long enough since the last GC. This misses some
important conditions; for example, whether GC is enabled at all by
GOGC. As a result, if GOGC is off, once we pass the timeout for
periodic GC, sysmon will attempt to trigger a GC every 10ms. This GC
will be a no-op because gcStart will check all of the appropriate
conditions and do nothing, but it still goes through the motions of
waking the forcegc goroutine and printing a gctrace line.

Fix this by making sysmon call gcShouldStart to check *all* of the
appropriate transition conditions before attempting to trigger a
periodic GC.

Fixes golang#19247.

Change-Id: Icee5521ce175e8419f934723849853d53773af31
Run-TryBot: Austin Clements <>
TryBot-Result: Gobot Gobot <>
Reviewed-by: Rick Hudson <>

@golang golang locked and limited conversation to collaborators Mar 31, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.