Software Transactional Memory on Relaxed Memory Models

Rachid Guerraoui, Thomas A. Henzinger, Vasu Singh

Software Transactional Memory (STM) offers a high-level abstraction for concurrent programming, but its implementation often overlooks the complexities of underlying hardware. Presented at CAV 2009, this research bridges the gap between high-level STM algorithmic descriptions and the "messy reality" of relaxed memory models on modern multiprocessors. The authors introduce a framework to verify STM correctness under hardware reordering and provide a tool that automatically inserts necessary memory fences.

The Challenge of Relaxed Memory Models

Most STM algorithms are designed under the assumption of Sequential Consistency (SC), where operations occur in the exact order specified by the code. However, modern architectures (e.g., x86, SPARC) utilize relaxed memory models like Total Store Order (TSO), Partial Store Order (PSO), and Relaxed Memory Order (RMO) to improve performance. These models allow processors to reorder certain instructions, such as a store followed by a load to a different address.

Example of concurrent thread execution where instruction reordering under relaxed memory models can lead to unexpected states.

For an STM, such reordering can be fatal. It may allow a transaction to observe an inconsistent state, potentially leading to infinite loops or system crashes—a violation of the opacity property. To maintain safety, developers must use "fences" (memory barriers) to force a specific order. However, fences are computationally expensive; over-fencing degrades performance, while under-fencing compromises correctness. Before this work, there was no automated way to verify STMs at this low level of hardware atomicity.

The FOIL Framework: RML and Model Checking

To address this, the authors developed a two-part solution:

  1. RML (Relaxed Memory Language): A language for expressing concurrent algorithms with hardware-level atomicity. RML's semantics are parameterized by the memory model, explicitly accounting for instruction deferral and reordering allowed by the hardware.
  2. FOIL: An explicit-state model checker that takes an STM algorithm in RML and a memory model description. FOIL checks for opacity violations and, upon finding a counterexample, automatically inserts fences to rectify the issue.
Pseudocode for STM read and commit operations, illustrating the logic where memory reordering can occur and fences are needed.

To manage the "state space explosion" inherent in hardware-level verification—where a simple model's state count can jump from thousands to millions—the authors utilized structural properties of STMs. This allowed them to reduce the verification problem to a manageable scenario involving just two threads and two variables, making the computation feasible.

Key Insights and Results

The research yielded several significant findings regarding common STM implementations like DSTM, TL2, and McRT STM:

  • TSO Safety: Surprisingly, these algorithms were found to be opaque under TSO without any additional fences. This is because TSO only reorders stores followed by loads, whereas these STMs are primarily sensitive to the ordering of two stores or two loads.
  • Sensitivity to Store-Store Reordering: STMs are highly vulnerable under PSO and RMO, which allow store-store reordering. For instance, if a commit updates a data variable before its associated lock due to reordering, other threads may read corrupted data.
  • Automated Fence Discovery: FOIL's automated fence insertion matched the pragmatic, optimized placements chosen by human experts. For the TL2 algorithm under RMO, FOIL correctly identified the need for exactly one store fence in the commit procedure and two load fences in the read procedure.

Conclusion and Future Work

This work provides a robust methodology for verifying low-level concurrent systems and ensuring they maintain high-level properties like opacity. While FOIL successfully verified major STM implementations across various hardware models, limitations remain. Current models do not yet account for complex compiler optimizations or higher-level software memory models like the Java Memory Model. Extending FOIL to these domains remains a primary goal for future research in ensuring the reliability of concurrent software on modern hardware.

Summary updated

BibTeX
@inproceedings{guerraoui2009software,
  author = {Rachid Guerraoui and Thomas A. Henzinger and Vasu Singh},
  title = {{Software Transactional Memory on Relaxed Memory Models}},
  booktitle = {CAV},
  year = {2009},
  doi = {10.1007/978-3-642-02658-4\_26},
}
Figure