SLIDE 1 Designing, Modeling, and Optimizing Transactional Data Structures
Ahmed Hassan
Electrical and Computer Engineering Department Virginia Tech September 1, 2015
PhD Dissertation Defense
SLIDE 2 State of the Art
Multi-core architectures. Synchronization
– Critical sections. – Using locks.
Efficient synchronization:
– Cache coherence protocols. – Atomic instructions (e.g. CAS operations).
From www.microway.com
SLIDE 3
Concurrent Data Structures Concurrent Data Structures
SLIDE 4
Example: Linked List
10 5 2 70 60 50
SLIDE 5
Example: Linked List
10 5 2 70 60 50 55
X
7
X
T1 T2
SLIDE 6 Synchronization in Concurrent Data Structures
Coarse-grained locking
– Easy to implement, good for low number of small threads . – But minimizes concurrency.
Fine-grained locking
– Allows more concurrency. – But error prone.
Non-Blocking Designs
– Lock-free, obstruction-free, wait-free, … – Progress guarantees But more complex designs.
SLIDE 7 Transactional Memory
Use an underlying TM framework to guarantee consistency,
atomicity, and isolation.
Programmable (like coarse-grained locking). Allows concurrency (like fine-grained locking).
Thread 1
@Atomic foo1() { seqList.add(5) }
SLIDE 8 Transactional Memory Gains Traction!!
Intel Haswell's TSX Extensions. IBM Power8. STM support in C++ and GCC.
SLIDE 9 What about data structures?
New APIs New synchronization
primitives.
New TM libraries New compiler
support.
New hardware
components.
Transactional Programming Model Concurrent Data Structures
Customized Designs Optimizations Different Primitives
SLIDE 10 What about data structures?
New APIs New synchronization
primitives.
New TM libraries New compiler
support.
New hardware
components.
Transactional Programming Model Concurrent Data Structures
Customized Designs Optimizations Different Primitives
Simpler interface
less complex designs
SLIDE 11 What about data structures?
Transactional Programming Model Concurrent Data Structures
Customized Designs Optimizations Different Primitives
Simpler interface
less complex designs
Atomic transaction
instead of atomic operations
New APIs New synchronization
primitives.
New TM libraries New compiler
support.
New hardware
components.
SLIDE 12 What about data structures?
Transactional Programming Model Concurrent Data Structures
Customized Designs Optimizations Different Primitives
Simpler interface
less complex designs
Atomic transaction
instead of atomic operations
Hardware Support
possible performance improvement
New APIs New synchronization
primitives.
New TM libraries New compiler
support.
New hardware
components.
SLIDE 13
Our Goal
From Concurrent to Transactional Data Structures
Our Goal
From Concurrent to Transactional Data Structures
SLIDE 14 Challenges
Composability. Integration with generic transactions. Modeling.
SLIDE 15 Composability
Shared data: concurrentList atomicFoo() { concurrentList.add(x); concurrentList.add(y); } Shared data: concurrentList1 Shared data: concurrentList2 atomicFoo() { concurrentList1.remove(x); concurrentList2.add(x); } Shared data: concurrentList atomicFoo() { concurrentList.add(x); }
SLIDE 16 Composability
Shared data: concurrentList atomicFoo() { concurrentList.add(x); concurrentList.add(y); } Shared data: concurrentList1 Shared data: concurrentList2 atomicFoo() { concurrentList1.remove(x); concurrentList2.add(x); } Shared data: concurrentList atomicFoo() { concurrentList.add(x); }
Modify the design of concurrentList? More complex designs
SLIDE 17 Composability
Shared data: concurrentList atomicFoo() { concurrentList.add(x); concurrentList.add(y); } Shared data: concurrentList1 Shared data: concurrentList2 atomicFoo() { concurrentList1.remove(x); concurrentList2.add(x); } Shared data: concurrentList atomicFoo() { concurrentList.add(x); }
Modify the design of concurrentList? More complex designs Transactional Memory? Lose optimizations of concurrentList
SLIDE 18 Integration
Shared data: concurrentList atomicFoo() { If(concurrentList.add(x)) n1++; Else n2++; }
SLIDE 19 Modeling
Different Designs and Implementations
– Different ad-hoc approaches for proving correctness.
Is there a unified model for concurrent data
structures? – General enough – Easy to use – Includes composability and integration
SLIDE 20
Our Contributions Our Contributions
SLIDE 21 Our Contributions
Transactional Data Structures
Composability Integration Modeling
SLIDE 22 Our Contributions
Transactional Data Structures
Composability Integration Modeling Optimistic Transactional Boosting PPoPP 2014 OTB-Set OPODIS 2014 TxCF-Tree DISC 2015
SLIDE 23 Our Contributions
Transactional Data Structures
Composability Integration Modeling Optimistic Transactional Boosting PPoPP 2014 OTB-Set OPODIS 2014 TxCF-Tree DISC 2015 Integration with STM TRANSACT 2014 Integration with HTM Under submission Remote Transaction Commit IEEE TC 2015 Remote Invalidation IPDPS 2014
SLIDE 24 Our Contributions
Transactional Data Structures
Composability Integration Modeling Optimistic Transactional Boosting PPoPP 2014 OTB-Set OPODIS 2014 TxCF-Tree DISC 2015 SWC and C-SWC Models WTTM 2015, under submission Integration with STM TRANSACT 2014 Integration with HTM Under submission Remote Transaction Commit IEEE TC 2015 Remote Invalidation IPDPS 2014
SLIDE 25 Our Contributions
Transactional Data Structures
Composability Integration Modeling Optimistic Transactional Boosting PPoPP 2014 OTB-Set OPODIS 2014 TxCF-Tree DISC 2015 SWC and C-SWC Models WTTM 2015, under submission Integration with STM TRANSACT 2014 Integration with HTM Under submission Remote Transaction Commit IEEE TC 2015 Remote Invalidation IPDPS 2014
SLIDE 26
Past and Related Work Past and Related Work
SLIDE 27 Past and Related Work
Composability and Integration
– Transactional Memory. – Transactional Boosting.
Modeling
– SWMR Model
SLIDE 28 Past and Related Work
Composability and Integration
– Transactional Memory. – Transactional Boosting.
Modeling
– SWMR Model
SLIDE 29 Transactional Memory
Software Transactional Memory (STM)
– SW meta-data (e.g. read-sets and write-sets) on the current HW.
Hardware Transactional Memory (HTM)
– New HW (modify cache coherency protocols).
Hybrid Transactional Memory (Hybrid TM)
– HTM transactions fall-back to STM
SLIDE 30
TM Limitation: False Conflict
10 5 2 70 60 50 55
X
Example: Linked list (Insert “55”)
SLIDE 31
TM Limitation: False Conflict
10 5 2 70 60 50 55
All “red” nodes are in the read-set “50” and “55” are in the write-set Example: Linked list (Insert “55”)
SLIDE 32
TM Limitation: False Conflict
10 5 2 70 60 50 55
All “red” nodes are in the read-set “50” and “55” are in the write-set What if a concurrent transaction deletes “5”?? Example: Linked list (Insert “55”)
SLIDE 33
TM Limitation: False Conflict
10 5 2 70 60 50 55
All “red” nodes are in the read-set “50” and “55” are in the write-set What if a concurrent transaction deletes “5”??
False Conflict
Example: Linked list (Insert “55”)
SLIDE 34 Transactional Boosting
Convert highly concurrent data structures to be transactional. Composable (like STM) And efficient (like lazy/lock-free linked-list)
34
SLIDE 35 Transactional Boosting
Convert highly concurrent data structures to be transactional. Composable (like STM) And efficient (like lazy/lock-free linked-list) Issues:
–
Eager locking.
–
Inverse operations.
–
Black-box concurrent data structure.
–
No Straightforward Integration
35
SLIDE 36
Optimistic Transactional Boosting Optimistic Transactional Boosting
SLIDE 37 Past Solutions
Sequential Tree
TM-BEGIN TM-END
Concurrent Tree
Acquire Semantic Locks Release Semantic Locks
Transactional Memory Transactional Boosting
SLIDE 38 Past Solutions
TM-BEGIN TM-END Acquire Semantic Locks Release Semantic Locks
Transactional Memory Transactional Boosting
Sequential Tree Concurrent Tree
SLIDE 39 Past Solutions
Sequential Tree
TM-BEGIN TM-END
Concurrent Tree
Acquire Semantic Locks Release Semantic Locks
Transactional Memory Transactional Boosting
General, BUT not optimized.
SLIDE 40
Concurrent Operation (add, remove, contains, ...)
OTB's Three Guidelines
SLIDE 41
Traversal (long - unmonitored) Commit (short - monitored) Concurrent Operation (add, remove, contains, ...)
OTB's Three Guidelines
SLIDE 42
OTB's Three Guidelines
SLIDE 43 Traversal(Op1)
Commit(op1) Traversal(Op2) Commit(op2) Atomic Block (Tx)
OTB's Three Guidelines
SLIDE 44 Traversal(Op1)
Commit(op1) Traversal(Op2) Commit(op2) Atomic Block (Tx) Traversal(Op1)
Commit(op2)
Traversal(Op2)
Commit(op1)
Traversal(Tx) Commit(Tx)
OTB's Three Guidelines
SLIDE 45
OTB's Three Guidelines
SLIDE 46
–
Specific to each data structure.
–
Linked-list-based Set.
–
Skip-list-based Set.
–
Skip-list-based Priority Queue.
–
Balanced Tree
OTB's Three Guidelines
SLIDE 47
–
Specific to each data structure.
–
Linked-list-based Set.
–
Skip-list-based Set.
–
Skip-list-based Priority Queue.
–
Balanced Tree
OTB's Three Guidelines
SLIDE 48 Lazy Vs Boosting Vs Optimistic Boosting
48
SLIDE 49
Example Bootsing “lazy” concurrent linked list Example Bootsing “lazy” concurrent linked list
SLIDE 50 Concurrent Non-optimized Transactional G1 & G2 Optimized Transactional G3
OTB Methodology
50
General Data Structure Specific
SLIDE 51 Example
Lazy Linked list (Insert “55”)
10 5 2 70 60 50
51
SLIDE 52 Example
Lazy Linked list (Insert “55”) Traversal (unmonitored)
10 5 2 70 60 50
52
SLIDE 53 Example
Lazy Linked list (Insert “55”) Traversal (unmonitored) Validation
10 5 2 70 60 50
53
SLIDE 54 Example
Lazy Linked list (Insert “55”) Traversal (unmonitored) Validation Commit
10 5 2 70 60 50
54
55
X
SLIDE 55 To Make it Transactional
Results of traversal are saved in local objects:
–
Semantic read-set: to be validated.
–
Semantic write-set: to be published at commit.
SLIDE 56 To Make it Transactional
Example: Linked list (Insert “55”)
10 5 2 70 60 50
SLIDE 57 To Make it Transactional
Example: Linked list (Insert “55”)
10 5 2 70 60 50
read-set entry
write-set entry
SLIDE 58 To Make it Transactional
Example: Linked list (Insert “55”)
Guidelines to guarantee opacity (see OPODIS'14 paper)
10 5 2 70 60 50
read-set entry
write-set entry
SLIDE 59 Example optimizations on Linked-List and Skip-List
–
Local elimination:
- Ex. Add(x) then Remove(x).
- No need to access the shared data structure.
Specific Optimizations
SLIDE 60 Results Skip-list 512 Nodes 5 ops/transaction Skip-list 64K Nodes 5 ops/transaction
60
SLIDE 61
Transactional Interference-less Balanced Tree Transactional Interference-less Balanced Tree
SLIDE 62 Transactional Interference-less Balanced Trees
- Transactional: Functionality (following OTB's G1, G2).
- Interference-less: Performance (following OTB's G3).
SLIDE 63 The Next Question
- Which concurrent balanced tree design fits OTB?
SLIDE 64 The Next Question
- Which concurrent balanced tree design fits OTB?
Contention-Friendly Tree
Crain, Gramoli, & Raynal'13
SLIDE 65 CF-Tree
10 20 10 20 30 20 30 10
SLIDE 66 CF-Tree
10 20 10 20 30 20 30 10
{10, 20} {10, 20, 30} {10, 20, 30}
SLIDE 67 CF-Tree
10 20 10 20 30 20 30 10
{10, 20} {10, 20, 30} {10, 20, 30}
Semantic Structural
SLIDE 68 CF-Tree
10 20 10 20 30 20 30 10
{10, 20} {10, 20, 30} {10, 20, 30}
Semantic Structural
Application Thread Helper Thread
SLIDE 69
Our Proposal
Transactionalizing CF-Tree using OTB (TxCF-Tree)
SLIDE 70 TxCF-Tree
10 20 10 20 30 20 30 10 Application Thread Helper Thread
SLIDE 71 TxCF-Tree
10 20 10 20 30 20 30 10 Application Thread Helper Thread
SLIDE 72 TxCF-Tree
10 20 Application Thread
SLIDE 73 TxCF-Tree
10 20 Application Thread unmonitored traversal
SLIDE 74 TxCF-Tree
10 20 Application Thread unmonitored traversal Lock & Validate
SLIDE 75 TxCF-Tree
10 20 30 Application Thread unmonitored traversal Lock & Validate Insert
SLIDE 76 TxCF-Tree
10 20 30 Application Thread unmonitored traversal Lock & Validate Insert Commit Traversal
SLIDE 77 Remove is similar...
20 10 30 10 20(d) 30 10 30
{10, 20, 30} {10, 20} {10, 20}
Semantic Structural Application Thread Helper Thread
SLIDE 78 Remove is similar...
20 10 30 10 20(d) 30 10 30
{10, 20, 30} {10, 20} {10, 20}
Semantic Structural Application Thread Helper Thread
SLIDE 79 Remove is similar...
10 20(d) 30 Application Thread unmonitored traversal Lock & Validate Mark as “d” Commit Traversal
SLIDE 80
Transactional Interference-less Tree
SLIDE 81 Transactional Interference-less Tree
–
Step 1: CF-Tree!!
–
Step 2: Always give the highest priority to semantic operations over structural operations.
SLIDE 82 Transactional Interference-less Tree
–
Step 1: CF-Tree!!
–
Step 2: Always give the highest priority to semantic operations over structural operations.
–
Aborting transactions rolls back all its operations (including the non-conflicting ones).
–
Long transactions are more prone to interfere with the helper thread.
SLIDE 83 Two building blocks
- Structural Locks.
- Structural Invalidation.
SLIDE 84
Structural Locks
SLIDE 85 Structural Locks
10 20 30
- Transaction T1 wants to delete 30.
- after traversal and before commit, assume 2 scenarios
A concurrent rotation
10 20 30
A concurrent delete(30)
SLIDE 86 Structural Locks
10 20 30
- Transaction T1 wants to delete 30.
- after traversal and before commit, assume 2 scenarios
A concurrent rotation
10 20 30
A concurrent delete(30)
SLIDE 87 Structural Locks
10 20 30
- Transaction T1 wants to delete 30.
- after traversal and before commit, assume 2 scenarios
A concurrent rotation
10 20 30
A concurrent delete(30) T1 observes that “30” is locked What is the best to do in both cases?
SLIDE 88 Structural Locks
10 20 30
- Transaction T1 wants to delete 30.
- after traversal and before commit, assume 2 scenarios
A concurrent rotation
10 20 30
A concurrent delete(30) T1 observes that “30” is locked What is the best to do in both cases?
Do Nothing Abort
SLIDE 89 Structural Locks
10 20 30
- Transaction T1 wants to delete 30.
- after traversal and before commit, assume 2 scenarios
A concurrent rotation
10 20 30
A concurrent delete(30) Solution?
SLIDE 90 Structural Locks
10 20 30
- Transaction T1 wants to delete 30.
- after traversal and before commit, assume 2 scenarios
A concurrent rotation
10 20 30
A concurrent delete(30)
Structural Locks Semantic Lock
Solution? Two types of locks
SLIDE 91
Structural Invalidation
SLIDE 92 Structural Invalidation
10 20 30
- Transaction T1 wants to insert 15.
- after traversal and before commit, assume 2 scenarios
A concurrent rotation
10 20 30
A concurrent insert(15)
SLIDE 93 Structural Invalidation
- Transaction T1 wants to insert 15.
- after traversal and before commit, assume 2 scenarios
A concurrent rotation
10
A concurrent insert(15)
20 30 15 20 30 10
SLIDE 94 Structural Invalidation
- Transaction T1 wants to insert 15.
- after traversal and before commit, assume 2 scenarios
A concurrent rotation
10
A concurrent insert(15)
20 30 15 20 30 10
T1 observes that the right child of “20” is not NULL What is the best to do in both cases?
SLIDE 95 Structural Invalidation
- Transaction T1 wants to insert 15.
- after traversal and before commit, assume 2 scenarios
A concurrent rotation
10
A concurrent insert(15)
20 30 15 20 30 10
T1 observes that the right child of “20” is not NULL What is the best to do in both cases?
Continue Traversal Abort
SLIDE 96 Structural Invalidation
- Transaction T1 wants to insert 15.
- after traversal and before commit, assume 2 scenarios
A concurrent rotation
10
A concurrent insert(15)
20 30 15 20 30 10
Solution?
SLIDE 97 Structural Invalidation
- Transaction T1 wants to insert 15.
- after traversal and before commit, assume 2 scenarios
A concurrent rotation
10
A concurrent insert(15)
20 30 15 20 30 10
Solution? Continue Traversal anyway
SLIDE 98 Evaluation
AMD 64-cores, size 10K nodes, 50% reads, 5 ops/transaction
SLIDE 99 Evaluation
AMD 64-cores, size: 10K nodes , 32 threads, 50% reads, 5 ops/transaction
SLIDE 100
Modeling Transactional Data Structures Modeling Transactional Data Structures
SLIDE 101 Concurrent Data Structures
- Different Designs and Implementations
–
Different ad-hoc approaches for proving correctness.
- Is there a unified model for concurrent data structures?
–
General enough.
–
Easy to use.
SLIDE 102
SWMR Model (Lev-Ari et. Al, DISC'14)
UO1 UO2 UOn UO3 RO1 RO2
SLIDE 103 Shared States
- Data Structure is represented as a set of shared variables.
- The values of those variables is the shared state of the data
structure. Operation“O”
Pre-state(O) Post-state(O)
SLIDE 104 Local States
- Operation is represented as a set of steps.
- The values of the operation's local variables before any step is
the local state of the step.
Pre-state(O) Post-state(O)
Step1 Step2 Stepn L1 L2 Ln Operation “O”
SLIDE 105 SWMR Scenario
UO1 UO2 UOn UO3 Step1 Step2 Stepn L1 L2 Ln RO
S0 S1 S2 S3 Sn
SLIDE 106
Validity
SLIDE 107 Validity
UO1 UO2 UOn UO3 Step1 Step2 Stepn L1 L2 Ln RO
S0 S1 S2 S3 Sn
SLIDE 108 Validity
- All Si are sequentially reachable, so all UOi are valid.
UO1 UO2 UOn UO3 Step1 Step2 Stepn L1 L2 Ln RO
S0 S1 S2 S3 Sn
SLIDE 109 Validity
- All Si are sequentially reachable, so all UOi are valid.
- Stepi in RO is valid if there is Sj such that a sequential
execution of RO starting from Sj reaches Li. UO1 UO2 UOn UO3 Step1 Step2 Stepn L1 L2 Ln RO
S0 S1 S2 S3 Sn
SLIDE 110 Validity
- All Si are sequentially reachable, so all UOi are valid.
- Stepj in RO is valid if there is Si such that a sequential
execution of RO starting from Si reaches Lj. UO1 UO2 UOn UO3 Step1 Step2 Stepn L1 L2 Ln RO
S0 S1 S2 S3 Sn
SLIDE 111
- All Si are sequentially reachable, so all UOi are valid.
- Stepj in RO is valid if there is Si such that a sequential execution of RO
starting from Si reaches Lj.
- Stepj in RO is valid if there is a “base point” where the “base condition”
- f stepj holds.
Validity
UO1 UO2 UOn UO3 Step1 Step2 Stepn L1 L2 Ln RO
S0 S1 S2 S3 Sn
SLIDE 112 Validity
- How to prove validity for any data structure.
–
Identify the base conditions for each step in each operation (it is sufficient to do so only for steps that access the shared memory).
–
Prove that in any concurrent execution, every step has a base point that satisfies its base condition.
SLIDE 113 Validity
- How to prove validity for any data structure.
–
Identify the base conditions for each step in each operation (it is sufficient to do so only for steps that access the shared memory).
–
Prove that in any concurrent execution, every step has a base point that satisfies its base condition.
SLIDE 114
Regularity
UO1 UO2 UOn UO3 RO1 RO2
SLIDE 115
Regularity
UO1 UO2 UOn UO3 RO1 RO2 UO1 UO2 UOn UO3 RO1 UO1 UO2 UOn UO3 RO2
SLIDE 116 Regularity
UO1 UO2 UOn UO3 RO1 RO2 UO1 UO2 UOn UO3 RO1 UO1 UO2 UOn UO3 RO2
Linearizable Linearizable
SLIDE 117 Regularity
UO1 UO2 UOn UO3 Step1 Step2 Stepn RO
S0 S1 S2 S3 Sn
SLIDE 118 Regularity
- Acceptable base points for RO's return step are only S1, S2, S3.
– Observes either the last update or a concurrent update.
UO1 UO2 UOn UO3 Step1 Step2 Stepn Ln RO
S0 S1 S2 S3 Sn
SLIDE 119
Example
SLIDE 120
Example
SLIDE 121
Example
SLIDE 122
Where is the Problem? It covers only single-writer designs It does not cover composable designs Can we cover a wider set? Optimistic Composable Data Structures
SLIDE 123
Our Models Single Writer Commit (SWC) Composable SWC (C-SWC)
SLIDE 124
SWC Model
UO1 Step1 Step2 Stepn RO UO2 UO3 UO5 UO4
SLIDE 125
SWC Model
Step1 Step2 Stepn RO T4 C4 T1 C1 T2 C2 T3 C3 T5 C5
SLIDE 126 SWC Model
T4 C4 T1 C1 T2 C2 T3 C3 T5 C5
S0 S1 S2 S3 S5 S4
Step1 Step2 Stepn RO
SLIDE 127 SWC Model
T4 C4 T1 C1 T2 C2 T3 C3 T5 C5
S0 S1 S2 S3 S5 S4
Step1 Step2 Stepn L1 L2 Ln RO
L1 L2 Ln L1 L2 Ln L1 L2 Ln L1 L2 Ln L1 L2 Ln
SLIDE 128 Even More...
- Do we really need single commit at a time:
–
NO!!!
–
It is enough to execute commit phases atomically with single lock atomicity (SLA) guarantees.
–
More practical alternatives:
- HTM (e.g. Intel TSX).
- STM (e.g. NOrec “the SLA version”).
SLIDE 129
Example
SLIDE 130
Example
SLIDE 131
Example
SLIDE 132
Composable SWC Model (C-SWC)
SLIDE 133 Composable SWC Model (C-SWC)
Traversal(Op1) Commit(op1) Traversal(Op2) Commit(op2) Atomic Block (Tx) Traversal(Op1)
Commit(op2)
Traversal(Op2)
Commit(op1)
Traversal(Tx) Commit(Tx)
SLIDE 134 What is remaining?
–
The commit phase of each operation reflects what the operation
- bserved in its traversal.
–
The shared state of an operation is visible to subsequent operations in the same transaction.
SLIDE 135 How to prove internal consistency?
Traversal(Op1)
Commit(op2)
Traversal(Op2)
Commit(op1)
SLIDE 136 How to prove internal consistency?
Traversal(Op1)
Commit(op2)
Traversal(Op2)
Commit(op1)
L L L
Have the same base point
SLIDE 137
Conclusions Conclusions
SLIDE 138 Our Contributions
Transactional Data Structures
Composability Integration Modeling Optimistic Transactional Boosting PPoPP 2014 OTB-Set OPODIS 2014 TxCF-Tree DISC 2015 SWC and C-SWC Models WTTM 2015, under submission Integration with STM TRANSACT 2014 Integration with HTM Under submission Remote Transaction Commit IEEE TC 2015 Remote Invalidation IPDPS 2014
SLIDE 139 Thanks!
Questions?
139