From: Michael Anthony Knyszek Date: Wed, 9 Oct 2024 17:38:49 +0000 (+0000) Subject: runtime: execute publicationBarrier in noscan case for delayed zeroing X-Git-Tag: go1.24rc1~665 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=acd072a0784863dfbdf32da9d770753722270a26;p=gostls13.git runtime: execute publicationBarrier in noscan case for delayed zeroing This is a peace-of-mind change to make sure that delayed-zeroed memory (in the large alloc case) is globally visible from the moment the allocation is published back to the caller. The way it's written right now is good enough for the garbage collector (we already have a publication barrier for a nil span.largeType, so the GC will ignore the noscan span) but this might matter for user code on weak memory architectures. Change-Id: I06ac9b95863074e5f09382629083b19bfa87fdb8 Reviewed-on: https://go-review.googlesource.com/c/go/+/619036 Reviewed-by: Keith Randall Auto-Submit: Michael Knyszek LUCI-TryBot-Result: Go LUCI Reviewed-by: Keith Randall --- diff --git a/src/runtime/malloc.go b/src/runtime/malloc.go index 3416b599f9..83f7f64f6f 100644 --- a/src/runtime/malloc.go +++ b/src/runtime/malloc.go @@ -1581,14 +1581,13 @@ func mallocgcLarge(size uintptr, typ *_type, needzero bool) (unsafe.Pointer, uin memclrNoHeapPointersChunked(size, x) // This is a possible preemption point: see #47302 // Finish storing the type information for this case. + mp := acquirem() if !noscan { - mp := acquirem() getMCache(mp).scanAlloc += heapSetTypeLarge(uintptr(x), size, typ, span) - - // Publish the type information with the zeroed memory. - publicationBarrier() - releasem(mp) } + // Publish the object with the now-zeroed memory. + publicationBarrier() + releasem(mp) } return x, size }