]> Cypherpunks repositories - gostls13.git/commit
[release-branch.go1.13] 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)
committerAndrew Bonventre <andybons@golang.org>
Wed, 2 Oct 2019 19:51:10 +0000 (19:51 +0000)
commit8a6cd7a082cb0c15bc4eef19519506125e76f66a
tree53d3011d374542d807eeb8961c343243e12e2682
parent8c8a881688ea386070ee9f6646b9ef7af52ad5ba
[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>
src/runtime/mgc.go
src/runtime/mgcscavenge.go
src/runtime/mheap.go