]> Cypherpunks repositories - gostls13.git/commit
runtime: eliminate global span queue [green tea]
authorMichael Anthony Knyszek <mknyszek@google.com>
Fri, 15 Aug 2025 17:09:05 +0000 (17:09 +0000)
committerMichael Knyszek <mknyszek@google.com>
Tue, 23 Sep 2025 23:36:08 +0000 (16:36 -0700)
commitd7a38adf4c81f0fa83203e37844192182b22680a
tree30b912472124b6a67bee535a2d3fbc2b410f819f
parent7bc1935db55c9d182617aba074f048f9c7573680
runtime: eliminate global span queue [green tea]

This change removes the locked global span queue and replaces the
fixed-size local span queue with a variable-sized local span queue. The
variable-sized local span queue grows as needed to accomodate local
work. With no global span queue either, GC workers balance work amongst
themselves by stealing from each other.

The new variable-sized local span queues are inspired by the P-local
deque underlying sync.Pool. Unlike the sync.Pool deque, however, both
the owning P and stealing Ps take spans from the tail, making this
incarnation a strict queue, not a deque. This is intentional, since we
want a queue-like order to encourage objects to accumulate on each span.

These variable-sized local span queues are crucial to mark termination,
just like the global span queue was. To avoid hitting the ragged barrier
too often, we must check whether any Ps have any spans on their
variable-sized local span queues. We maintain a per-P atomic bitmask
(another pMask) that contains this state. We can also use this to speed
up stealing by skipping Ps that don't have any local spans.

The variable-sized local span queues are slower than the old fixed-size
local span queues because of the additional indirection, so this change
adds a non-atomic local fixed-size queue. This risks getting work stuck
on it, so, similarly to how workbufs work, each worker will occasionally
dump some spans onto its local variable-sized queue. This scales much
more nicely than dumping to a global queue, but is still visible to all
other Ps.

For #73581.

Change-Id: I814f54d9c3cc7fa7896167746e9823f50943ac22
Reviewed-on: https://go-review.googlesource.com/c/go/+/700496
Reviewed-by: Michael Pratt <mpratt@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
src/runtime/export_test.go
src/runtime/gc_test.go
src/runtime/mgc.go
src/runtime/mgcmark.go
src/runtime/mgcmark_greenteagc.go
src/runtime/mgcmark_nogreenteagc.go
src/runtime/mgcpacer.go
src/runtime/mgcsweep.go
src/runtime/mgcwork.go
src/runtime/mheap.go
src/runtime/proc.go