go: runtime: mallocgc does not seem to need to call publicationBarrier when allocating noscan objects
I’m doing some performance analysis of go1.20
on arm64
platform, and I found that the DMB instruction in mallocgc consumes a lot of time.
I found some CLs:
- CL11083: In
go1.5
,publicationBarrier
was added when allocating scan objects. - CL23043: In
go1.7
,publicationBarrier
is was added when allocating noscan objects because of theheapBitsSetTypeNoScan
. - CL41253: However,
publicationBarrier
is still called when allocating noscan objects afterheapBitsSetTypeNoScan
is deleted.
I tried to find the reason why publicationBarrier
was called when allocating noscan objects, but I couldn’t find it.
Knowing from the comments of source code, publicationBarrier
in mallocgc
ensure that the stores above that initialize x to type-safe memory and set the heap bits occur before the caller can make x observable to the GC. publicationBarrier
in allocSpan
make sure the newly allocated span will be observed by the GC before pointers into the span are published.
My question is, GC don’t scan noscan object, why is publicationBarrier
required when allocating noscan objects in mallocgc
?
Thank you in advance for your help.
About this issue
- Original URL
- State: open
- Created 8 months ago
- Comments: 17 (14 by maintainers)
I also think you might be right, but such changes are risky. We could try removing it for noscan objects early next development cycle and watch CI closely to see if anything breaks.