Download presentation
Presentation is loading. Please wait.
Published byJune Nash Modified over 9 years ago
1
Transactional Locking Nir Shavit Tel Aviv University Joint work with Dave Dice and Ori Shalev
2
object Shared Memory Concurrent Programming How do we make the programmer’s life simple without slowing computation down to a halt?!
3
A FIFO Queue bcd TailHead a Enqueue(d)Dequeue() => a
4
A Concurrent FIFO Queue synchronized{} Object lock bcd TailHead a P: Dequeue() => a Q: Enqueue(d)
5
Fine Grain Locks bcd TailHead a P: Dequeue() => a Q: Enqueue(d) Better Performance, More Complex Code Worry about deadlock, livelock…
6
Lock-Free (JSR-166) bcd TailHead a P: Dequeue() => a Q: Enqueue(d) Even Better Performance, Even More Complex Code Worry about deadlock, livelock, subtle bugs, hard to modify…
7
Transactional Memory [Herlihy-Moss] bcd TailHead a P: Dequeue() => a Q: Enqueue(d) Don’t worry about deadlock, livelock, subtle bugs, etc… Great Performance, Simple Code
8
Transactional Memory [Herlihy-Moss] bcd TailHead a P: Dequeue() => a Q: Enqueue(d) Don’t worry about deadlock, livelock, subtle bugs, etc… b TailHead a Great Performance, Simple Code
9
TM: How Does It Work synchronized{ } atomic Execute all synchronized instructions as an atomic transaction… Simplicity of Global Lock with Granularity of Fine-Grained Implementation
10
Hardware TM [Herlihy-Moss] Limitations: atomic{ } Machines will differ in their support When we build 1000 instruction transactions, it will not be for free…
11
Software Transactional Memory Implement transactions in Software All the flexibility of hardware…today Ability to extend hardware when it is available (Hybrid TM) But there are problems: –Performance? –Ease of programming (software engineering)? –Mechanical code transformation?
12
The Breif History of STM 1993 STM (Shavit,Touitou) 2003 DSTM (Herlihy et al) 2003 WSTM (Fraser, Harris) Lock-free 2003 OSTM (Fraser, Harris) 2004 ASTM (Marathe et al) 2004 T-Monitor (Jagannathan…) Obstruction-free Lock-based 2005 Lock-OSTM (Ennals) 2004 HybridTM (Moir) 2004 Meta Trans (Herlihy, Shavit) 2005 McTM (Saha et al) 2006 AtomJava (Hindman…) 1997 Trans Support TM (Moir) 2005 TL (Dice, Shavit))
13
As Good As Fine Grained Postulate (i.e. take it or leave it): If we could implement fine-grained locking with the same simplicity of course grained, we would never think of building a transactional memory. Implication: Lets try to provide TMs that get as close as possible to hand-crafted fine-grained locking.
14
Premise of Lock-based STMs 1.Memory Lifecycle: work with GC or any malloc/free 2.Transactification: allow mechanical transformation of sequential code 3.Performance: match fine grained 4.Safety: work on coherent state Unfortunately: Hybrid, Ennals, Saha, AtomJava deliver only 2 and 3 (in some cases)…
15
Transactional Locking TL2 Delivers all four properties How ? - Unlike all prior algs: use Commit time locking instead of Encounter order locking - Introduce Version Clock mechanism for validation
16
TL Design Choices Map Array of Versioned- Write-Locks Application Memory PS = Lock per Stripe (separate array of locks) PO = Lock per Object (embedded in object) V#
17
Encounter Order Locking (Undo Log) 1.To Read: load lock + location 2.Check unlocked add to Read-Set 3.To Write: lock location, store value 4.Add old value to undo-set 5.Validate read-set v#’s unchanged 6.Release each lock with v#+1 V# 0 X V# 1 V# 0 Y V# 1 V# 0 Mem Locks V#+1 0 V# 0 V#+1 0 V# 0 V#+1 0 V# 0 X Y Quick read of values freshly written by the reading transaction [Ennals,Hybrid,Saha,Harris,…]
18
Commit Time Locking (Write Buff) 1.To Read: load lock + location 2.Location in write-set? (Bloom Filter) 3.Check unlocked add to Read-Set 4.To Write: add value to write set 5.Acquire Locks 6.Validate read/write v#’s unchanged 7.Release each lock with v#+1 V# 0 Mem Locks V#+1 0 V# 0 Hold locks for very short duration V# 1 X Y V#+1 0 V# 1 V#+1 0 V# 0 V#+1 0 V# 0 V#+1 0 V# 0 X Y [TL,TL2]
19
Why COM and not ENC? 1.Under low load they perform pretty much the same. 2.COM withstands high loads (small structures or high write %). ENC does not withstand high loads. 3.COM works seamlessly with Malloc/Free. ENC does not work with Malloc/Free.
20
COM vs. ENC High Load ENC Hand MCS COM Red-Black Tree 20% Delete 20% Update 60% Lookup
21
COM vs. ENC Low Load COM ENC Hand MCS Red-Black Tree 5% Delete 5% Update 90% Lookup
22
Obnoxious Statement About Benchmarking Pick sequential algorithms and show how they do when parallelized Please no more Specjbb, Splash… Compare to other STMs and hand- crafted fine-grained implementations
23
COM: Works with Malloc/Free PS Lock Array A B To free B from transactional space: 1.Wait till its lock is free. 2.Free(B) B is never written inconsistently because any write is preceded by a validation while holding lock V# VALIDATE X FAILS IF INCONSISTENT
24
ENC: Fails with Malloc/Free PS Lock Array A B Cannot free B from transactional space because undo-log means locations are written after every lock acquisition and before validation. Possible solution: validate after every lock acquisition (yuck) V# VALIDATE X
25
Problem: Application Safety 1.All current lock based STMs work on inconsistent states. 2.They must introduce validation into user code at fixed intervals or loops, use traps, OS support,… 3.And still there are cases, however rare, where an error could occur in user code…
26
Solution: TL2’s “Version Clock” Have one shared global version clock Incremented by (small subset of) writing transactions Read by all transactions Used to validate that state worked on is always consistent Later: how we learned not to worry about contention and love the clock
27
Version Clock: Read-Only COM Trans 1.RV VClock 2.On Read: read lock, read mem, read lock: check unlocked, unchanged, and v# <= RV 3.Commit. 87 0 34 0 88 0 V# 0 44 0 V# 0 34 0 99 0 50 0 Mem Locks Reads form a snapshot of memory. No read set! 100 VClock 87 0 34 0 99 0 50 0 87 0 34 0 88 0 V# 0 44 0 V# 0 99 0 50 0
28
Version Clock: Writing COM Trans 1.RV VClock 2.On Read/Write: check unlocked and v# <= RV then add to Read/Write-Set 3.Acquire Locks 4.WV = F&I(VClock) 5.Validate each v# <= RV 6.Release locks with v# WV Reads+Inc+Writes =Linearizable 100 VClock 87 0 34 0 88 0 44 0 V# 0 34 0 99 0 50 0 Mem Locks 87 0 34 0 99 0 50 0 34 1 99 1 87 0 X Y Commit 121 0 50 0 87 0 121 0 88 0 V# 0 44 0 V# 0 121 0 50 0 100 RV 100120121 X Y
29
Version Clock Implementation On sys-on-chip like Sun T200™ Niagara: virtually no contention, just CAS and be happy On others: add TID to VClock, if VClock has changed since last write can use new value +TID. Reduces contention by a factor of N. Future: Coherent Hardware VClock that guarantees unique tick per access.
30
Performance Benchmarks Mechanically Transformed Sequential Red-Black Tree using TL2 Compare to STMs and hand-crafted fine-grained Red-Black implementation On a 16–way Sun Fire™ running Solaris™ 10
31
Uncontended Large Red-Black Tree 5% Delete 5% Update 90% Lookup Hand- crafted TL/PS TL2/PS TL/PO TL2/P0 Ennals Farser Harris Lock- free
32
Uncontended Small RB-Tree 5% Delete 5% Update 90% Lookup TL/P0 TL2/P0
33
Contended Small RB-Tree 30% Delete 30% Update 40% Lookup Ennals TL/P0 TL2/P0
34
Speedup: Normalized Throughput Hand- Crafted TL/PO Large RB-Tree 5% Delete 5% Update 90% Lookup
35
Overhead Overhead Overhead STM scalability is as good if not better than hand-crafted, but overheads are much higher Overhead is the dominant performance factor – bodes well for HTM Read set and validation cost (not locking cost) dominates performance
36
On Sun T200™ (Niagara): maybe a long way to go… RB-tree 5% Delete 5% Update 90% Lookup Hand- crafted STMs
37
Detail of RB-tree STMs Only RB-tree 5% Delete 5% Update 90% Lookup
38
Conclusions COM time locking, implemented efficiently, has clear advantages over ENC order locking: –No meltdown under contention –Working seamlessly with malloc/free VCounter can guarantee safety so we –don’t need to embed repeated validation in user code
39
What Next? Further improve performance Make TL1 and TL2 library available Mechanical code transformation tool… Cut read-set and validation overhead, maybe with hardware support? Add hardware VClock to Sys-on-chip.
40
Thank You
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.