aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/mcache.go
diff options
context:
space:
mode:
authorDavid Chase <drchase@google.com>2020-11-17 19:54:31 -0500
committerDavid Chase <drchase@google.com>2021-04-30 19:41:02 +0000
commit0bbfc5c31eb4cb77f12e10c73d5462377e66b06c (patch)
tree7641ae1ee24c4e0c425ef8e023844506398de440 /src/runtime/mcache.go
parent41afd3af42bd8028a1740c30a2b745105b4063d2 (diff)
downloadgo-0bbfc5c31eb4cb77f12e10c73d5462377e66b06c.tar.gz
go-0bbfc5c31eb4cb77f12e10c73d5462377e66b06c.zip
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>
Diffstat (limited to 'src/runtime/mcache.go')
-rw-r--r--src/runtime/mcache.go9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/runtime/mcache.go b/src/runtime/mcache.go
index 097e4a5ade..a9e959109a 100644
--- a/src/runtime/mcache.go
+++ b/src/runtime/mcache.go
@@ -206,7 +206,10 @@ func (c *mcache) refill(spc spanClass) {
}
// allocLarge allocates a span for a large object.
-func (c *mcache) allocLarge(size uintptr, needzero bool, noscan bool) *mspan {
+// The boolean result indicates whether the span is known-zeroed.
+// If it did not need to be zeroed, it may not have been zeroed;
+// but if it came directly from the OS, it is already zeroed.
+func (c *mcache) allocLarge(size uintptr, needzero bool, noscan bool) (*mspan, bool) {
if size+_PageSize < size {
throw("out of memory")
}
@@ -221,7 +224,7 @@ func (c *mcache) allocLarge(size uintptr, needzero bool, noscan bool) *mspan {
deductSweepCredit(npages*_PageSize, npages)
spc := makeSpanClass(0, noscan)
- s := mheap_.alloc(npages, spc, needzero)
+ s, isZeroed := mheap_.alloc(npages, spc, needzero)
if s == nil {
throw("out of memory")
}
@@ -245,7 +248,7 @@ func (c *mcache) allocLarge(size uintptr, needzero bool, noscan bool) *mspan {
mheap_.central[spc].mcentral.fullSwept(mheap_.sweepgen).push(s)
s.limit = s.base() + size
heapBitsForAddr(s.base()).initSpan(s)
- return s
+ return s, isZeroed
}
func (c *mcache) releaseAll() {