]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: convert mcache.flushGen to atomic type
authorcuiweixie <cuiweixie@gmail.com>
Thu, 25 Aug 2022 03:10:52 +0000 (11:10 +0800)
committerMichael Pratt <mpratt@google.com>
Wed, 31 Aug 2022 15:30:26 +0000 (15:30 +0000)
For #53821

Change-Id: I90ab52a45b7fb6b9e3ff1d6ea97251549306c7aa
Reviewed-on: https://go-review.googlesource.com/c/go/+/425435
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Run-TryBot: xie cui <523516579@qq.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/runtime/mcache.go
src/runtime/mgc.go

index e01a99bd6ef53299cf576385de4683e276bf83c5..ba45034943fae999afa222cc3b251b71ebfb9a81 100644 (file)
@@ -50,7 +50,7 @@ type mcache struct {
        // was last flushed. If flushGen != mheap_.sweepgen, the spans
        // in this mcache are stale and need to the flushed so they
        // can be swept. This is done in acquirep.
-       flushGen uint32
+       flushGen atomic.Uint32
 }
 
 // A gclink is a node in a linked list of blocks, like mlink,
@@ -87,7 +87,7 @@ func allocmcache() *mcache {
        systemstack(func() {
                lock(&mheap_.lock)
                c = (*mcache)(mheap_.cachealloc.alloc())
-               c.flushGen = mheap_.sweepgen
+               c.flushGen.Store(mheap_.sweepgen)
                unlock(&mheap_.lock)
        })
        for i := range c.alloc {
@@ -318,13 +318,14 @@ func (c *mcache) prepareForSweep() {
        // allocate-black. However, with this approach it's difficult
        // to avoid spilling mark bits into the *next* GC cycle.
        sg := mheap_.sweepgen
-       if c.flushGen == sg {
+       flushGen := c.flushGen.Load()
+       if flushGen == sg {
                return
-       } else if c.flushGen != sg-2 {
-               println("bad flushGen", c.flushGen, "in prepareForSweep; sweepgen", sg)
+       } else if flushGen != sg-2 {
+               println("bad flushGen", flushGen, "in prepareForSweep; sweepgen", sg)
                throw("bad flushGen")
        }
        c.releaseAll()
        stackcache_clear(c)
-       atomic.Store(&c.flushGen, mheap_.sweepgen) // Synchronizes with gcStart
+       c.flushGen.Store(mheap_.sweepgen) // Synchronizes with gcStart
 }
index 8021a56b9a72fd19a1290fedbce27005b35b531a..3243a15b4d1e8589f4882094792fb8760337db26 100644 (file)
@@ -636,7 +636,7 @@ func gcStart(trigger gcTrigger) {
 
        // Check that all Ps have finished deferred mcache flushes.
        for _, p := range allp {
-               if fg := atomic.Load(&p.mcache.flushGen); fg != mheap_.sweepgen {
+               if fg := p.mcache.flushGen.Load(); fg != mheap_.sweepgen {
                        println("runtime: p", p.id, "flushGen", fg, "!= sweepgen", mheap_.sweepgen)
                        throw("p mcache not flushed")
                }