From 1f7a01459b1172fdc571a81ffd369dbf32b6c8b2 Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Mon, 23 Nov 2020 15:42:48 +0800 Subject: [PATCH] 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 Run-TryBot: Ian Lance Taylor TryBot-Result: Go Bot Reviewed-by: Austin Clements --- src/runtime/proc.go | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/src/runtime/proc.go b/src/runtime/proc.go index dbb430fd25..19049d21f3 100644 --- a/src/runtime/proc.go +++ b/src/runtime/proc.go @@ -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) }