]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: set HeapGoal to zero when the GC is disabled
authorCarlos Amedee <carlos@golang.org>
Thu, 2 Jan 2025 19:41:59 +0000 (14:41 -0500)
committerCarlos Amedee <carlos@golang.org>
Fri, 30 May 2025 18:29:03 +0000 (11:29 -0700)
When the GC is disabled, the tracer should emit a heap goal of 0. Not
setting the heap goal to 0 causes an inaccurate NextGC value to be
emmited.

Fixes #63864

Change-Id: Iecceaca86c0a43c1cc4d9433f1f9bb736f01ccbc
Reviewed-on: https://go-review.googlesource.com/c/go/+/639417
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
src/runtime/traceruntime.go

index 98ac1082a824b2a380af38e3ae9582cd7cd3f4e4..39adeb4c07ea37608478c86dc0ef308ab5b04a11 100644 (file)
@@ -574,7 +574,9 @@ func (tl traceLocker) HeapAlloc(live uint64) {
 // HeapGoal reads the current heap goal and emits a HeapGoal event.
 func (tl traceLocker) HeapGoal() {
        heapGoal := gcController.heapGoal()
-       if heapGoal == ^uint64(0) {
+       // The heapGoal calculations will result in strange numbers if the GC if off. See go.dev/issue/63864.
+       // Check gcPercent before using the heapGoal in the trace.
+       if heapGoal == ^uint64(0) || gcController.gcPercent.Load() < 0 {
                // Heap-based triggering is disabled.
                heapGoal = 0
        }