• Austin Clements's avatar
    runtime: decentralize sweep termination and mark transition · a51905fa
    Austin Clements authored
    This moves all of GC initialization, sweep termination, and the
    transition to concurrent marking in to the off->mark transition
    function. This means it's now handled on the goroutine that detected
    the state exit condition.
    
    As a result, malloc no longer needs to Gosched() at the beginning of
    the GC cycle to prevent over-allocation while the GC is starting up
    because it will now *help* the GC to start up. The Gosched hack is
    still necessary during GC shutdown (this is easy to test by enabling
    gctrace and hitting Ctrl-S to block the gctrace output).
    
    At this point, the GC coordinator still handles later phases. This
    requires a small tweak to how we start the GC coordinator. Currently,
    starting the GC coordinator is best-effort and may fail if the
    coordinator is about to park from the previous cycle but hasn't yet.
    We fix this by replacing the park/ready to wake up the coordinator
    with a semaphore. This is temporary since the coordinator will be
    going away in a few commits.
    
    Updates #11970.
    
    Change-Id: I2c6a11c91e72dfbc59c2d8e7c66146dee9a444fe
    Reviewed-on: https://go-review.googlesource.com/16357Reviewed-by: default avatarRick Hudson <rlh@golang.org>
    Run-TryBot: Austin Clements <austin@google.com>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    a51905fa
mgc.go 61.6 KB