]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: set sweepgen atomically before updating span state
authorKeith Randall <khr@golang.org>
Thu, 24 Jul 2014 21:37:34 +0000 (14:37 -0700)
committerKeith Randall <khr@golang.org>
Thu, 24 Jul 2014 21:37:34 +0000 (14:37 -0700)
Sweepone may be running while a new span is allocating.  It
must not see the state updated while the sweepgen is unset.

Fixes #8399

LGTM=dvyukov
R=golang-codereviews, dvyukov
CC=golang-codereviews
https://golang.org/cl/118050043

src/pkg/runtime/mheap.c

index 7ae5a399b3564bc1e298f4457d46bfe15bfa29ef..3a5981d3c7eb7fe338aff5b97b234a08132ec8cd 100644 (file)
@@ -189,13 +189,13 @@ mheap_alloc(MHeap *h, uintptr npage, int32 sizeclass, bool large)
        if(s != nil) {
                // Record span info, because gc needs to be
                // able to map interior pointer to containing span.
+               runtime·atomicstore(&s->sweepgen, h->sweepgen);
                s->state = MSpanInUse;
                s->freelist = nil;
                s->ref = 0;
                s->sizeclass = sizeclass;
                s->elemsize = (sizeclass==0 ? s->npages<<PageShift : runtime·class_to_size[sizeclass]);
                s->types.compression = MTypes_Empty;
-               s->sweepgen = h->sweepgen;
 
                // update stats, sweep lists
                if(large) {