]> Cypherpunks.ru repositories - gostls13.git/commit
runtime: decouple consistent stats from mcache and allow P-less update
authorMichael Anthony Knyszek <mknyszek@google.com>
Mon, 2 Nov 2020 19:03:16 +0000 (19:03 +0000)
committerMichael Knyszek <mknyszek@google.com>
Mon, 2 Nov 2020 21:21:46 +0000 (21:21 +0000)
commit39a5ee52b9b41b1e4f4cf821c78ef5b7be68d181
tree7c1929e087a1d27118dcad9f607391868dbb32a0
parentac766e37182f36cd0a3247e44a4143d2d2132e42
runtime: decouple consistent stats from mcache and allow P-less update

This change modifies the consistent stats implementation to keep the
per-P sequence counter on each P instead of each mcache. A valid mcache
is not available everywhere that we want to call e.g. allocSpan, as per
issue #42339. By decoupling these two, we can add a mechanism to allow
contexts without a P to update stats consistently.

In this CL, we achieve that with a mutex. In practice, it will be very
rare for an M to update these stats without a P. Furthermore, the stats
reader also only needs to hold the mutex across the update to "gen"
since once that changes, writers are free to continue updating the new
stats generation. Contention could thus only arise between writers
without a P, and as mentioned earlier, those should be rare.

A nice side-effect of this change is that the consistent stats acquire
and release API becomes simpler.

Fixes #42339.

Change-Id: Ied74ab256f69abd54b550394c8ad7c4c40a5fe34
Reviewed-on: https://go-review.googlesource.com/c/go/+/267158
Run-TryBot: Michael Knyszek <mknyszek@google.com>
Trust: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
src/runtime/mcache.go
src/runtime/mgcscavenge.go
src/runtime/mgcsweep.go
src/runtime/mheap.go
src/runtime/mstats.go
src/runtime/proc.go
src/runtime/runtime2.go