Does a store-release followed by a load-acquire guarantee visibility of pagination offsets on AArch64 without extra barriers?
0 reputation · 13 Nov 2022, 10:02 UTC
0 reputation · 13 Nov 2022, 10:02 UTC
Ensure that a consumer thread observing a readiness flag via a load-acquire also sees the pagination offset updated by a preceding store-release, preventing duplicate or skipped pages when bounding queries and paginating large datasets on AArch64.
AArch64 follows a weak memory model where normal loads and stores may be reordered unless explicit barrier instructions (DSB, DMB, ISH) or matching acquire-release pairs are used. It is unclear whether the release-acquire pairing alone guarantees visibility of the offset, or whether additional memory barriers are required when the offset and flag reside in normal memory, and whether the result varies with memory type (device vs normal) or cacheability attributes.
33275 reputation · 13 Nov 2022, 12:56 UTC
Yes. On AArch64, a store-release (STLR) followed by a load-acquire (LDAR) on the same memory location guarantees that the consumer thread will see the updated pagination offset, provided the offset was written before the store-release in program order. No additional DMB or DSB barriers are required for this specific synchronization pattern in normal memory.
AArch64 utilizes a weakly ordered memory model, but STLR and LDAR provide one-way barriers that create a "synchronizes-with" relationship:
STLR in program order are observed by other observers before the STLR itself becomes visible.LDAR in program order are observed only after the LDAR has completed.When the consumer's LDAR reads the value written by the producer's STLR, the architecture guarantees that the preceding write to the pagination offset is visible to the consumer. This prevents the consumer from observing a stale offset while seeing a "ready" flag.
DSB) may be necessary depending on the specific device attribute.std::atomic in C++ with memory_order_release and memory_order_acquire) to ensure the compiler does not reorder the instructions before they reach the hardware.LDAR must target the same memory address as the STLR to establish the synchronization edge.To verify the implementation, perform the following checks:
STLR and LDAR instructions rather than standard STR/LDR paired with DMB.litmus-test or herd to simulate the memory pattern and ensure no stale reads occur under high contention.Diagnostic Detail Required: Are the pagination offset and readiness flag located in the same cache line or mapped to different memory attributes (e.g., one in Normal and one in Device memory)?
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.