aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/runtime1.go
diff options
context:
space:
mode:
authorKeith Randall <khr@golang.org>2021-08-28 15:50:52 -0700
committerKeith Randall <khr@google.com>2022-05-12 22:32:42 +0000
commit016d7552138077741a9c3fdadc73c0179f5d3ff7 (patch)
treecfe978bcbb00bb7e67a610af16fe5706cd181723 /src/runtime/runtime1.go
parentda0a6f4b57fc9eb4779c295bc9620c5ed271a641 (diff)
downloadgo-016d7552138077741a9c3fdadc73c0179f5d3ff7.tar.xz
runtime: measure stack usage; start stacks larger if needed
Measure the average stack size used by goroutines at every GC. When starting a new goroutine, allocate an initial goroutine stack of that average size. Intuition is that we'll waste at most 2x in stack space because only half the goroutines can be below average. In turn, we avoid some of the early stack growth / copying needed in the average case. More details in the design doc at: https://docs.google.com/document/d/1YDlGIdVTPnmUiTAavlZxBI1d9pwGQgZT7IKFKlIXohQ/edit?usp=sharing name old time/op new time/op delta Issue18138 95.3µs ± 0% 67.3µs ±13% -29.35% (p=0.000 n=9+10) Fixes #18138 Change-Id: Iba34d22ed04279da7e718bbd569bbf2734922eaa Reviewed-on: https://go-review.googlesource.com/c/go/+/345889 Run-TryBot: Keith Randall <khr@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Keith Randall <khr@google.com>
Diffstat (limited to 'src/runtime/runtime1.go')
-rw-r--r--src/runtime/runtime1.go3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/runtime/runtime1.go b/src/runtime/runtime1.go
index 62ecbdf59b..e307901fc2 100644
--- a/src/runtime/runtime1.go
+++ b/src/runtime/runtime1.go
@@ -321,6 +321,7 @@ var debug struct {
tracebackancestors int32
asyncpreemptoff int32
harddecommit int32
+ adaptivestackstart int32
// debug.malloc is used as a combined debug check
// in the malloc function and should be set
@@ -351,12 +352,14 @@ var dbgvars = []dbgVar{
{"asyncpreemptoff", &debug.asyncpreemptoff},
{"inittrace", &debug.inittrace},
{"harddecommit", &debug.harddecommit},
+ {"adaptivestackstart", &debug.adaptivestackstart},
}
func parsedebugvars() {
// defaults
debug.cgocheck = 1
debug.invalidptr = 1
+ debug.adaptivestackstart = 1 // go119 - set this to 0 to turn larger initial goroutine stacks off
if GOOS == "linux" {
// On Linux, MADV_FREE is faster than MADV_DONTNEED,
// but doesn't affect many of the statistics that