[go] runtime, cmd/compile: use preemptible memclr for large pointer-free clears

0 views
Skip to first unread message

Gopher Robot (Gerrit)

unread,
Mar 4, 2026, 2:13:43 PM (23 hours ago) Mar 4
to Muhammad Hamza, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Robert Griesemer, Go LUCI, Keith Randall, Keith Randall, Robert Griesemer, Martin Möhrmann, golang-co...@googlegroups.com

Gopher Robot submitted the change

Change information

Commit message:
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-by: Keith Randall <k...@google.com>
Reviewed-by: Keith Randall <k...@golang.org>
Auto-Submit: Keith Randall <k...@golang.org>
Reviewed-by: Robert Griesemer <g...@google.com>
Files:
  • M src/cmd/compile/internal/ssa/_gen/generic.rules
  • M src/cmd/compile/internal/ssa/rewritegeneric.go
  • M src/cmd/compile/internal/typecheck/_builtin/runtime.go
  • M src/cmd/compile/internal/typecheck/builtin.go
  • M src/cmd/compile/internal/walk/assign.go
  • M src/cmd/compile/internal/walk/range.go
  • M src/runtime/malloc.go
  • M src/runtime/memmove_test.go
Change size: M
Delta: 8 files changed, 47 insertions(+), 9 deletions(-)
Branch: refs/heads/master
Submit Requirements:
  • requirement satisfiedCode-Review: +1 by Robert Griesemer, +2 by Keith Randall, +1 by Keith Randall
  • requirement satisfiedTryBots-Pass: LUCI-TryBot-Result+1 by Go LUCI
Open in Gerrit
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: merged
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Ide14d6bcdca1f60d6ac95443acb57da9a8822538
Gerrit-Change-Number: 750480
Gerrit-PatchSet: 3
Gerrit-Owner: Muhammad Hamza <hamz...@live.co.uk>
Gerrit-Reviewer: Gopher Robot <go...@golang.org>
Gerrit-Reviewer: Keith Randall <k...@golang.org>
Gerrit-Reviewer: Keith Randall <k...@google.com>
Gerrit-Reviewer: Martin Möhrmann <moeh...@google.com>
Gerrit-Reviewer: Robert Griesemer <g...@golang.org>
Gerrit-Reviewer: Robert Griesemer <g...@google.com>
open
diffy
satisfied_requirement
Reply all
Reply to author
Forward
0 new messages