From 1c59199c919419293075ac9c93b27b033e2733f9 Mon Sep 17 00:00:00 2001 From: Michael Anthony Knyszek Date: Wed, 7 Sep 2022 20:03:25 +0000 Subject: [PATCH] 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 Reviewed-by: Keith Randall TryBot-Result: Gopher Robot Run-TryBot: Michael Knyszek Reviewed-by: Keith Randall --- src/runtime/mpagealloc.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/runtime/mpagealloc.go b/src/runtime/mpagealloc.go index 5661c37501..83df7c5150 100644 --- a/src/runtime/mpagealloc.go +++ b/src/runtime/mpagealloc.go @@ -393,14 +393,13 @@ func (p *pageAlloc) grow(base, size uintptr) { for c := chunkIndex(base); c < chunkIndex(limit); c++ { if p.chunks[c.l1()] == nil { // 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) if r == nil { 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) }