-
- Downloads
runtime: schedule cleanups across multiple goroutines
This change splits the finalizer and cleanup queues and implements a new lock-free blocking queue for cleanups. The basic design is as follows: The cleanup queue is organized in fixed-sized blocks. Individual cleanup functions are queued, but only whole blocks are dequeued. Enqueuing cleanups places them in P-local cleanup blocks. These are flushed to the full list as they get full. Cleanups can only be enqueued by an active sweeper. Dequeuing cleanups always dequeues entire blocks from the full list. Cleanup blocks can be dequeued and executed at any time. The very last active sweeper in the sweep phase is responsible for flushing all local cleanup blocks to the full list. It can do this without any synchronization because the next GC can't start yet, so we can be very certain that nobody else will be accessing the local blocks. Cleanup blocks are stored off-heap because the need to be allocated by the sweeper, which is called from heap allocation paths. As a result, the GC treats cleanup blocks as roots, just like finalizer blocks. Flushes to the full list signal to the scheduler that cleanup goroutines should be awoken. Every time the scheduler goes to wake up a cleanup goroutine and there were more signals than goroutines to wake, it then forwards this signal to runtime.AddCleanup, so that it creates another goroutine the next time it is called, up to gomaxprocs goroutines. The signals here are a little convoluted, but exist because the sweeper and the scheduler cannot safely create new goroutines. For #71772. For #71825. Change-Id: Ie839fde2b67e1b79ac1426be0ea29a8d923a62cc Reviewed-on: https://go-review.googlesource.com/c/go/+/650697 Reviewed-by:Michael Pratt <mpratt@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Michael Knyszek <mknyszek@google.com>
Showing
- src/cmd/internal/objabi/funcid.go 22 additions, 21 deletionssrc/cmd/internal/objabi/funcid.go
- src/internal/abi/symtab.go 2 additions, 1 deletionsrc/internal/abi/symtab.go
- src/runtime/abi_test.go 3 additions, 0 deletionssrc/runtime/abi_test.go
- src/runtime/crash_test.go 75 additions, 69 deletionssrc/runtime/crash_test.go
- src/runtime/export_test.go 4 additions, 0 deletionssrc/runtime/export_test.go
- src/runtime/lockrank.go 29 additions, 26 deletionssrc/runtime/lockrank.go
- src/runtime/mcleanup.go 432 additions, 2 deletionssrc/runtime/mcleanup.go
- src/runtime/mcleanup_test.go 40 additions, 0 deletionssrc/runtime/mcleanup_test.go
- src/runtime/mfinal.go 4 additions, 22 deletionssrc/runtime/mfinal.go
- src/runtime/mgc.go 6 additions, 0 deletionssrc/runtime/mgc.go
- src/runtime/mgcmark.go 9 additions, 2 deletionssrc/runtime/mgcmark.go
- src/runtime/mgcsweep.go 2 additions, 0 deletionssrc/runtime/mgcsweep.go
- src/runtime/mheap.go 1 addition, 1 deletionsrc/runtime/mheap.go
- src/runtime/mklockrank.go 2 additions, 0 deletionssrc/runtime/mklockrank.go
- src/runtime/mprof.go 4 additions, 13 deletionssrc/runtime/mprof.go
- src/runtime/pprof/pprof_test.go 6 additions, 6 deletionssrc/runtime/pprof/pprof_test.go
- src/runtime/proc.go 7 additions, 0 deletionssrc/runtime/proc.go
- src/runtime/runtime2.go 30 additions, 24 deletionssrc/runtime/runtime2.go
- src/runtime/testdata/testprog/finalizer_deadlock.go 11 additions, 5 deletionssrc/runtime/testdata/testprog/finalizer_deadlock.go
- src/runtime/traceback.go 17 additions, 7 deletionssrc/runtime/traceback.go
Loading
Please register or sign in to comment