From 9c634ea889fdfa41aec9183bd5693c155374ba76 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Fri, 3 Aug 2018 14:56:55 -0400 Subject: [PATCH] runtime: flush write barrier buffer to create work Currently, if the gcWork runs out of work, we'll fall out of the GC worker, even though flushing the write barrier buffer could produce more work. While this is not a correctness issue, it can lead to premature mark 2 or mark termination. Fix this by flushing the write barrier buffer if the local gcWork runs out of work and then checking the local gcWork again. This reduces the number of premature mark terminations during all.bash by about a factor of 10. Updates #26903. This is preparation for eliminating mark 2. Change-Id: I48577220b90c86bfd28d498e8603bc379a8cd617 Reviewed-on: https://go-review.googlesource.com/c/134315 Run-TryBot: Austin Clements TryBot-Result: Gobot Gobot Reviewed-by: Rick Hudson --- src/runtime/mgcmark.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/runtime/mgcmark.go b/src/runtime/mgcmark.go index f713841cfa..bf69172f6a 100644 --- a/src/runtime/mgcmark.go +++ b/src/runtime/mgcmark.go @@ -882,6 +882,13 @@ func gcDrain(gcw *gcWork, flags gcDrainFlags) { b = gcw.tryGetFast() if b == 0 { b = gcw.tryGet() + if b == 0 { + // Flush the write barrier + // buffer; this may create + // more work. + wbBufFlush(nil, 0) + b = gcw.tryGet() + } } } if b == 0 { @@ -963,6 +970,12 @@ func gcDrainN(gcw *gcWork, scanWork int64) int64 { b := gcw.tryGetFast() if b == 0 { b = gcw.tryGet() + if b == 0 { + // Flush the write barrier buffer; + // this may create more work. + wbBufFlush(nil, 0) + b = gcw.tryGet() + } } if b == 0 { -- 2.50.0