From f986191325e9c8be606b5f4db69a33692728274b Mon Sep 17 00:00:00 2001 From: Michael Anthony Knyszek Date: Thu, 11 Nov 2021 18:12:20 +0000 Subject: [PATCH] runtime: fix released bytes accumulation in bg scavenger Currently "released" is not accumulated bytes released. If the last attempt to scavenge ends up as 0, then the scavenger will go to sleep too soon. This is an artifact from the old code where scavenge would only be called into once. Change-Id: I85aa2261f1504a6fb5bf086daa029eecb0e09cf4 Reviewed-on: https://go-review.googlesource.com/c/go/+/363416 Trust: Michael Knyszek Reviewed-by: Michael Pratt Run-TryBot: Michael Knyszek TryBot-Result: Go Bot --- src/runtime/mgcscavenge.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/runtime/mgcscavenge.go b/src/runtime/mgcscavenge.go index 4a7f2465fd..286aa1bbae 100644 --- a/src/runtime/mgcscavenge.go +++ b/src/runtime/mgcscavenge.go @@ -326,8 +326,8 @@ func bgscavenge(c chan int) { // Accumulate the amount of time spent scavenging. start := nanotime() - released = mheap_.pages.scavenge(scavengeQuantum) - atomic.Xadduintptr(&mheap_.pages.scav.released, released) + r := mheap_.pages.scavenge(scavengeQuantum) + atomic.Xadduintptr(&mheap_.pages.scav.released, r) end := nanotime() // On some platforms we may see end >= start if the time it takes to scavenge @@ -339,10 +339,11 @@ func bgscavenge(c chan int) { // on timing. const approxCritNSPerPhysicalPage = 10e3 if end <= start { - crit += approxCritNSPerPhysicalPage * float64(released/physPageSize) + crit += approxCritNSPerPhysicalPage * float64(r/physPageSize) } else { crit += float64(end - start) } + released += r } if released == 0 { -- 2.48.1