]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: fix the miscalculation of memoryLimitGoal in gcPaceScavenger
authorAndy Pan <panjf2000@gmail.com>
Tue, 5 Sep 2023 09:12:24 +0000 (17:12 +0800)
committerMichael Knyszek <mknyszek@google.com>
Wed, 6 Sep 2023 19:37:10 +0000 (19:37 +0000)
The goal is supposed to be (100-reduceExtraPercent) / 100 * memoryLimit,
as stated in the original design.

Fixes #62449

Change-Id: Ia33acadc3320aa3625814595a24b9631ae8896d9
Reviewed-on: https://go-review.googlesource.com/c/go/+/525555
Reviewed-by: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Run-TryBot: Andy Pan <panjf2000@gmail.com>

src/runtime/mgcscavenge.go

index 4c6d6be4f04b754412fdd2337537d1b957c47bd7..b24d8307320523369b8010bb581daab98ae3d641 100644 (file)
@@ -172,7 +172,7 @@ func gcPaceScavenger(memoryLimit int64, heapGoal, lastHeapGoal uint64) {
        // it's simpler.
 
        // We want to target retaining (100-reduceExtraPercent)% of the heap.
-       memoryLimitGoal := uint64(float64(memoryLimit) * (100.0 - reduceExtraPercent))
+       memoryLimitGoal := uint64(float64(memoryLimit) * (1 - reduceExtraPercent/100.0))
 
        // mappedReady is comparable to memoryLimit, and represents how much total memory
        // the Go runtime has committed now (estimated).
@@ -1297,7 +1297,7 @@ const (
        scavChunkHasFree scavChunkFlags = 1 << iota
        // scavChunkNoHugePage indicates whether this chunk has had any huge
        // pages broken by the scavenger.
-       //.
+       //
        // The negative here is unfortunate, but necessary to make it so that
        // the zero value of scavChunkData accurately represents the state of
        // a newly-grown chunk. (New memory is marked as backed by huge pages.)