你使用的Go版本是什么( go version
)?
$ go version
go version devel +13f59a65 Sat Nov 7 10:28:10 2020 +0800 linux/amd64
这个问题在最新版本中是否重现?
未测试
你正在使用什么操作系统和处理器架构( go env
)?
go env
输出
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/taoqy/.cache/go-build"
GOENV="/home/taoqy/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/taoqy/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/taoqy/go"
GOPRIVATE=""
GOPROXY="https://goproxy.io"
GOROOT="/home/taoqy/cc/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/taoqy/cc/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build557590123=/tmp/go-build -gno-record-gcc-switches"
你做了什么?
package main
import (
"fmt"
"runtime"
_ "unsafe"
)
type Work struct {
_ [400 - 96]byte
// cycles is the number of completed GC cycles, where a GC
// cycle is sweep termination, mark, mark termination, and
// sweep. This differs from memstats.numgc, which is
// incremented at mark termination.
cycles uint32
// Timing/utilization stats for this cycle.
stwprocs, maxprocs int32
tSweepTerm, tMark, tMarkTerm, tEnd int64 // nanotime() of phase start
pauseNS int64 // total STW time this cycle
pauseStart int64 // nanotime() of last STW
// debug.gctrace heap sizes for this cycle.
heap0, heap1, heap2, heapGoal uint64
}
//go:linkname work runtime.work
var work Work
func main() {
work.cycles = ^uint32(0) - 3
runtime.GC()
fmt.Println(work.cycles)
runtime.GC()
fmt.Println(work.cycles)
runtime.GC()
fmt.Println(work.cycles)
}
你期望看到什么?
正常退出。
你看到了什么?
4294967293
4294967294
fatal error: all goroutines are asleep - deadlock!
goroutine 1 [wait for GC cycle]:
runtime.GC()
/home/taoqy/cc/go/src/runtime/mgc.go:1162 +0xa5
main.main()
/tmp/wgc/main2.go:41 +0x105
3条答案
按热度按时间tzdcorbm1#
这有很多GC周期...
cc @aclements是否值得处理这个问题。
6tr1vspr2#
假设垃圾回收每2毫秒发生一次,需要(1 << 32) / 500 / (24 * 3600) = 99天才能溢出。这似乎是可能的。
nom7f22z3#
查看一些产品数据,似乎更现实的GC周期速率可能是每秒10次,在99.9百分位数?