From efb0c55407cdbef6aa5471f057b8afd1d0303369 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Fri, 11 Mar 2016 13:54:55 -0500 Subject: [PATCH] runtime: avoid span root marking entirely during mark termination Currently we enqueue span root mark jobs during both concurrent mark and mark termination, but we make the job a no-op during mark termination. This is silly. Instead of queueing them up just to not do them, don't queue them up in the first place. Change-Id: Ie1d36de884abfb17dd0db6f0449a2b7c997affab Reviewed-on: https://go-review.googlesource.com/20666 Reviewed-by: Rick Hudson Run-TryBot: Austin Clements TryBot-Result: Gobot Gobot --- src/runtime/mgcmark.go | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/runtime/mgcmark.go b/src/runtime/mgcmark.go index 3c6aec943b..8384190407 100644 --- a/src/runtime/mgcmark.go +++ b/src/runtime/mgcmark.go @@ -55,8 +55,19 @@ func gcMarkRootPrepare() { } } - // Compute number of span roots. - work.nSpanRoots = (len(work.spans) + rootBlockSpans - 1) / rootBlockSpans + if !work.markrootDone { + // On the first markroot, we need to scan span roots. + // In concurrent GC, this happens during concurrent + // mark and we depend on addfinalizer to ensure the + // above invariants for objects that get finalizers + // after concurrent mark. In STW GC, this will happen + // during mark termination. + work.nSpanRoots = (len(work.spans) + rootBlockSpans - 1) / rootBlockSpans + } else { + // We've already scanned span roots and kept the scan + // up-to-date during concurrent mark. + work.nSpanRoots = 0 + } // Snapshot of allglen. During concurrent scan, we just need // to be consistent about how many markroot jobs we create and @@ -263,14 +274,8 @@ func markrootSpans(gcw *gcWork, shard int) { // TODO(austin): There are several ideas for making this more // efficient in issue #11485. - // We process objects with finalizers only during the first - // markroot pass. In concurrent GC, this happens during - // concurrent mark and we depend on addfinalizer to ensure the - // above invariants for objects that get finalizers after - // concurrent mark. In STW GC, this will happen during mark - // termination. if work.markrootDone { - return + throw("markrootSpans during second markroot") } sg := mheap_.sweepgen -- 2.48.1