73
Commutativity and Coarse-Grained Transactions Maurice Herlihy Brown University Joint work with Eric Koskinen and Matthew Parkinson (POPL 10)

Commutativity and Coarse-Grained Transactions

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

Page 1: Commutativity  and Coarse-Grained  Transactions

Commutativity andCoarse-Grained

Transactions

Maurice HerlihyBrown University

Joint work with Eric Koskinen and Matthew Parkinson  (POPL 10)

Page 2: Commutativity  and Coarse-Grained  Transactions

2CCDP February 2011

Moore’s Law

(hat tip: Herb Sutter)

Clock speed

flattening sharply

Transistor count still

rising

Page 3: Commutativity  and Coarse-Grained  Transactions

3CCDP February 2011 3

The Multicore Processor

cache

BusBus

shared memory

cachecache

More processors,Same clock

Sun T2000Niagara

Page 4: Commutativity  and Coarse-Grained  Transactions

4CCDP February 2011

What Keeps Microsoft and Intel awake at Night?

• If more cores does not deliver more value …

• Then why upgrade??

Page 5: Commutativity  and Coarse-Grained  Transactions

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.

Page 6: Commutativity  and Coarse-Grained  Transactions

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– …

Page 7: Commutativity  and Coarse-Grained  Transactions

7CCDP February 2011

The Transactional Manifesto

• Threads + locking don’t scale• Replace locking with a

transactional API • Promising … but not there yet

Page 8: Commutativity  and Coarse-Grained  Transactions

8CCDP February 2011

Challenge

• Do transactions provide enough concurrency?– As implemented, arguably No.

• Does the transactional model provide enough concurrency?– Arguably, Yes.

Page 9: Commutativity  and Coarse-Grained  Transactions

TMW April 2010

Skew Heaps

0

1

Tree with “heap”

property2

43

Page 10: Commutativity  and Coarse-Grained  Transactions

TMW April 2010

Concurrent Skew Heap

0

1 3

54

2

Insert me!

6

Insert me!

Page 11: Commutativity  and Coarse-Grained  Transactions

TMW April 2010

Concurrent Skew Heap

0

1 3

54

2 6 Lock parent

Swap R & L

Page 12: Commutativity  and Coarse-Grained  Transactions

TMW April 2010

Concurrent Skew Heap

0

1 3

54

6

Lock right child

Unlock parent2

Page 13: Commutativity  and Coarse-Grained  Transactions

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

Page 14: Commutativity  and Coarse-Grained  Transactions

TMW April 2010

Transactional Skew Heap

0

1 3

54

2

Insert me!

6

Insert me!

Page 15: Commutativity  and Coarse-Grained  Transactions

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

Page 16: Commutativity  and Coarse-Grained  Transactions

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?

Page 17: Commutativity  and Coarse-Grained  Transactions

TMW April 2010

Pessimistic Boosting

transactions

Abstract locks Black-box linearizable data

object

Undo Logs

Page 18: Commutativity  and Coarse-Grained  Transactions

TMW April 2010

Pessimistic Boosting

transactions

Abstract locks Black-box linearizable data

object

Undo Logs

add(x)

Page 19: Commutativity  and Coarse-Grained  Transactions

TMW April 2010

Pessimistic Boosting

transactions

Abstract locks Black-box linearizable data

object

Undo Logs

add(x)

Page 20: Commutativity  and Coarse-Grained  Transactions

TMW April 2010

Pessimistic Boosting

transactions

Abstract locks Black-box linearizable data

object

Undo Logs

add(x)

Page 21: Commutativity  and Coarse-Grained  Transactions

TMW April 2010

Pessimistic Boosting

transactions

Abstract locks Black-box linearizable data

object

rem(x)

Undo Logs

add(x)

x

Page 22: Commutativity  and Coarse-Grained  Transactions

TMW April 2010

Pessimistic Boosting

transactions

Abstract locks Black-box linearizable data

object

rem(x)

Undo Logs

add(x)

x

add(y)

y

