Software transactional memory for dynamic-sized data structures
Summary (3 min read)
1. INTRODUCTION
- Using locks in programs for shared-memory multiprocessors introduces well-known software engineering problems.
- Coarse-grained locks, which protect relatively large amounts of data, generally do not scale: threads block one another even when they do not really interfere, and the lock becomes a source of contention.
- Fine-grained locks can mitigate these scalability problems, but they introduce software engineering problems as the locking conventions for guarartteeing correctness and avoiding deadlock become complex and error-prone.
- A thread preempted while holding a lock will obstruct other threads.
PODC'03,
- Dynamic Software Transactional Memory (DSTM) is a low-level application programming interface (API) for synchronizing shared data without using locks.
- Transactional memory supports a computational model in which each thread announces the start of a transaction, executes a sequence of operations on shared objects, and then tries to commit the transaction.
- Like stronger non-blocking progress conditions such as lock-freedom and wait-freedom, obstruction-freedom ensures that a halted thread cannot prevent other threads from making progress.
- It consults a contention manager to determine whether it should abort the other transaction immediately or wait for some time to allow the other transaction a chance to complete.
- The authors believe that this approach will yield simpler and more efficleat concurrent data structures, which will help accelerate their widespread acceptance and deployment.
2. OVERVIEW AND EXAMPLES
- Ultimately, the authors would like DSTM to support nested transactions, so that a class whose methods use transactions can invoke from within a transaction methods of other classes that also use transactions.
- The authors have not acquired sufficient experience programming with DSTM to decide on the appropriate nesting semantics, so they do not specify this behavior for now.
2.1 Extended Example
- An attractive feature of DSTM is that the authors can reason about this code almost as if it were sequential.
- The principal differences are the need to catch Denied exceptions and to retry transactions that fail to commit, and the need to distinguish between transactional :nodes and non-transactional list elements.
- Note that after catching a Denied exception, the authors must still call commitTransaction to terminate the transaction, even though it is guaranteed to fail.
2.2 Conflict Reduction
- DSTM provides several mechanisms for eliminating unneeded conflicts.
- One conventional mechanism is to allow transactions to open nodes in read-only mode, indicating that the transaction will not modify the object.
List list = (List)node.open(READ);
- Concurrent transactions that open the same transactional object for reading do not conflict.
- Once an object has been released, other transactions accessing that object do not conflict with the releasing transaction over the released object.
- The effects in this case are potentially even worse because that transaction can actually commit, even though it is not linearizable.
- A transaction that adds an element to the list "upgrades" its access to the node to be modified by reopening that node in WRITE mode.
- Because a transaction may open the same object several times, the DSTM matches, for each object, invocations of 4This is analogous to the technique of lock coupling (see [5] , e.g.), but of course does not use any locks.
3. IMPLEMENTATION
- A transaction object (class Transaction) has a status field that is initialized to be ACTIVE, and is later set to either COMMITTED or AB01:tTED using a CAS instruction.
- 5 (CAS functionality is provided by the AtemicRe:f class in the experimental prototype of Doug Lea's java.util, concurrent package [1] .).
3.1 Opening a Transactional Object
- To match invocations of open(READ) and release, the transaction also maintains a counter for each pair in its readonly table.
- If an object is opened in READ mode when it already has an entry in the table, the transaction increments the corresponding counter instead of inserting a new pair.
- This counter is decremented by the release method, and the pair is removed when the counter is reduced to zero.
3.2 Validating and Committing a Transaction
- This problem does not arise in their Java implementation, because garbage collection (GC) ensures that a Locater object does not get recycled until no thread has a pointer to it.
- While GC eliminates the ABA problem in this case, the authors caution the reader against assuming that the ABA problem can never occur in environments that support GC.
- Committing a transaction requires two steps: validating the entries in the read-only table as described above, and calling CAS to attempt to change the status field of the Transaction object from ACTIVE to COMMITTED.
3.3 Costs
- Validating a transaction that has opened W objects for writing and R objects for reading (that have not been released) requires O(R) work.
- Because validation must be performed whenever an object is opened and when the transaction commits, the total overhead due to the DSTM implementation for a transaction that opens R for reading and W objects for writing is O((R + W)R) plus the cost of copying each of the W objects opened for writing once.
- Note that, in addition to reducing the potential for conflict, releasing objects opened for reading also reduces the overhead due to validation: released objects do not need to be validated.
- Thus, if at most K objects are open for reading at any time, then the total overhead for a transaction is only O((R + W)K) plus the cost of cloning the W objects.
4. CONTENTION MANAGEMENT
- In addition to their explicit purposes, the contention manager's methods may implement other measures, such as backoff and queuing, to manage contention.
- The authors have done only preliminary work using these methods to implement some simple contention management strategies, and they expect the Contention.
- Manager interface to evolve as the authors gain experience with what methods--especially notification methods-are useful for implementing more sophisticated strategies.
4.1 Examples
- One can imagine many variations on this strategy, as well as different strategies based on queuing rather than backoff combined with spinning.
- Discovering which strategies work best remains an open area of research.
5. RESULTS
- One shortcoming of their current DSTM implementation with respect to the range of possible contention managers is that there is no way for one transaction to detect that another transaction has opened an object in READ mode.
- By opening that object in WRITE mode, the first transaction will cause the other transaction to abort.
- Clearly there is a tradeoff between the amount of synchronization needed to open an object for reading in a "visible" way in order to enable competing transactions to "be polite" and the benefit derived from doing so.
- The authors axe currently working on some ideas in this direction.
6. CONCLUDING REMARKS
- Thanks to Ron Larson for getting us access to the Sun Fire 15K computer, to Doug Lea for his ex-perimentM j a v a .
- Thanks also to Guy Steele and Jan-Willem Maessen for useful feedback, especially about the DSTM interface.
- (Jan Mso suggested nulling out the extra pointer of locators whose transactions are aborted or committed to allow garbage collection of the obsolete version.).
Did you find this useful? Give us your feedback
Citations
1,268 citations
934 citations
Cites background or methods from "Software transactional memory for d..."
...Additional performance can be achieved in the program by using early-release [19], as described in [40]....
[...]
...To benefit from the increasing number of cores per chip, application developers have to develop parallel programs and deal with cumbersome issues such as synchronization tradeoffs, deadlock avoidance, and races....
[...]
893 citations
Cites methods from "Software transactional memory for d..."
...We present here a set of microbenchmarks that have become standard in the community [25], comparing a sequential red-black tree made concurrent using various algorithms representing state-of-the-art non-blocking [6] and lock-based [5, 18] STMs....
[...]
891 citations
850 citations
References
21,651 citations
3,396 citations
"Software transactional memory for d..." refers background in this paper
...Coarse-grained locks, which protect relatively large amounts of data, generally do not scale: threads block one another even when they do not really interfere, and the lock be- comes a source of contention....
[...]
2,406 citations
"Software transactional memory for d..." refers background in this paper
...Victor Luchangco Sun Microsystems Laboratories 1 Network Drive Burlington, MA 01803, USA victor.luchangco@sun.com William N. Scherer III Department of Computer Science University of Rochester Rochester, NY 14620, USA scherer@cs.rochester.edu failures and delays....
[...]
939 citations
"Software transactional memory for d..." refers background in this paper
...about the ABA problem [8], in which a CAS operation fails to notice that the location it accesses has changed to a new value and then back to the original value, causing the CAS to succeed...
[...]
880 citations
"Software transactional memory for d..." refers background in this paper
...3.2 Validating and Committing a Transaction After open() has determined which version of an object to return, and before it actually returns that version, the DSTM must validate the calling transaction in order to en- sure that the user transaction code can never observe an inconsistent state....
[...]
...In Proceedings of the 13th Annual ACM Symposium on Principles of Distributed Computing, pages 151-160, 1994....
[...]
...In Proceedings of the 20th International Symposium in Computer Architecture, pages 289-300, 1993....
[...]
...Journal of Parallel and Distributed Computing, 51(1):1-26, 1998....
[...]
...In Proceedings of the 27th Annual ACM Symposium on Theory of Computing, pages 538-547, 1995....
[...]