mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
runtime: separate stack freeing from stack shrinking
Currently, shrinkstack will free the stack if the goroutine is dead. There are only two places that call shrinkstack: scanstack, which will never call it if the goroutine is dead; and markrootFreeGStacks, which only calls it on dead goroutines. Clean this up by separating stack freeing out of shrinkstack. Change-Id: I7d7891e620550c32a2220833923a025704986681 Reviewed-on: https://go-review.googlesource.com/c/go/+/170890 Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com>
This commit is contained in:
parent
ea9859f858
commit
68d89bb8e0
2 changed files with 3 additions and 11 deletions
|
|
@ -270,7 +270,9 @@ func markrootFreeGStacks() {
|
||||||
// Free stacks.
|
// Free stacks.
|
||||||
q := gQueue{list.head, list.head}
|
q := gQueue{list.head, list.head}
|
||||||
for gp := list.head.ptr(); gp != nil; gp = gp.schedlink.ptr() {
|
for gp := list.head.ptr(); gp != nil; gp = gp.schedlink.ptr() {
|
||||||
shrinkstack(gp)
|
stackfree(gp.stack)
|
||||||
|
gp.stack.lo = 0
|
||||||
|
gp.stack.hi = 0
|
||||||
// Manipulate the queue directly since the Gs are
|
// Manipulate the queue directly since the Gs are
|
||||||
// already all linked the right way.
|
// already all linked the right way.
|
||||||
q.tail.set(gp)
|
q.tail.set(gp)
|
||||||
|
|
|
||||||
|
|
@ -1077,16 +1077,6 @@ func gostartcallfn(gobuf *gobuf, fv *funcval) {
|
||||||
// gp must be stopped, but the world need not be.
|
// gp must be stopped, but the world need not be.
|
||||||
func shrinkstack(gp *g) {
|
func shrinkstack(gp *g) {
|
||||||
gstatus := readgstatus(gp)
|
gstatus := readgstatus(gp)
|
||||||
if gstatus&^_Gscan == _Gdead {
|
|
||||||
if gp.stack.lo != 0 {
|
|
||||||
// Free whole stack - it will get reallocated
|
|
||||||
// if G is used again.
|
|
||||||
stackfree(gp.stack)
|
|
||||||
gp.stack.lo = 0
|
|
||||||
gp.stack.hi = 0
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if gp.stack.lo == 0 {
|
if gp.stack.lo == 0 {
|
||||||
throw("missing stack in shrinkstack")
|
throw("missing stack in shrinkstack")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue