Skip to content

Commit 70462f9

Browse files
committed
runtime: simplify mSpan_Sweep
This is a cleanup following cc8f544, which was a minimal change to fix issue golang#11617. This consolidates the two places in mSpan_Sweep that update sweepgen. Previously this was necessary because sweepgen must be updated before freeing the span, but we freed large spans early. Now we free large spans later, so there's no need to duplicate the sweepgen update. This also means large spans can take advantage of the sweepgen sanity checking performed for other spans. Change-Id: I23b79dbd9ec81d08575cd307cdc0fa6b20831768 Reviewed-on: https://go-review.googlesource.com/12451 Reviewed-by: Rick Hudson <[email protected]>
1 parent 572f08a commit 70462f9

File tree

1 file changed

+1
-7
lines changed

1 file changed

+1
-7
lines changed

src/runtime/mgcsweep.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,6 @@ func mSpan_Sweep(s *mspan, preserve bool) bool {
235235
heapBitsForSpan(p).initSpan(s.layout())
236236
s.needzero = 1
237237

238-
// important to set sweepgen before returning it to heap
239-
atomicstore(&s.sweepgen, sweepgen)
240-
241238
// Free the span after heapBitsSweepSpan
242239
// returns, since it's not done with the span.
243240
freeToHeap = true
@@ -264,10 +261,7 @@ func mSpan_Sweep(s *mspan, preserve bool) bool {
264261
// But we need to set it before we make the span available for allocation
265262
// (return it to heap or mcentral), because allocation code assumes that a
266263
// span is already swept if available for allocation.
267-
//
268-
// TODO(austin): Clean this up by consolidating atomicstore in
269-
// large span path above with this.
270-
if !freeToHeap && nfree == 0 {
264+
if freeToHeap || nfree == 0 {
271265
// The span must be in our exclusive ownership until we update sweepgen,
272266
// check for potential races.
273267
if s.state != mSpanInUse || s.sweepgen != sweepgen-1 {

0 commit comments

Comments
 (0)