]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: remove atomic store requirement on pageAlloc.chunks
authorMichael Anthony Knyszek <mknyszek@google.com>
Wed, 7 Sep 2022 20:03:25 +0000 (20:03 +0000)
committerGopher Robot <gobot@golang.org>
Thu, 8 Sep 2022 16:05:56 +0000 (16:05 +0000)
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>
src/runtime/mpagealloc.go

index 5661c375011c60df7412fb07cc21364325cf6967..83df7c5150e5901f39290a4279223df60b670a1c 100644 (file)
@@ -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)
        }