From 3590d9ce695baa7535537e3d1404de52bf94fae5 Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Thu, 24 Jul 2014 14:37:34 -0700 Subject: [PATCH] runtime: set sweepgen atomically before updating span state 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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pkg/runtime/mheap.c b/src/pkg/runtime/mheap.c index 7ae5a399b3..3a5981d3c7 100644 --- a/src/pkg/runtime/mheap.c +++ b/src/pkg/runtime/mheap.c @@ -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<types.compression = MTypes_Empty; - s->sweepgen = h->sweepgen; // update stats, sweep lists if(large) { -- 2.48.1