aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/malloc.go
diff options
context:
space:
mode:
author“Muhammad <hamza3256@live.co.uk>2026-03-01 23:53:03 +0000
committerGopher Robot <gobot@golang.org>2026-03-04 11:13:38 -0800
commit50126a8e44f76134349edf5ba3cc94efabc61c80 (patch)
tree1b4110fadab2962c3250ce844a0e2e8f6898e003 /src/runtime/malloc.go
parent7aeb2f7e285006ad68789581dedf2b35ba444dbf (diff)
downloadgo-50126a8e44f76134349edf5ba3cc94efabc61c80.tar.xz
runtime, cmd/compile: use preemptible memclr for large pointer-free clears
Large memory clearing operations (via clear() or large slice allocation) currently use non-preemptible assembly loops. This blocks the Garbage Collector from performing a Stop The World (STW) event, leading to significant tail latency or even indefinite hangs in tight loops. This change introduces memclrNoHeapPointersPreemptible, which chunks clears into 256KB blocks with preemption checks. The compiler's walk phase is updated to emit this call for large pointer-free clears. To prevent regressions, SSA rewrite rules are added to ensure that constant-size clears (which are common and small) continue to be inlined into OpZero assembly. Benchmarks on darwin/arm64: - STW with 50MB clear: Improved from 'Hung' to ~500µs max pause. - Small clears (5-64B): No measurable regression. - Large clears (1M-64M): No measurable regression. Fixes #69327 Change-Id: Ide14d6bcdca1f60d6ac95443acb57da9a8822538 Reviewed-on: https://go-review.googlesource.com/c/go/+/750480 Reviewed-by: Keith Randall <khr@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@golang.org> Auto-Submit: Keith Randall <khr@golang.org> Reviewed-by: Robert Griesemer <gri@google.com>
Diffstat (limited to 'src/runtime/malloc.go')
-rw-r--r--src/runtime/malloc.go9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/runtime/malloc.go b/src/runtime/malloc.go
index c08bc7574b..2144ea602a 100644
--- a/src/runtime/malloc.go
+++ b/src/runtime/malloc.go
@@ -2202,6 +2202,15 @@ func memclrNoHeapPointersChunked(size uintptr, x unsafe.Pointer) {
}
}
+// memclrNoHeapPointersPreemptible is the compiler-callable entry point
+// for clearing large buffers with preemption support. It has the same
+// signature as memclrNoHeapPointers so the compiler can emit calls to it
+// directly. It delegates to memclrNoHeapPointersChunked which splits the
+// work into 256KB chunks with preemption checks between them.
+func memclrNoHeapPointersPreemptible(ptr unsafe.Pointer, n uintptr) {
+ memclrNoHeapPointersChunked(n, ptr)
+}
+
// implementation of new builtin
// compiler (both frontend and SSA backend) knows the signature
// of this function.