Skip to content

Commit 6d4a91c

Browse files
mknyszekgopherbot
authored andcommitted
runtime: only clear inline mark bits on span alloc if necessary
This change modifies initInlineMarkBits to only clear mark bits if the span wasn't just freshly allocated from the OS, where we know the bits are already zeroed. This probably doesn't make a huge difference most of the time, but it's an easy optimization and helps rule it out as a source of slowdown. For #73581. Change-Id: I78cd4d8968bb0bf6536c0a38ef9397475c39f0ad Reviewed-on: https://go-review.googlesource.com/c/go/+/687937 Auto-Submit: Michael Knyszek <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Cherry Mui <[email protected]> Reviewed-by: Michael Pratt <[email protected]>
1 parent 0c6296a commit 6d4a91c

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/runtime/mgcmark_greenteagc.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func (o *spanScanOwnership) or(v spanScanOwnership) spanScanOwnership {
110110
return spanScanOwnership(atomic.Or32(o32, uint32(v)<<off) >> off)
111111
}
112112

113-
func (imb *spanInlineMarkBits) init(class spanClass) {
113+
func (imb *spanInlineMarkBits) init(class spanClass, needzero bool) {
114114
if imb == nil {
115115
// This nil check and throw is almost pointless. Normally we would
116116
// expect imb to never be nil. However, this is called on potentially
@@ -131,7 +131,9 @@ func (imb *spanInlineMarkBits) init(class spanClass) {
131131
// See go.dev/issue/74375 for details.
132132
throw("runtime: span inline mark bits nil?")
133133
}
134-
*imb = spanInlineMarkBits{}
134+
if needzero {
135+
*imb = spanInlineMarkBits{}
136+
}
135137
imb.class = class
136138
}
137139

@@ -180,7 +182,8 @@ func (s *mspan) initInlineMarkBits() {
180182
if doubleCheckGreenTea && !gcUsesSpanInlineMarkBits(s.elemsize) {
181183
throw("expected span with inline mark bits")
182184
}
183-
s.inlineMarkBits().init(s.spanclass)
185+
// Zeroing is only necessary if this span wasn't just freshly allocated from the OS.
186+
s.inlineMarkBits().init(s.spanclass, s.needzero != 0)
184187
}
185188

186189
// moveInlineMarks merges the span's inline mark bits into dst and clears them.
@@ -205,7 +208,7 @@ func (s *mspan) moveInlineMarks(dst *gcBits) {
205208
}
206209

207210
// Reset the inline mark bits.
208-
imb.init(s.spanclass)
211+
imb.init(s.spanclass, true /* We know these bits are always dirty now. */)
209212
}
210213

211214
// inlineMarkBits returns the inline mark bits for the span.

0 commit comments

Comments
 (0)