Skip to content

Commit 287c5e8

Browse files
TapirLiurandall77
authored andcommitted
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: 57205f9 GitHub-Pull-Request: #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>
1 parent 743f03e commit 287c5e8

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/runtime/stack.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1064,7 +1064,9 @@ func newstack() {
10641064
// recheck the bounds on return.)
10651065
if f := findfunc(gp.sched.pc); f.valid() {
10661066
max := uintptr(funcMaxSPDelta(f))
1067-
for newsize-gp.sched.sp < max+_StackGuard {
1067+
needed := max + _StackGuard
1068+
used := gp.stack.hi - gp.sched.sp
1069+
for newsize-used < needed {
10681070
newsize *= 2
10691071
}
10701072
}

0 commit comments

Comments
 (0)