From 16018b05ae226e7a99f166bded7f939c5b0c4a98 Mon Sep 17 00:00:00 2001 From: Michael Pratt Date: Fri, 20 Mar 2026 17:49:14 -0400 Subject: Revert "runtime: fix memclrNoHeapPointersPreemptible" This reverts CL 756122. Reason: Adding preemptible memclrNoHeapPointers exposes existing unsafe use of notInHeapSlice, causing crashes. Revert the memclr stack until the underlying issue is fixed. For #78254. Change-Id: I8a234d1a6dddf70d9aa5ecda1ac8bb25deb08248 Reviewed-on: https://go-review.googlesource.com/c/go/+/757342 Reviewed-by: Keith Randall LUCI-TryBot-Result: Go LUCI Reviewed-by: Keith Randall --- src/runtime/malloc.go | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) (limited to 'src/runtime/malloc.go') diff --git a/src/runtime/malloc.go b/src/runtime/malloc.go index 44b4b3bc57..2144ea602a 100644 --- a/src/runtime/malloc.go +++ b/src/runtime/malloc.go @@ -2184,27 +2184,22 @@ func reusableSize(size uintptr) bool { // Use this with care; if the data being cleared is tagged to contain // pointers, this allows the GC to run before it is all cleared. func memclrNoHeapPointersChunked(size uintptr, x unsafe.Pointer) { - if getg().preempt { - // TODO: no need for this, except to test that - // the preemption point is ok for small zeroings. - // (The pre-CL-756122 allowed preemption in this case, - // which is probably why we noticed 78081 at all.) - // Remove once we think 78081 is fixed. - // may hold locks, e.g., profiling - goschedguarded() - } + v := uintptr(x) // got this from benchmarking. 128k is too small, 512k is too large. const chunkBytes = 256 * 1024 - for size > chunkBytes { - memclrNoHeapPointers(x, chunkBytes) - x = add(x, chunkBytes) - size -= chunkBytes + vsize := v + size + for voff := v; voff < vsize; voff = voff + chunkBytes { if getg().preempt { // may hold locks, e.g., profiling goschedguarded() } + // clear min(avail, lump) bytes + n := vsize - voff + if n > chunkBytes { + n = chunkBytes + } + memclrNoHeapPointers(unsafe.Pointer(voff), n) } - memclrNoHeapPointers(x, size) } // memclrNoHeapPointersPreemptible is the compiler-callable entry point -- cgit v1.3-6-g1900