mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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>
This commit is contained in:
parent
d3b35a4242
commit
a25a34abe9
2 changed files with 8 additions and 7 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue