-
Type:
Improvement
-
Resolution: Fixed
-
Priority:
Major - P3
-
Affects Version/s: None
-
Component/s: Query Execution
-
None
-
Query Execution
-
Fully Compatible
-
200
-
None
-
None
-
None
-
None
-
None
-
None
-
None
Overview
Copying a BSONObj increments the SharedBuffer holder's refcount. Atomic::fetchAndAdd() defaults to seq_cst, which on aarch64 emits a full acquire-release LDADDAL. Relaxed is sufficient for an increment because the caller already holds a reference, so only the decrement that reaches zero needs ordering. RefCountable already does exactly this, with the same justification.
Scope of Work
* src/mongo/util/shared_buffer.h — use fetchAndAddRelaxed() in intrusive_ptr_add_ref()
Notes
Found via getFieldDottedOrArray(), which takes an owning BSONObj copy on the matcher's per-document path. With PGO and BOLT enabled that function is inlined into BSONMatchableDocument::allocateIterator, the third hottest symbol at ~3%, and the atomic dominated it.
The decrement is deliberately left at seq_cst. Relaxing it to release with an acquire fence on the zero transition has no in-tree precedent, and on aarch64 acq_rel and seq_cst emit the same instruction, so it needs a separate argument.
Acceptance Criteria
* No change in behaviour; TSAN clean