Page 23: Commutativity  and Coarse-Grained  Transactions

TMW April 2010

Pessimistic Boosting

transactions

Abstract locks Black-box linearizable data

object

rem(x)

Undo Logs

add(x)

x

member(x)

Page 24: Commutativity  and Coarse-Grained  Transactions

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?

Page 25: Commutativity  and Coarse-Grained  Transactions

TMW April 2010

Optimistic Boosting

Black-box linearizable data

object

Page 26: Commutativity  and Coarse-Grained  Transactions

TMW April 2010

Optimistic Boosting

private copies

Black-box linearizable data

object

Page 27: Commutativity  and Coarse-Grained  Transactions

TMW April 2010

Optimistic Boostingredo logs

private copies

Black-box linearizable data

object

Page 28: Commutativity  and Coarse-Grained  Transactions

TMW April 2010

Optimistic Boostingredo logs

private copies

Black-box linearizable data

object

add(x)

Page 29: Commutativity  and Coarse-Grained  Transactions

TMW April 2010

Optimistic Boostingadd(x)

redo logs

private copies

Black-box linearizable data

object

add(x)

x

Page 30: Commutativity  and Coarse-Grained  Transactions

TMW April 2010

Optimistic Boostingadd(x) add(y)

redo logs

private copies

Black-box linearizable data

object

add(x)

x

add(y)

y

Page 31: Commutativity  and Coarse-Grained  Transactions

TMW April 2010

On Commitadd(x) add(y)

redo logs

private copies

Black-box linearizable data

object

x y

add(x)

add(x)

Page 32: Commutativity  and Coarse-Grained  Transactions

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

Page 33: Commutativity  and Coarse-Grained  Transactions

TMW April 2010

On Commitadd(x) add(y)

x y

add(x)

add(x)

x

x

Different physical values,Same logical values

Page 34: Commutativity  and Coarse-Grained  Transactions

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

Page 35: Commutativity  and Coarse-Grained  Transactions

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?

Page 36: Commutativity  and Coarse-Grained  Transactions

TMW April 2010

Left-Movers

time

legal history

Page 37: Commutativity  and Coarse-Grained  Transactions

TMW April 2010

Left-Movers

time

If and are adjacent,Ok to move earlier

Page 38: Commutativity  and Coarse-Grained  Transactions

Left-Mover Example: Semaphore

time

inc()dec() dec()

1 0 1 0

Page 39: Commutativity  and Coarse-Grained  Transactions

Inc() is Left-mover WRT Dec()

time

inc() dec() dec()

1 10 01 02 11

Page 40: Commutativity  and Coarse-Grained  Transactions

Same sequence of calls(results unaffected)

Left-Mover Example: Semaphore

time

inc() dec() dec()

1 10 01 02 11

Page 41: Commutativity  and Coarse-Grained  Transactions

Same final state

Left-Mover Example: Semaphore

time

inc() dec() dec()

3 23 23 24 33

Page 42: Commutativity  and Coarse-Grained  Transactions

Left-Mover Counter-example

time

1

dec()

0

inc()

1

dec()

0

Page 43: Commutativity  and Coarse-Grained  Transactions

Dec() not Left-Mover WRT Inc()

time

1

dec()

0

inc()

1

dec()

0-1

Page 44: Commutativity  and Coarse-Grained  Transactions

Right-Movers

time

legal history

Page 45: Commutativity  and Coarse-Grained  Transactions

Right-Movers

time

If and are adjacent,Ok to move later

Page 46: Commutativity  and Coarse-Grained  Transactions

Commutativity

time

If and are adjacent,Ok to swap

Page 47: Commutativity  and Coarse-Grained  Transactions

47

Pessimistic Semantics(modify shared state in place)

time

Txn B beg

Txn A beg

Pessimistic Commit: Move Left of pending

cmt

Page 48: Commutativity  and Coarse-Grained  Transactions

48

Pessimistic Semantics(modify shared state in place)

time

Txn B beg

Txn A beg abt

Page 49: Commutativity  and Coarse-Grained  Transactions

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

