]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: simplify mSpan_Sweep
authorAustin Clements <austin@google.com>
Tue, 21 Jul 2015 15:31:44 +0000 (11:31 -0400)
committerAustin Clements <austin@google.com>
Mon, 14 Sep 2015 18:29:58 +0000 (18:29 +0000)
This is a cleanup following cc8f544, which was a minimal change to fix
issue #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 <rlh@golang.org>
src/runtime/mgcsweep.go

index eaa446323be233990c287ed710e7ac16341b90f8..d9eb58fdf7b37ebdf9a6f0babab19b9eb4863f00 100644 (file)
@@ -235,9 +235,6 @@ func mSpan_Sweep(s *mspan, preserve bool) bool {
                        heapBitsForSpan(p).initSpan(s.layout())
                        s.needzero = 1
 
-                       // important to set sweepgen before returning it to heap
-                       atomicstore(&s.sweepgen, sweepgen)
-
                        // Free the span after heapBitsSweepSpan
                        // returns, since it's not done with the span.
                        freeToHeap = true
@@ -264,10 +261,7 @@ func mSpan_Sweep(s *mspan, preserve bool) bool {
        // But we need to set it before we make the span available for allocation
        // (return it to heap or mcentral), because allocation code assumes that a
        // span is already swept if available for allocation.
-       //
-       // TODO(austin): Clean this up by consolidating atomicstore in
-       // large span path above with this.
-       if !freeToHeap && nfree == 0 {
+       if freeToHeap || nfree == 0 {
                // The span must be in our exclusive ownership until we update sweepgen,
                // check for potential races.
                if s.state != mSpanInUse || s.sweepgen != sweepgen-1 {