From: Andy Pan Date: Tue, 5 Sep 2023 09:12:24 +0000 (+0800) Subject: runtime: fix the miscalculation of memoryLimitGoal in gcPaceScavenger X-Git-Tag: go1.22rc1~976 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=729f214e3afd61afd924b946745798a8d144aad6;p=gostls13.git runtime: fix the miscalculation of memoryLimitGoal in gcPaceScavenger 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 TryBot-Result: Gopher Robot Run-TryBot: Michael Knyszek Reviewed-by: Michael Pratt LUCI-TryBot-Result: Go LUCI Run-TryBot: Andy Pan --- diff --git a/src/runtime/mgcscavenge.go b/src/runtime/mgcscavenge.go index 4c6d6be4f0..b24d830732 100644 --- a/src/runtime/mgcscavenge.go +++ b/src/runtime/mgcscavenge.go @@ -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.)