Page 50: Commutativity  and Coarse-Grained  Transactions

50

Optimistic Semantics(modify local copies; merge)

time

Txn B

Txn A beg

Optimistic Commit: Move Right of committed

cmt

cmt

Page 51: Commutativity  and Coarse-Grained  Transactions

51

Optimistic Semantics(modify local copies; merge)

time

Txn B

Txn A beg

Optimistic Abort: Discard Operations

abt

cmt

Page 52: Commutativity  and Coarse-Grained  Transactions

Pessimistic Optimistic

Two Execution Models

52

Left-Moverness Right-MovernessAlgebraic Abstract

Properties

Page 53: Commutativity  and Coarse-Grained  Transactions

53

But …

• Are commutativity+inverses the limit?– Other algebraic properties?

• Abstract locks are blocking– may cause multiple transactions– may block on same lock

Page 54: Commutativity  and Coarse-Grained  Transactions

54

Example

atomic { with (abstractLock(3)){ if (skiplist.insert(3)) { self.onAbort.add( (λ() skiplist.remove(3))) } } bigComputation(); }

Lock key 3

Page 55: Commutativity  and Coarse-Grained  Transactions

55

Example

atomic { with (abstractLock(3)){ if (skiplist.insert(3)) { self.onAbort.add( (λ() skiplist.remove(3))) } } bigComputation(); }

Add value 3

Page 56: Commutativity  and Coarse-Grained  Transactions

56

Example

atomic { with (abstractLock(3)){ if (skiplist.insert(3)) { self.onAbort.add( (λ() skiplist.remove(3))) } } bigComputation(); }

If set modified,Log inverse

Page 57: Commutativity  and Coarse-Grained  Transactions

57

Example

atomic { with (abstractLock(3)){ if (skiplist.insert(3)) { self.onAbort.add( (λ() skiplist.remove(3))) } } bigComputation(); }

Do something long,Not involving skiplist

Page 58: Commutativity  and Coarse-Grained  Transactions

58

Conflicting Operations

remove(3)

insert(3)

no conflict

Page 59: Commutativity  and Coarse-Grained  Transactions

59

Conflicting Locks

remove(3)

insert(3)

(3)

(3)

No concurrency

Page 60: Commutativity  and Coarse-Grained  Transactions

60

Conflicting Locks

insert(3)

(3)

remove(3)

(3)

Page 61: Commutativity  and Coarse-Grained  Transactions

61

Conflicting Locks

insert(3)

(3)

remove(3)

(3)

Page 62: Commutativity  and Coarse-Grained  Transactions

62

Conflicting Locks

insert(3)

(3)

remove(3)

(3)

Lock handoff

Page 63: Commutativity  and Coarse-Grained  Transactions

63

Lock Handoff

dependence

Page 64: Commutativity  and Coarse-Grained  Transactions

64

Lock Handoff

dependence Lock handoff

Page 65: Commutativity  and Coarse-Grained  Transactions

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

Page 66: Commutativity  and Coarse-Grained  Transactions

66

Deadlock?

Page 67: Commutativity  and Coarse-Grained  Transactions

67

Detection

• Dreadlocks– [Herlihy & Koskinen, SPAA 2008]

• Fast, incremental deadlock detection

• Low overhead• Cache-friendly

Page 68: Commutativity  and Coarse-Grained  Transactions

68

Waits-For Graph

waiting owned

Page 69: Commutativity  and Coarse-Grained  Transactions

69

Digest

Page 70: Commutativity  and Coarse-Grained  Transactions

70

Digest

Page 71: Commutativity  and Coarse-Grained  Transactions

71

Digest

Uh-oh!

Page 72: Commutativity  and Coarse-Grained  Transactions

72

Details

• Can represent digest as– Bit map (small population)– Bloom filter (larger population)

• [Herlihy & Koskinen, SPAA 2008]

Page 73: Commutativity  and Coarse-Grained  Transactions

Challenges

• Automation?– Theorem proving– Model checking

• Compiler & Language support?• Implementation …