runtime: remove write barriers from traceRegionAlloc

The memory managed by traceRegionAlloc is off-heap by design. However,
stores to the "current" pointer currently have a write barrier. This CL
switches the stores to their write barrier-free equivalents. If the
traceMap data structure gets extended and used elsewhere in the future,
such as for runtime lock contention profiling, we might not have a P and
thus won't be able to use a write barrier in this code. But for now this
is just a cleanup and minor efficiency improvment.

Change-Id: I3081c9d48a8471fd87534e5c4951823d6a6a6964
Reviewed-on: https://go-review.googlesource.com/c/go/+/748120
Reviewed-by: David Chase <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
This commit is contained in:
Nick Ripley
2026-02-23 15:46:04 +00:00
parent fe08017303
commit 04772f022a

View File

@@ -92,8 +92,8 @@ func (a *traceRegionAlloc) alloc(n uintptr) *notInHeap {
block.off.Store(n)
x = (*notInHeap)(unsafe.Pointer(&block.data[0]))
// Publish the new block.
a.current.Store(unsafe.Pointer(block))
// Publish the new block. No write barrier as the memory is off heap.
a.current.StoreNoWB(unsafe.Pointer(block))
unlock(&a.lock)
})
return x
@@ -112,7 +112,7 @@ func (a *traceRegionAlloc) drop() {
}
if current := a.current.Load(); current != nil {
sysFree(current, unsafe.Sizeof(traceRegionAllocBlock{}), &memstats.other_sys)
a.current.Store(nil)
a.current.StoreNoWB(nil)
}
a.dropping.Store(false)
}