diff options
| author | Keith Randall <khr@golang.org> | 2020-03-27 11:17:00 -0700 |
|---|---|---|
| committer | Keith Randall <khr@golang.org> | 2020-05-07 18:31:25 +0000 |
| commit | b1760f3a27ed9a0e99599bf028b2b48403f8c3fc (patch) | |
| tree | 46be2f377f2455a620195111f428f3be5ae501ce /src | |
| parent | 6ed4661807b219781d1aa452b7f210e21ad1974b (diff) | |
| download | go-git-b1760f3a27ed9a0e99599bf028b2b48403f8c3fc.tar.gz | |
runtime: grow stack more than 2x if the new frame is large
We might as well grow the stack at least as large as we'll need for
the frame that is calling morestack. It doesn't help with the
lots-of-small-frames case, but it may help a bit with the
few-big-frames case.
Update #18138
Change-Id: I1f49c97706a70e20b30433cbec99a7901528ea52
Reviewed-on: https://go-review.googlesource.com/c/go/+/225800
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/runtime/stack.go | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/runtime/stack.go b/src/runtime/stack.go index eeac66d1ce..6e1f07bf73 100644 --- a/src/runtime/stack.go +++ b/src/runtime/stack.go @@ -1033,6 +1033,17 @@ func newstack() { // Allocate a bigger segment and move the stack. oldsize := gp.stack.hi - gp.stack.lo newsize := oldsize * 2 + + // Make sure we grow at least as much as needed to fit the new frame. + // (This is just an optimization - the caller of morestack will + // recheck the bounds on return.) + if f := findfunc(gp.sched.pc); f.valid() { + max := uintptr(funcMaxSPDelta(f)) + for newsize-oldsize < max+_StackGuard { + newsize *= 2 + } + } + if newsize > maxstacksize { print("runtime: goroutine stack exceeds ", maxstacksize, "-byte limit\n") print("runtime: sp=", hex(sp), " stack=[", hex(gp.stack.lo), ", ", hex(gp.stack.hi), "]\n") |
