diff options
| author | cuiweixie <cuiweixie@gmail.com> | 2022-08-25 11:10:52 +0800 |
|---|---|---|
| committer | Michael Pratt <mpratt@google.com> | 2022-08-31 15:30:26 +0000 |
| commit | a25a34abe986bd78ab9a543d2a96cbce427a4f3c (patch) | |
| tree | 238e1d6ed697bf15de64bf1b6b9707d0c8b340cd /src/runtime | |
| parent | d3b35a42429cec6d57d0d1e167d9443d0fbd6e97 (diff) | |
| download | go-a25a34abe986bd78ab9a543d2a96cbce427a4f3c.tar.xz | |
runtime: convert mcache.flushGen to atomic type
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>
Diffstat (limited to 'src/runtime')
| -rw-r--r-- | src/runtime/mcache.go | 13 | ||||
| -rw-r--r-- | src/runtime/mgc.go | 2 |
2 files changed, 8 insertions, 7 deletions
diff --git a/src/runtime/mcache.go b/src/runtime/mcache.go index e01a99bd6e..ba45034943 100644 --- a/src/runtime/mcache.go +++ b/src/runtime/mcache.go @@ -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 } diff --git a/src/runtime/mgc.go b/src/runtime/mgc.go index 8021a56b9a..3243a15b4d 100644 --- a/src/runtime/mgc.go +++ b/src/runtime/mgc.go @@ -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") } |
