Skip to content

Commit 9c634ea

Browse files
committed
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Rick Hudson <[email protected]>
1 parent 7db509e commit 9c634ea

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/runtime/mgcmark.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,13 @@ func gcDrain(gcw *gcWork, flags gcDrainFlags) {
882882
b = gcw.tryGetFast()
883883
if b == 0 {
884884
b = gcw.tryGet()
885+
if b == 0 {
886+
// Flush the write barrier
887+
// buffer; this may create
888+
// more work.
889+
wbBufFlush(nil, 0)
890+
b = gcw.tryGet()
891+
}
885892
}
886893
}
887894
if b == 0 {
@@ -963,6 +970,12 @@ func gcDrainN(gcw *gcWork, scanWork int64) int64 {
963970
b := gcw.tryGetFast()
964971
if b == 0 {
965972
b = gcw.tryGet()
973+
if b == 0 {
974+
// Flush the write barrier buffer;
975+
// this may create more work.
976+
wbBufFlush(nil, 0)
977+
b = gcw.tryGet()
978+
}
966979
}
967980

968981
if b == 0 {

0 commit comments

Comments
 (0)