1
0
mirror of https://github.com/golang/go synced 2024-11-05 15:06:09 -07:00

runtime: remove atomic store requirement on pageAlloc.chunks

pageAlloc.chunks used to require an atomic store when growing the heap
because the scavenger would look at the list without locking the heap
lock. However, the scavenger doesn't do that anymore, and it looks like
nothing really does at all.

This change updates the comment and makes the store non-atomic.

Change-Id: Ib452d147861060f9f6e74e2d98ee111cf89ce8f5
Reviewed-on: https://go-review.googlesource.com/c/go/+/429219
Auto-Submit: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Keith Randall <khr@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
Michael Anthony Knyszek 2022-09-07 20:03:25 +00:00 committed by Gopher Robot
parent cd8aa40149
commit 1c59199c91

View File

@ -393,14 +393,13 @@ func (p *pageAlloc) grow(base, size uintptr) {
for c := chunkIndex(base); c < chunkIndex(limit); c++ { for c := chunkIndex(base); c < chunkIndex(limit); c++ {
if p.chunks[c.l1()] == nil { if p.chunks[c.l1()] == nil {
// Create the necessary l2 entry. // Create the necessary l2 entry.
//
// Store it atomically to avoid races with readers which
// don't acquire the heap lock.
r := sysAlloc(unsafe.Sizeof(*p.chunks[0]), p.sysStat) r := sysAlloc(unsafe.Sizeof(*p.chunks[0]), p.sysStat)
if r == nil { if r == nil {
throw("pageAlloc: out of memory") throw("pageAlloc: out of memory")
} }
atomic.StorepNoWB(unsafe.Pointer(&p.chunks[c.l1()]), r) // Store the new chunk block but avoid a write barrier.
// grow is used in call chains that disallow write barriers.
*(*uintptr)(unsafe.Pointer(&p.chunks[c.l1()])) = uintptr(r)
} }
p.chunkOf(c).scavenged.setRange(0, pallocChunkPages) p.chunkOf(c).scavenged.setRange(0, pallocChunkPages)
} }