1
0
mirror of https://github.com/golang/go synced 2024-11-08 05:36:13 -07:00

runtime: batch moving gFree list between local p and global schedt

Change-Id: I0ca1fcee6d3f08bdfcfa51f0dc774118d7355636
Reviewed-on: https://go-review.googlesource.com/c/go/+/271914
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
This commit is contained in:
Andy Pan 2020-11-23 15:42:48 +08:00 committed by Austin Clements
parent bcac57f89c
commit 1f7a01459b

View File

@ -4170,17 +4170,25 @@ func gfput(_p_ *p, gp *g) {
_p_.gFree.push(gp)
_p_.gFree.n++
if _p_.gFree.n >= 64 {
lock(&sched.gFree.lock)
var (
inc int32
stackQ gQueue
noStackQ gQueue
)
for _p_.gFree.n >= 32 {
_p_.gFree.n--
gp = _p_.gFree.pop()
_p_.gFree.n--
if gp.stack.lo == 0 {
sched.gFree.noStack.push(gp)
noStackQ.push(gp)
} else {
sched.gFree.stack.push(gp)
stackQ.push(gp)
}
sched.gFree.n++
inc++
}
lock(&sched.gFree.lock)
sched.gFree.noStack.pushAll(noStackQ)
sched.gFree.stack.pushAll(stackQ)
sched.gFree.n += inc
unlock(&sched.gFree.lock)
}
}
@ -4232,17 +4240,25 @@ retry:
// Purge all cached G's from gfree list to the global list.
func gfpurge(_p_ *p) {
lock(&sched.gFree.lock)
var (
inc int32
stackQ gQueue
noStackQ gQueue
)
for !_p_.gFree.empty() {
gp := _p_.gFree.pop()
_p_.gFree.n--
if gp.stack.lo == 0 {
sched.gFree.noStack.push(gp)
noStackQ.push(gp)
} else {
sched.gFree.stack.push(gp)
stackQ.push(gp)
}
sched.gFree.n++
inc++
}
lock(&sched.gFree.lock)
sched.gFree.noStack.pushAll(noStackQ)
sched.gFree.stack.pushAll(stackQ)
sched.gFree.n += inc
unlock(&sched.gFree.lock)
}