Memory Consistency and Program Transformations

Akshay Gopalakrishnan,Clark Verbrugge,Mark Batty
2024-09-18
Abstract:A memory consistency model specifies the allowed behaviors of shared memory concurrent programs. At the language level, these models are known to have a non-trivial impact on the safety of program optimizations, limiting the ability to rearrange/refactor code without introducing new behaviors. Existing programming language memory models try to address this by permitting more (relaxed/weak) concurrent behaviors but are still unable to allow all the desired optimizations. A core problem is that weaker consistency models may also render optimizations unsafe, a conclusion that goes against the intuition of them allowing more behaviors. This exposes an open problem of the compositional interaction between memory consistency semantics and optimizations: which parts of the semantics correspond to allowing/disallowing which set of optimizations is unclear. In this work, we establish a formal foundation suitable enough to understand this compositional nature, decomposing optimizations into a finite set of elementary effects on program execution traces, over which aspects of safety can be assessed. We use this decomposition to identify a desirable compositional property (complete) that would guarantee the safety of optimizations from one memory model to another. We showcase its practicality by proving such a property between Sequential Consistency (SC) and $SC_{RR}$, the latter allowing independent read-read reordering over $SC$. Our work potentially paves way to a new design methodology of programming-language memory models, one that places emphasis on the optimizations desired to be performed.
Programming Languages
What problem does this paper attempt to address?
The core problem that this paper attempts to solve is **the complex relationship between memory consistency models and program optimization**. Specifically, the author focuses on how to safely perform program optimization, especially the optimization of multi - threaded programs, under different memory consistency models. ### Problem Background 1. **The Role of Memory Consistency Models**: - The Memory Consistency Model defines the allowed behaviors of shared - memory concurrent programs. It determines the order in which actions executed by one thread/processor are visible to another thread/processor. - These models have a significant impact on the safety of program optimization and limit the ability of code reordering and restructuring because these operations may introduce new behaviors. 2. **Limitations of Existing Models**: - Existing programming - language memory models attempt to solve this problem by allowing more weakly - consistent behaviors, but still cannot allow all desired optimizations. - Weaker consistency models may make optimization unsafe, which is counter - intuitive: a weaker consistency model should allow more behaviors, but in fact it does not necessarily mean that more optimizations are safe. ### Core Problem - **The Composability Problem of Optimization and Consistency**: - It is not clear which semantic parts correspond to which optimizations being allowed or prohibited. - A weaker consistency model may allow more behaviors, but not necessarily more optimizations, which makes it complex to understand how to combine the consistency requirements of individual program optimizations. ### Goals of the Paper The author aims to establish a formal basis for understanding this compositional nature and decompose optimization into basic effects on a finite set of program execution traces. In this way, the safety of certain aspects can be evaluated, and an ideal compositional property (i.e., "complete") can be identified to ensure the safety of optimization from one memory model to another. ### Main Contributions 1. **Representing Concurrent - Program Behaviors**: - Use pre - traces and candidate - executions to conservatively approximate execution traces. 2. **Decomposing Program Transformations**: - Decompose program transformations into different transformation effects on each pre - trace. 3. **Proposing a Methodology**: - Propose a method to derive a memory consistency model representing the desired transformation effect and formalize the required compositional interaction property (Complete) to ensure the safety of transformation effects from one model to another. 4. **Demonstrating Practicality**: - Demonstrate the practical application value of this method by deriving the SCRR model and proving its completeness under Sequential Consistency (SC). ### Summary This paper solves the composability problem between memory consistency models and program optimization by establishing a formal basis and methodology, providing new ideas for designing new programming - language memory models, with particular emphasis on desired compiler optimizations.