mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
runtime, cmd: rationalize StackLimit and StackGuard
The current definitions of StackLimit and StackGuard only indirectly
specify the NOSPLIT stack limit and duplicate a literal constant
(928). Currently, they define the stack guard delta, and from there
compute the NOSPLIT limit.
Rationalize these by defining a new constant, abi.StackNosplitBase,
which consolidates and directly specifies the NOSPLIT stack limit (in
the default case). From this we then compute the stack guard delta,
inverting the relationship between these two constants. While we're
here, we rename StackLimit to StackNosplit to make it clearer what's
being limited.
This change does not affect the values of these constants in the
default configuration. It does slightly change how
StackGuardMultiplier values other than 1 affect the constants, but
this multiplier is a pretty rough heuristic anyway.
before after
stackNosplit 800 800
_StackGuard 928 928
stackNosplit -race 1728 1600
_StackGuard -race 1856 1728
For #59670.
Change-Id: Ia94094c5e47897e7c088d24b4a5e33f5c2768db5
Reviewed-on: https://go-review.googlesource.com/c/go/+/486976
Auto-Submit: Austin Clements <austin@google.com>
Run-TryBot: Austin Clements <austin@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
parent
03ad1f1a34
commit
0f099a4bc5
6 changed files with 25 additions and 34 deletions
|
|
@ -85,19 +85,18 @@ const (
|
|||
_FixedStack6 = _FixedStack5 | (_FixedStack5 >> 16)
|
||||
_FixedStack = _FixedStack6 + 1
|
||||
|
||||
// stackNosplit is the maximum number of bytes that a chain of NOSPLIT
|
||||
// functions can use.
|
||||
// This arithmetic must match that in cmd/internal/objabi/stack.go:StackNosplit.
|
||||
stackNosplit = abi.StackNosplitBase * sys.StackGuardMultiplier
|
||||
|
||||
// The stack guard is a pointer this many bytes above the
|
||||
// bottom of the stack.
|
||||
//
|
||||
// The guard leaves enough room for one _StackSmall frame plus
|
||||
// a _StackLimit chain of NOSPLIT calls plus _StackSystem
|
||||
// bytes for the OS.
|
||||
// The guard leaves enough room for a stackNosplit chain of NOSPLIT calls
|
||||
// plus one stackSmall frame plus stackSystem bytes for the OS.
|
||||
// This arithmetic must match that in cmd/internal/objabi/stack.go:StackLimit.
|
||||
_StackGuard = 928*sys.StackGuardMultiplier + _StackSystem
|
||||
|
||||
// The maximum number of bytes that a chain of NOSPLIT
|
||||
// functions can use.
|
||||
// This arithmetic must match that in cmd/internal/objabi/stack.go:StackLimit.
|
||||
_StackLimit = _StackGuard - _StackSystem - abi.StackSmall
|
||||
_StackGuard = stackNosplit + _StackSystem + abi.StackSmall
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -1211,7 +1210,7 @@ func shrinkstack(gp *g) {
|
|||
// down to the SP plus the stack guard space that ensures
|
||||
// there's room for nosplit functions.
|
||||
avail := gp.stack.hi - gp.stack.lo
|
||||
if used := gp.stack.hi - gp.sched.sp + _StackLimit; used >= avail/4 {
|
||||
if used := gp.stack.hi - gp.sched.sp + stackNosplit; used >= avail/4 {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue