From 71a76476627fb0752d1b816406da4e5a6511c2c9 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Thu, 15 Oct 2015 13:25:19 -0400 Subject: [PATCH] [release-branch.go1.5] runtime: fix recursive GC assist better Commit c257dfb attempted to fix recursive allocation in gcAssistAlloc; however, it only reduced it: setting gp.gcalloc to 0 isn't sufficient to disable assists at the beginning of the GC cycle when gp.gcscanwork is also small or zero. Fix this recursion more completely by setting gcalloc to a sentinel value that directly disables assists. Fixes #12894 (again). Change-Id: I9599566222d8f540d0b39806846bfc702e6666e5 Reviewed-on: https://go-review.googlesource.com/15891 Run-TryBot: Austin Clements TryBot-Result: Gobot Gobot Reviewed-by: Russ Cox --- src/runtime/mgcmark.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/runtime/mgcmark.go b/src/runtime/mgcmark.go index e5dfa72026..64cc1af64f 100644 --- a/src/runtime/mgcmark.go +++ b/src/runtime/mgcmark.go @@ -152,6 +152,11 @@ func gcAssistAlloc(size uintptr, allowAssist bool) { } // Record allocation. + if gp.gcalloc+size < gp.gcalloc { + // gcalloc would overflow, or it's set to a sentinel + // value to prevent recursive assist. + return + } gp.gcalloc += size if !allowAssist { @@ -295,7 +300,7 @@ retry: // timeSleep may allocate, so avoid recursive assist. gcalloc := gp.gcalloc - gp.gcalloc = 0 + gp.gcalloc = ^uintptr(0) timeSleep(100 * 1000) gp.gcalloc = gcalloc goto retry -- 2.48.1