From 9da64156a62e4661fb5b0e64a2f196f253ce0dc5 Mon Sep 17 00:00:00 2001 From: Michael Anthony Knyszek Date: Mon, 12 Apr 2021 22:40:36 +0000 Subject: [PATCH] runtime: track scannable globals space For #44167. Change-Id: I2cd13229d88f630451fabd113b0e5a04841e9e79 Reviewed-on: https://go-review.googlesource.com/c/go/+/309590 Trust: Michael Knyszek Run-TryBot: Michael Knyszek TryBot-Result: Go Bot Reviewed-by: Michael Pratt --- src/runtime/mgcpacer.go | 10 ++++++++++ src/runtime/symtab.go | 7 +++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/runtime/mgcpacer.go b/src/runtime/mgcpacer.go index 9cc7cf99dbad64..ad7c4bb840dfe1 100644 --- a/src/runtime/mgcpacer.go +++ b/src/runtime/mgcpacer.go @@ -182,6 +182,12 @@ type gcControllerState struct { // Read and updated atomically. scannableStackSize uint64 + // globalsScan is the total amount of global variable space + // that is scannable. + // + // Read and updated atomically. + globalsScan uint64 + // heapMarked is the number of bytes marked by the previous // GC. After mark termination, heapLive == heapMarked, but // unlike heapLive, heapMarked does not change until the @@ -715,6 +721,10 @@ func (c *gcControllerState) addScannableStack(pp *p, amount int64) { } } +func (c *gcControllerState) addGlobals(amount int64) { + atomic.Xadd64(&c.globalsScan, amount) +} + // commit sets the trigger ratio and updates everything // derived from it: the absolute trigger, the heap goal, mark pacing, // and sweep pacing. diff --git a/src/runtime/symtab.go b/src/runtime/symtab.go index 41161d6f900561..3237a6b708611c 100644 --- a/src/runtime/symtab.go +++ b/src/runtime/symtab.go @@ -529,8 +529,11 @@ func modulesinit() { } *modules = append(*modules, md) if md.gcdatamask == (bitvector{}) { - md.gcdatamask = progToPointerMask((*byte)(unsafe.Pointer(md.gcdata)), md.edata-md.data) - md.gcbssmask = progToPointerMask((*byte)(unsafe.Pointer(md.gcbss)), md.ebss-md.bss) + scanDataSize := md.edata - md.data + md.gcdatamask = progToPointerMask((*byte)(unsafe.Pointer(md.gcdata)), scanDataSize) + scanBSSSize := md.ebss - md.bss + md.gcbssmask = progToPointerMask((*byte)(unsafe.Pointer(md.gcbss)), scanBSSSize) + gcController.addGlobals(int64(scanDataSize + scanBSSSize)) } }