]> Cypherpunks repositories - gostls13.git/commit
runtime: fix lock acquire cycles related to scavenge.lock
authorMichael Anthony Knyszek <mknyszek@google.com>
Thu, 5 Sep 2019 16:34:00 +0000 (16:34 +0000)
committerMichael Knyszek <mknyszek@google.com>
Thu, 26 Sep 2019 15:44:49 +0000 (15:44 +0000)
commit62e415655238a3c0103c1b70e6805edf8193c543
treea727170cfbdd9a0c66e9f00982100964abfcaab7
parentf7a00c99064d0cb367908a2bc6dea0bb007089de
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 #34047.

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>
src/runtime/mgc.go
src/runtime/mgcscavenge.go
src/runtime/mheap.go