]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: compute goal first in gcSetTriggerRatio
authorAustin Clements <austin@google.com>
Wed, 21 Jun 2017 16:11:52 +0000 (12:11 -0400)
committerAustin Clements <austin@google.com>
Tue, 5 Mar 2019 23:08:15 +0000 (23:08 +0000)
This slightly rearranges gcSetTriggerRatio to compute the goal before
computing the other controls. This will simplify implementing the heap
limit, which needs to control the absolute goal and flow the rest of
the control parameters from this.

For #16843.

Change-Id: I46b7c1f8b6e4edbee78930fb093b60bd1a03d75e
Reviewed-on: https://go-review.googlesource.com/c/go/+/46750
Run-TryBot: Austin Clements <austin@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Rick Hudson <rlh@golang.org>
src/runtime/mgc.go

index 5b974d466b81f09e4d3fe2812fa92bfe2a83decc..730b64cd198da69b5b603bc679142100644cd35e 100644 (file)
@@ -765,6 +765,14 @@ func pollFractionalWorkerExit() bool {
 //
 // mheap_.lock must be held or the world must be stopped.
 func gcSetTriggerRatio(triggerRatio float64) {
+       // Compute the next GC goal, which is when the allocated heap
+       // has grown by GOGC/100 over the heap marked by the last
+       // cycle.
+       goal := ^uint64(0)
+       if gcpercent >= 0 {
+               goal = memstats.heap_marked + memstats.heap_marked*uint64(gcpercent)/100
+       }
+
        // Set the trigger ratio, capped to reasonable bounds.
        if triggerRatio < 0 {
                // This can happen if the mutator is allocating very
@@ -807,22 +815,16 @@ func gcSetTriggerRatio(triggerRatio float64) {
                        print("runtime: next_gc=", memstats.next_gc, " heap_marked=", memstats.heap_marked, " heap_live=", memstats.heap_live, " initialHeapLive=", work.initialHeapLive, "triggerRatio=", triggerRatio, " minTrigger=", minTrigger, "\n")
                        throw("gc_trigger underflow")
                }
-       }
-       memstats.gc_trigger = trigger
-
-       // Compute the next GC goal, which is when the allocated heap
-       // has grown by GOGC/100 over the heap marked by the last
-       // cycle.
-       goal := ^uint64(0)
-       if gcpercent >= 0 {
-               goal = memstats.heap_marked + memstats.heap_marked*uint64(gcpercent)/100
-               if goal < trigger {
+               if trigger > goal {
                        // The trigger ratio is always less than GOGC/100, but
                        // other bounds on the trigger may have raised it.
                        // Push up the goal, too.
                        goal = trigger
                }
        }
+
+       // Commit to the trigger and goal.
+       memstats.gc_trigger = trigger
        memstats.next_gc = goal
        if trace.enabled {
                traceNextGC()