8a6cd7a [release-branch.go1.13] runtime: fix lock acquire cycles related to scavenge.lock

3 files Authored by Michael Anthony Knyszek 4 years ago, Committed by Andrew Bonventre 4 years ago,
    [release-branch.go1.13] runtime: fix lock acquire cycles related to scavenge.lock
    
    There are currently two edges in the lock cycle graph caused by
    scavenge.lock: with sched.lock and mheap_.lock. These edges appear
    because of the call to ready() and stack growths respectively.
    Furthermore, there's already an invariant in the code wherein
    mheap_.lock must be acquired before scavenge.lock, hence the cycle.
    
    The fix to this is to bring scavenge.lock higher in the lock cycle
    graph, such that sched.lock and mheap_.lock are only acquired once
    scavenge.lock is already held.
    
    To faciliate this change, we move scavenger waking outside of
    gcSetTriggerRatio such that it doesn't have to happen with the heap
    locked. Furthermore, we check scavenge generation numbers with the heap
    locked by using gopark instead of goparkunlock, and specify a function
    which aborts the park should there be any skew in generation count.
    
    Fixes #34150.
    
    Change-Id: I3519119214bac66375e2b1262b36ce376c820d12
    Reviewed-on: https://go-review.googlesource.com/c/go/+/191977
    Run-TryBot: Michael Knyszek <mknyszek@google.com>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    Reviewed-by: Keith Randall <khr@golang.org>
    (cherry picked from commit 62e415655238a3c0103c1b70e6805edf8193c543)
    Reviewed-on: https://go-review.googlesource.com/c/go/+/197501
    Reviewed-by: Austin Clements <austin@google.com>
    
        
file modified
+5 -0
file modified
+39 -29
file modified
+1 -0