aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/runtime2.go
diff options
context:
space:
mode:
authorMichael Pratt <mpratt@google.com>2020-10-13 12:39:13 -0400
committerMichael Pratt <mpratt@google.com>2020-10-30 15:25:49 +0000
commite1faebe7b40c23811a6025ed104d3ce9882f0c3b (patch)
treeef2ffe4f958e22be92309ce3b3b23eeca3543883 /src/runtime/runtime2.go
parent733c4af41d2e89d18cfb039e0107336a4c1ec220 (diff)
downloadgo-e1faebe7b40c23811a6025ed104d3ce9882f0c3b.tar.gz
go-e1faebe7b40c23811a6025ed104d3ce9882f0c3b.zip
runtime: manage gcBgMarkWorkers with a global pool
Background mark workers perform per-P marking work. Currently each worker is assigned a P at creation time. The worker "attaches" to the P via p.gcBgMarkWorker, making itself (usually) available to findRunnableGCWorker for scheduling GC work. While running gcMarkDone, the worker "detaches" from the P (by clearing p.gcBgMarkWorker), since it may park for other reasons and should not be scheduled by findRunnableGCWorker. Unfortunately, this design is complex and difficult to reason about. We simplify things by changing the design to eliminate the hard P attachment. Rather than workers always performing work from the same P, workers perform work for whichever P they find themselves on. On park, the workers are placed in a pool of free workers, which each P's findRunnableGCWorker can use to run a worker for its P. Now if a worker parks in gcMarkDone, a P may simply use another worker from the pool to complete its own work. The P's GC worker mode is used to communicate the mode to run to the selected worker. It is also used to emit the appropriate worker EvGoStart tracepoint. This is a slight change, as this G may be preempted (e.g., in gcMarkDone). When it is rescheduled, the trace viewer will show it as a normal goroutine again. It is currently a bit difficult to connect to the original worker tracepoint, as the viewer does not display the goid for the original worker (though the data is in the trace file). Change-Id: Id7bd3a364dc18a4d2b1c99c4dc4810fae1293c1b Reviewed-on: https://go-review.googlesource.com/c/go/+/262348 Run-TryBot: Michael Pratt <mpratt@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com> Trust: Michael Pratt <mpratt@google.com>
Diffstat (limited to 'src/runtime/runtime2.go')
-rw-r--r--src/runtime/runtime2.go19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/runtime/runtime2.go b/src/runtime/runtime2.go
index 2dbc0efca3..82fedd804b 100644
--- a/src/runtime/runtime2.go
+++ b/src/runtime/runtime2.go
@@ -656,11 +656,15 @@ type p struct {
// Per-P GC state
gcAssistTime int64 // Nanoseconds in assistAlloc
gcFractionalMarkTime int64 // Nanoseconds in fractional mark worker (atomic)
- gcBgMarkWorker guintptr // (atomic)
- gcMarkWorkerMode gcMarkWorkerMode
- // gcMarkWorkerStartTime is the nanotime() at which this mark
- // worker started.
+ // gcMarkWorkerMode is the mode for the next mark worker to run in.
+ // That is, this is used to communicate with the worker goroutine
+ // selected for immediate execution by
+ // gcController.findRunnableGCWorker. When scheduling other goroutines,
+ // this field must be set to gcMarkWorkerNotWorker.
+ gcMarkWorkerMode gcMarkWorkerMode
+ // gcMarkWorkerStartTime is the nanotime() at which the most recent
+ // mark worker started.
gcMarkWorkerStartTime int64
// gcw is this P's GC work buffer cache. The work buffer is
@@ -1073,6 +1077,13 @@ var (
// must be atomic. Length may change at safe points.
timerpMask pMask
+ // Pool of GC parked background workers. Entries are type
+ // *gcBgMarkWorkerNode.
+ gcBgMarkWorkerPool lfstack
+
+ // Total number of gcBgMarkWorker goroutines. Protected by worldsema.
+ gcBgMarkWorkerCount int32
+
// Information about what cpu features are available.
// Packages outside the runtime should not use these
// as they are not an external api.