From: Michael Anthony Knyszek Date: Mon, 14 Jul 2025 19:23:12 +0000 (+0000) Subject: runtime: have mergeInlineMarkBits also clear the inline mark bits X-Git-Tag: go1.25rc3~5^2~22 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=0c6296ab12;p=gostls13.git runtime: have mergeInlineMarkBits also clear the inline mark bits This is conceptually simpler, as the sweeper doesn't have to worry about clearing them separately. It also doesn't have a use for them. This will also be useful to avoiding unnecessary zeroing in initInlineMarkBits at allocation time. Currently, because it's used in both span allocation and at sweep time, we cannot blindly trust needzero. This change also renames mergeInlineMarkBits to moveInlineMarkBits to make this change in semantics clearer from the name. For #73581. Change-Id: Ib154738a945633b7ff5b2ae27235baa310400139 Reviewed-on: https://go-review.googlesource.com/c/go/+/687936 Auto-Submit: Michael Knyszek LUCI-TryBot-Result: Go LUCI Reviewed-by: Michael Pratt --- diff --git a/src/runtime/mgcmark_greenteagc.go b/src/runtime/mgcmark_greenteagc.go index 3a368438d4..018f7df6ff 100644 --- a/src/runtime/mgcmark_greenteagc.go +++ b/src/runtime/mgcmark_greenteagc.go @@ -183,10 +183,10 @@ func (s *mspan) initInlineMarkBits() { s.inlineMarkBits().init(s.spanclass) } -// mergeInlineMarks merges the span's inline mark bits into dst. +// moveInlineMarks merges the span's inline mark bits into dst and clears them. // // gcUsesSpanInlineMarkBits(s.elemsize) must be true. -func (s *mspan) mergeInlineMarks(dst *gcBits) { +func (s *mspan) moveInlineMarks(dst *gcBits) { if doubleCheckGreenTea && !gcUsesSpanInlineMarkBits(s.elemsize) { throw("expected span with inline mark bits") } @@ -203,6 +203,9 @@ func (s *mspan) mergeInlineMarks(dst *gcBits) { if doubleCheckGreenTea && !s.spanclass.noscan() && imb.marks != imb.scans { throw("marks don't match scans for span with pointer") } + + // Reset the inline mark bits. + imb.init(s.spanclass) } // inlineMarkBits returns the inline mark bits for the span. diff --git a/src/runtime/mgcmark_nogreenteagc.go b/src/runtime/mgcmark_nogreenteagc.go index c0ca5c21ea..6e4f0c4f72 100644 --- a/src/runtime/mgcmark_nogreenteagc.go +++ b/src/runtime/mgcmark_nogreenteagc.go @@ -24,7 +24,7 @@ func tryDeferToSpanScan(p uintptr, gcw *gcWork) bool { func (s *mspan) initInlineMarkBits() { } -func (s *mspan) mergeInlineMarks(to *gcBits) { +func (s *mspan) moveInlineMarks(to *gcBits) { throw("unimplemented") } diff --git a/src/runtime/mgcsweep.go b/src/runtime/mgcsweep.go index a3bf2989df..1605c21966 100644 --- a/src/runtime/mgcsweep.go +++ b/src/runtime/mgcsweep.go @@ -650,9 +650,9 @@ func (sl *sweepLocked) sweep(preserve bool) bool { } } - // Copy over the inline mark bits if necessary. + // Copy over and clear the inline mark bits if necessary. if gcUsesSpanInlineMarkBits(s.elemsize) { - s.mergeInlineMarks(s.gcmarkBits) + s.moveInlineMarks(s.gcmarkBits) } // Check for zombie objects. @@ -704,11 +704,6 @@ func (sl *sweepLocked) sweep(preserve bool) bool { // Initialize alloc bits cache. s.refillAllocCache(0) - // Reset the object queue, if we have one. - if gcUsesSpanInlineMarkBits(s.elemsize) { - s.initInlineMarkBits() - } - // The span must be in our exclusive ownership until we update sweepgen, // check for potential races. if state := s.state.get(); state != mSpanInUse || s.sweepgen != sweepgen-1 {