mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
runtime: break up large calls to memclrNoHeapPointers to allow preemption
If something "huge" is allocated, and the zeroing is trivial (no pointers involved) then zero it by chunks in a loop so that preemption can occur, not all in a single non-preemptible call. Benchmarking suggests that 256K is the best chunk size. Updates #42642. Change-Id: I94015e467eaa098c59870e479d6d83bc88efbfb4 Reviewed-on: https://go-review.googlesource.com/c/go/+/270943 Trust: David Chase <drchase@google.com> Run-TryBot: David Chase <drchase@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com>
This commit is contained in:
parent
41afd3af42
commit
0bbfc5c31e
4 changed files with 51 additions and 7 deletions
|
|
@ -897,7 +897,8 @@ func (s spanAllocType) manual() bool {
|
|||
// spanclass indicates the span's size class and scannability.
|
||||
//
|
||||
// If needzero is true, the memory for the returned span will be zeroed.
|
||||
func (h *mheap) alloc(npages uintptr, spanclass spanClass, needzero bool) *mspan {
|
||||
// The boolean returned indicates whether the returned span is zeroed.
|
||||
func (h *mheap) alloc(npages uintptr, spanclass spanClass, needzero bool) (*mspan, bool) {
|
||||
// Don't do any operations that lock the heap on the G stack.
|
||||
// It might trigger stack growth, and the stack growth code needs
|
||||
// to be able to allocate heap.
|
||||
|
|
@ -911,13 +912,15 @@ func (h *mheap) alloc(npages uintptr, spanclass spanClass, needzero bool) *mspan
|
|||
s = h.allocSpan(npages, spanAllocHeap, spanclass)
|
||||
})
|
||||
|
||||
isZeroed := s.needzero == 0
|
||||
if s != nil {
|
||||
if needzero && s.needzero != 0 {
|
||||
memclrNoHeapPointers(unsafe.Pointer(s.base()), s.npages<<_PageShift)
|
||||
isZeroed = true
|
||||
}
|
||||
s.needzero = 0
|
||||
}
|
||||
return s
|
||||
return s, isZeroed
|
||||
}
|
||||
|
||||
// allocManual allocates a manually-managed span of npage pages.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue