diff options
author | go101 <tapir.liu@gmail.com> | 2021-07-02 08:01:20 +0000 |
---|---|---|
committer | Keith Randall <khr@golang.org> | 2021-07-02 20:11:05 +0000 |
commit | 287c5e8066396e953254d7980a80ec082edf11bd (patch) | |
tree | e5b990943e25fae13ae6f1365bdc86f80b432b50 | |
parent | 743f03eeb0bdcb596b46fae51d23c0fcf0db0474 (diff) | |
download | go-287c5e8066396e953254d7980a80ec082edf11bd.tar.gz go-287c5e8066396e953254d7980a80ec082edf11bd.zip |
cmd/compile: fix stack growing algorithm
The current stack growing implementation looks not right.
Specially, the line runtime/stack.go#L1068 never gets executed,
which causes many unnecessary copystack calls.
This PR is trying to correct the implementation.
As I'm not familiar with the code, the fix is just a guess.
Change-Id: I0bea1148175fad34f74f19d455c240c94d3cb78b
GitHub-Last-Rev: 57205f91fe6f7cecbf0b7aad0d90d2f81270b1e8
GitHub-Pull-Request: golang/go#47010
Reviewed-on: https://go-review.googlesource.com/c/go/+/332229
Reviewed-by: Keith Randall <khr@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Dmitri Shuralyov <dmitshur@golang.org>
-rw-r--r-- | src/runtime/stack.go | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/runtime/stack.go b/src/runtime/stack.go index b21c9c9518..6e0d157630 100644 --- a/src/runtime/stack.go +++ b/src/runtime/stack.go @@ -1064,7 +1064,9 @@ func newstack() { // recheck the bounds on return.) if f := findfunc(gp.sched.pc); f.valid() { max := uintptr(funcMaxSPDelta(f)) - for newsize-gp.sched.sp < max+_StackGuard { + needed := max + _StackGuard + used := gp.stack.hi - gp.sched.sp + for newsize-used < needed { newsize *= 2 } } |