From: Michael Anthony Knyszek Date: Thu, 11 Nov 2021 18:12:20 +0000 (+0000) Subject: runtime: fix released bytes accumulation in bg scavenger X-Git-Tag: go1.18beta1~325 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=f986191325e9c8be606b5f4db69a33692728274b;p=gostls13.git 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 --- 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 {