Upload
yolanda-russell
View
49
Download
3
Embed Size (px)
DESCRIPTION
Commutativity and Coarse-Grained Transactions. Maurice Herlihy Brown University Joint work with Eric Koskinen and Matthew Parkinson (POPL 10). Moore’s Law. Transistor count still rising. Clock speed flattening sharply. (hat tip: Herb Sutter). The Multicore Processor. More processors, - PowerPoint PPT Presentation
Citation preview
Commutativity andCoarse-Grained
Transactions
Maurice HerlihyBrown University
Joint work with Eric Koskinen and Matthew Parkinson (POPL 10)
2CCDP February 2011
Moore’s Law
(hat tip: Herb Sutter)
Clock speed
flattening sharply
Transistor count still
rising
3CCDP February 2011 3
The Multicore Processor
cache
BusBus
shared memory
cachecache
More processors,Same clock
Sun T2000Niagara
4CCDP February 2011
What Keeps Microsoft and Intel awake at Night?
• If more cores does not deliver more value …
• Then why upgrade??
5CCDP February 2011
Washing Machine Science?
• Computers could become like washing machines
• You don’t trade it in every 2 years for a cooler model
• You keep it until it breaks.
6CCDP February 2011
What could possibly go wrong?
• Concurrent programming is hard• Locks, monitors, etc. do not scale
– Confusing– Subject to deadlock– Relies on conventions– Not composable– …
7CCDP February 2011
The Transactional Manifesto
• Threads + locking don’t scale• Replace locking with a
transactional API • Promising … but not there yet
8CCDP February 2011
Challenge
• Do transactions provide enough concurrency?– As implemented, arguably No.
• Does the transactional model provide enough concurrency?– Arguably, Yes.
TMW April 2010
Skew Heaps
0
1
Tree with “heap”
property2
43
TMW April 2010
Concurrent Skew Heap
0
1 3
54
2
Insert me!
6
Insert me!
TMW April 2010
Concurrent Skew Heap
0
1 3
54
2 6 Lock parent
Swap R & L
TMW April 2010
Concurrent Skew Heap
0
1 3
54
6
Lock right child
Unlock parent2
TMW April 2010
Concurrent Skew Heap
0
1 3
54
6
2
No global rebalancingNo global rebalancing
Good amortized performanceGood amortized performance
Good concurrencyGood concurrency
TMW April 2010
Transactional Skew Heap
0
1 3
54
2
Insert me!
6
Insert me!
TMW April 2010
Transactional Skew Heap
0
1 3
54
2 6
I wrote
0
Write-write
conflict!
Good concurrency with lockingGood concurrency with locking
Not with transactions …Not with transactions …
Confusion betweenthread-level & transaction-level synchronization
Confusion betweenthread-level & transaction-level synchronization
TMW April 2010
Coarse-Grained Synchronization
Synchronize on high-level operations,Like add(), remove(), etc. …
Not low-level reads and writes
Synchronize on high-level operations,Like add(), remove(), etc. …
Not low-level reads and writesPessimistic: update in place, undo on abortPessimistic: update in place, undo on abort
Optimistic: update private copy, apply changes on commit
Optimistic: update private copy, apply changes on commit
But what is the meaning of conflict?
But what is the meaning of conflict?
TMW April 2010
Pessimistic Boosting
transactions
Abstract locks Black-box linearizable data
object
Undo Logs
TMW April 2010
Pessimistic Boosting
transactions
Abstract locks Black-box linearizable data
object
Undo Logs
add(x)
TMW April 2010
Pessimistic Boosting
transactions
Abstract locks Black-box linearizable data
object
Undo Logs
add(x)
TMW April 2010
Pessimistic Boosting
transactions
Abstract locks Black-box linearizable data
object
Undo Logs
add(x)
TMW April 2010
Pessimistic Boosting
transactions
Abstract locks Black-box linearizable data
object
rem(x)
Undo Logs
add(x)
x
TMW April 2010
Pessimistic Boosting
transactions
Abstract locks Black-box linearizable data
object
rem(x)
Undo Logs
add(x)
x
add(y)
y
TMW April 2010
Pessimistic Boosting
transactions
Abstract locks Black-box linearizable data
object
rem(x)
Undo Logs
add(x)
x
member(x)
TMW April 2010
Pessimistic BoostingThread-safe base objectThread-safe base object
Updated in placeUpdated in placeLog InversesLog InversesConflicting operations blocked by abstract locksConflicting operations blocked by abstract locks
What does it mean for operations to conflict?What does it mean for operations to conflict?
TMW April 2010
Optimistic Boosting
Black-box linearizable data
object
TMW April 2010
Optimistic Boosting
private copies
Black-box linearizable data
object
TMW April 2010
Optimistic Boostingredo logs
private copies
Black-box linearizable data
object
TMW April 2010
Optimistic Boostingredo logs
private copies
Black-box linearizable data
object
add(x)
TMW April 2010
Optimistic Boostingadd(x)
redo logs
private copies
Black-box linearizable data
object
add(x)
x
TMW April 2010
Optimistic Boostingadd(x) add(y)
redo logs
private copies
Black-box linearizable data
object
add(x)
x
add(y)
y
TMW April 2010
On Commitadd(x) add(y)
redo logs
private copies
Black-box linearizable data
object
x y
add(x)
add(x)
TMW April 2010
On Commitadd(x) add(y)
redo logs
private copies
Black-box linearizable data
object
x y
add(x)
add(x)
No conflict, apply
updates to my copy
x
x
TMW April 2010
On Commitadd(x) add(y)
x y
add(x)
add(x)
x
x
Different physical values,Same logical values
TMW April 2010
On Commitadd(x) rem(x)
redo logs
private copies
Black-box linearizable data
object
x
add(x)
add(x)
Conflict! Abort & restore my copy
x
TMW April 2010
Optimistic BoostingThread-local object copiesThread-local object copies
Deferred operatons kept in redo logDeferred operatons kept in redo log
No inversesNo inversesOn commit, broadcast deferred operations
To other transactions, public copy
On commit, broadcast deferred operationsTo other transactions, public copyTransactions snoop on broadcast,
Abort if conflict detected
Transactions snoop on broadcast,Abort if conflict detected
What does it mean for operations to conflict?What does it mean for operations to conflict?
TMW April 2010
Left-Movers
time
legal history
TMW April 2010
Left-Movers
time
If and are adjacent,Ok to move earlier
Left-Mover Example: Semaphore
time
inc()dec() dec()
1 0 1 0
Inc() is Left-mover WRT Dec()
time
inc() dec() dec()
1 10 01 02 11
Same sequence of calls(results unaffected)
Left-Mover Example: Semaphore
time
inc() dec() dec()
1 10 01 02 11
Same final state
Left-Mover Example: Semaphore
time
inc() dec() dec()
3 23 23 24 33
Left-Mover Counter-example
time
1
dec()
0
inc()
1
dec()
0
Dec() not Left-Mover WRT Inc()
time
1
dec()
0
inc()
1
dec()
0-1
Right-Movers
time
legal history
Right-Movers
time
If and are adjacent,Ok to move later
Commutativity
time
If and are adjacent,Ok to swap
47
Pessimistic Semantics(modify shared state in place)
time
Txn B beg
Txn A beg
Pessimistic Commit: Move Left of pending
cmt
48
Pessimistic Semantics(modify shared state in place)
time
Txn B beg
Txn A beg abt
49
Pessimistic Semantics(modify shared state in place)
time
3
Txn B beg
Txn A beg 1 2 4
Pessimistic Abort: Move Right of pending
24 3 1
Pessimistic Abort: Pending ops move Left
50
Optimistic Semantics(modify local copies; merge)
time
Txn B
Txn A beg
Optimistic Commit: Move Right of committed
cmt
cmt
51
Optimistic Semantics(modify local copies; merge)
time
Txn B
Txn A beg
Optimistic Abort: Discard Operations
abt
cmt
Pessimistic Optimistic
Two Execution Models
52
Left-Moverness Right-MovernessAlgebraic Abstract
Properties
53
But …
• Are commutativity+inverses the limit?– Other algebraic properties?
• Abstract locks are blocking– may cause multiple transactions– may block on same lock
54
Example
atomic { with (abstractLock(3)){ if (skiplist.insert(3)) { self.onAbort.add( (λ() skiplist.remove(3))) } } bigComputation(); }
Lock key 3
55
Example
atomic { with (abstractLock(3)){ if (skiplist.insert(3)) { self.onAbort.add( (λ() skiplist.remove(3))) } } bigComputation(); }
Add value 3
56
Example
atomic { with (abstractLock(3)){ if (skiplist.insert(3)) { self.onAbort.add( (λ() skiplist.remove(3))) } } bigComputation(); }
If set modified,Log inverse
57
Example
atomic { with (abstractLock(3)){ if (skiplist.insert(3)) { self.onAbort.add( (λ() skiplist.remove(3))) } } bigComputation(); }
Do something long,Not involving skiplist
58
Conflicting Operations
remove(3)
insert(3)
no conflict
59
Conflicting Locks
remove(3)
insert(3)
(3)
(3)
No concurrency
60
Conflicting Locks
insert(3)
(3)
remove(3)
(3)
61
Conflicting Locks
insert(3)
(3)
remove(3)
(3)
62
Conflicting Locks
insert(3)
(3)
remove(3)
(3)
Lock handoff
63
Lock Handoff
dependence
64
Lock Handoff
dependence Lock handoff
65
Key Ideas
• Handing off Abstract lock• Allows concurrent non-commuting
boosted transactions!• Novel ideas
– Mechanism for passing abstract lock– Thread-local cyclic dependency check– Lazy recovery
66
Deadlock?
67
Detection
• Dreadlocks– [Herlihy & Koskinen, SPAA 2008]
• Fast, incremental deadlock detection
• Low overhead• Cache-friendly
68
Waits-For Graph
waiting owned
69
Digest
70
Digest
71
Digest
Uh-oh!
72
Details
• Can represent digest as– Bit map (small population)– Bloom filter (larger population)
• [Herlihy & Koskinen, SPAA 2008]
Challenges
• Automation?– Theorem proving– Model checking
• Compiler & Language support?• Implementation …