]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: fix released bytes accumulation in bg scavenger
authorMichael Anthony Knyszek <mknyszek@google.com>
Thu, 11 Nov 2021 18:12:20 +0000 (18:12 +0000)
committerMichael Knyszek <mknyszek@google.com>
Mon, 15 Nov 2021 17:10:25 +0000 (17:10 +0000)
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 <mknyszek@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Run-TryBot: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Go Bot <gobot@golang.org>

src/runtime/mgcscavenge.go

index 4a7f2465fd1d749b9a2803e9b4c2741bf6a60238..286aa1bbaef05cb040c6b3f47828d78eb0c90479 100644 (file)
@@ -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 {