1
0
mirror of https://github.com/golang/go synced 2024-09-30 02:14:29 -06:00

runtime: simplify mSpan_Sweep

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>
This commit is contained in:
Austin Clements 2015-07-21 11:31:44 -04:00
parent 572f08a064
commit 70462f90ec

View 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 {