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: long sweep termination #22410

Closed
aclements opened this issue Oct 24, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@aclements
Copy link
Member

commented Oct 24, 2017

What version of Go are you using (go version)?

go version devel +083338cb97 Mon Oct 23 15:40:08 2017 +0000 linux/amd64

Does this issue reproduce with the latest release?

Yes. Also tested with Go 1.9.

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/austin/r/go"
GORACE=""
GOROOT="/home/austin/go.dev"
GOTOOLDIR="/home/austin/go.dev/pkg/tool/linux_amd64"
GCCGO="/usr/bin/gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build896210704=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

What did you do?

I added the following benchmark to runtime/gc_test.go:

var (
	wbSink interface{}
	wbPtr  *int
)

func BenchmarkWriteBarrier(b *testing.B) {
	if runtime.GOMAXPROCS(-1) < 2 {
		// We don't want to time the allocation goroutine.
		b.Skip("need GOMAXPROCS >= 2")
	}

	// Give the GC something interesting to chew on so it runs for
	// a while.
	type node struct{ l, r *node }
	var mkTree func(int) *node
	mkTree = func(level int) *node {
		if level == 0 {
			return nil
		}
		return &node{mkTree(level - 1), mkTree(level - 1)}
	}
	wbSink = mkTree(22) // 64 MB
	runtime.GC()
	var ms runtime.MemStats
	runtime.ReadMemStats(&ms)
	b.Logf("heap size: %d MB", ms.HeapAlloc>>20)
	var stop uint32
	done := make(chan bool)
	go func() {
		for atomic.LoadUint32(&stop) == 0 {
			println("force GC")
			runtime.GC()
		}
		close(done)
	}()
	var i1, i2 int
	b.ResetTimer()

	for i := 0; i < b.N; i++ {
		if i%2 == 0 {
			wbPtr = &i1
		} else {
			wbPtr = &i2
		}
	}

	b.StopTimer()
	atomic.StoreUint32(&stop, 1)
	<-done
	wbSink = nil
}

Then I ran GODEBUG=gctrace=1 go test -bench WriteB -run NONE -v runtime.

I briefly attempted to extract and minimize this, but it didn't exhibit the problem.

What did you expect to see?

All STW phases in the gctrace are extremely short.

What did you see instead?

The very last line I get before the benchmark finishes is:

gc 45 @2.416s 51%: 3354+82+0.14 ms clock, 10063+0/71/126+0.43 ms cpu, 64->64->64 MB, 128 MB goal, 4 P (forced)

The sweep termination pause was 3.3 seconds.

This may be related to #22331.

/cc @RLH

@aclements aclements added this to the Go1.10 milestone Oct 24, 2017

@aclements

This comment has been minimized.

Copy link
Member Author

commented Oct 24, 2017

Clearly I shouldn't file bugs at 10 PM. Closing as dup of #10958 (non-preemptible loops).

@aclements aclements closed this Oct 24, 2017

@golang golang locked and limited conversation to collaborators Oct 24, 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.