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

Closed
aclements opened this issue Feb 23, 2017 · 1 comment
Closed

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

aclements opened this issue Feb 23, 2017 · 1 comment
Milestone

Comments

@aclements
Copy link
Member

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() {
	runtime.GC()
	for {
		fib(10)
	}
}

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
@gopherbot
Copy link

CL https://golang.org/cl/37515 mentions this issue.

lparth pushed a commit to lparth/go that referenced this issue Apr 13, 2017
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
Reviewed-on: https://go-review.googlesource.com/37515
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rick Hudson <rlh@golang.org>
@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.
Projects
None yet
Development

No branches or pull requests

2 participants