diff options
author | Austin Clements <austin@google.com> | 2021-04-06 19:25:28 -0400 |
---|---|---|
committer | Austin Clements <austin@google.com> | 2021-04-12 19:22:52 +0000 |
commit | 1b736b3c19375f6ebd0d834c02316fb13700be27 (patch) | |
tree | 82814077b9ad2d5476b28920febd14a45b6ac56d /src/runtime/mgc.go | |
parent | a25a77aed2d76b0aebff8892477f27283398a932 (diff) | |
download | go-1b736b3c19375f6ebd0d834c02316fb13700be27.tar.gz go-1b736b3c19375f6ebd0d834c02316fb13700be27.zip |
runtime: consolidate "is sweep done" conditions
The runtime currently has two different notions of sweep completion:
1. All spans are either swept or have begun sweeping.
2. The sweeper has *finished* sweeping all spans.
Having both is confusing (it doesn't help that the documentation is
often unclear or wrong). Condition 2 is stronger and the theoretical
slight optimization that condition 1 could impact is never actually
useful. Hence, this CL consolidates both conditions down to condition 2.
Updates #45315.
Change-Id: I55c84d767d74eb31a004a5619eaba2e351162332
Reviewed-on: https://go-review.googlesource.com/c/go/+/307916
Trust: Austin Clements <austin@google.com>
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Diffstat (limited to 'src/runtime/mgc.go')
-rw-r--r-- | src/runtime/mgc.go | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/runtime/mgc.go b/src/runtime/mgc.go index 8c1ff20936..25bf4a226b 100644 --- a/src/runtime/mgc.go +++ b/src/runtime/mgc.go @@ -175,7 +175,7 @@ func gcinit() { } // No sweep on the first cycle. - mheap_.sweepdone = 1 + mheap_.sweepDrained = 1 // Set a reasonable initial GC trigger. memstats.triggerRatio = 7 / 8.0 @@ -1187,7 +1187,7 @@ func GC() { // First, wait for sweeping to finish. (We know there are no // more spans on the sweep queue, but we may be concurrently // sweeping spans, so we have to wait.) - for atomic.Load(&work.cycles) == n+1 && atomic.Load(&mheap_.sweepers) != 0 { + for atomic.Load(&work.cycles) == n+1 && !isSweepDone() { Gosched() } @@ -2192,7 +2192,7 @@ func gcSweep(mode gcMode) { lock(&mheap_.lock) mheap_.sweepgen += 2 - mheap_.sweepdone = 0 + mheap_.sweepDrained = 0 mheap_.pagesSwept = 0 mheap_.sweepArenas = mheap_.allArenas mheap_.reclaimIndex = 0 |