State Teleportation How Hardware Transactional Memory can Improve Legacy Data Structures Maurice...

47
State Teleportation How Hardware Transactional Memory can Improve Legacy Data Structures Maurice Herlihy and Eli Wald Brown University

Transcript of State Teleportation How Hardware Transactional Memory can Improve Legacy Data Structures Maurice...

Page 1: State Teleportation How Hardware Transactional Memory can Improve Legacy Data Structures Maurice Herlihy and Eli Wald Brown University.

State Teleportation

How Hardware Transactional Memory can Improve Legacy Data

Structures

Maurice Herlihy and Eli Wald

Brown University

Page 2: State Teleportation How Hardware Transactional Memory can Improve Legacy Data Structures Maurice Herlihy and Eli Wald Brown University.

Transactional Memory

2

Page 3: State Teleportation How Hardware Transactional Memory can Improve Legacy Data Structures Maurice Herlihy and Eli Wald Brown University.

Concurrent Data Structure = State Machine

3

atomicstep

memorybarrier

atomicstep

memorybarrier

atomicstep

memorybarrier

Page 4: State Teleportation How Hardware Transactional Memory can Improve Legacy Data Structures Maurice Herlihy and Eli Wald Brown University.

Concurrent Data Structure = State Machine

4

atomicstep

memorybarrier

atomicstep

memorybarrier

atomicstep

memorybarrier

critical section,CAS, load/store

Page 5: State Teleportation How Hardware Transactional Memory can Improve Legacy Data Structures Maurice Herlihy and Eli Wald Brown University.

State Teleportation

5

atomicstep

memorybarrier

atomicstep

memorybarrier

atomicstep

memorybarrierHardware Transaction

“as if” sequence of transitions

Page 6: State Teleportation How Hardware Transactional Memory can Improve Legacy Data Structures Maurice Herlihy and Eli Wald Brown University.

Three Concurrent Lists

6

lazy

lock-free

locking

wait-free traversal + locks

lock-free everything

hand-over-hand locking

Page 7: State Teleportation How Hardware Transactional Memory can Improve Legacy Data Structures Maurice Herlihy and Eli Wald Brown University.

7

Hand-Over-Hand Locking

a b c d

remove(b)

Page 8: State Teleportation How Hardware Transactional Memory can Improve Legacy Data Structures Maurice Herlihy and Eli Wald Brown University.

8

Hand-Over-Hand Locking

a b c d

remove(b)

Page 9: State Teleportation How Hardware Transactional Memory can Improve Legacy Data Structures Maurice Herlihy and Eli Wald Brown University.

9

Hand-Over-Hand Locking

a b c d

remove(b)Found

it!

Page 10: State Teleportation How Hardware Transactional Memory can Improve Legacy Data Structures Maurice Herlihy and Eli Wald Brown University.

10

Hand-Over-Hand Locking

a b c d

remove(b)

Page 11: State Teleportation How Hardware Transactional Memory can Improve Legacy Data Structures Maurice Herlihy and Eli Wald Brown University.

11

Lazy List

a b c

remove(b)

Page 12: State Teleportation How Hardware Transactional Memory can Improve Legacy Data Structures Maurice Herlihy and Eli Wald Brown University.

12

Lazy List

a b c

remove(b)

Page 13: State Teleportation How Hardware Transactional Memory can Improve Legacy Data Structures Maurice Herlihy and Eli Wald Brown University.

13

Lazy List

a b c

remove(b)

Page 14: State Teleportation How Hardware Transactional Memory can Improve Legacy Data Structures Maurice Herlihy and Eli Wald Brown University.

14

Lazy List

a b c

remove(b)

Page 15: State Teleportation How Hardware Transactional Memory can Improve Legacy Data Structures Maurice Herlihy and Eli Wald Brown University.

15

Lazy List

a b c

validate …

remove(b)

Page 16: State Teleportation How Hardware Transactional Memory can Improve Legacy Data Structures Maurice Herlihy and Eli Wald Brown University.

16

Lazy List

a b c

Logical delete

remove(b)

Page 17: State Teleportation How Hardware Transactional Memory can Improve Legacy Data Structures Maurice Herlihy and Eli Wald Brown University.

17

Lazy List

a b c

Physical delete

Page 18: State Teleportation How Hardware Transactional Memory can Improve Legacy Data Structures Maurice Herlihy and Eli Wald Brown University.

bCAS

18

Lock-Free List

a c d

remove(c)

Page 19: State Teleportation How Hardware Transactional Memory can Improve Legacy Data Structures Maurice Herlihy and Eli Wald Brown University.

Benchmarks

19

1 2 3 4 5 6 7 8 9 10 11 120

1000000000

2000000000

3000000000

4000000000

5000000000

6000000000

7000000000

lazy lock-free lock-coupling

seconds to finish 100,000 operations

80% writes, 20% modifications

higher = worse

median of 6 runs

Page 20: State Teleportation How Hardware Transactional Memory can Improve Legacy Data Structures Maurice Herlihy and Eli Wald Brown University.

Benchmarks

20

1 2 3 4 5 6 7 8 9 10 11 120

1000000000

2000000000

3000000000

4000000000

5000000000

6000000000

7000000000

lazy lock-free lock-coupling

1-4

every threadhas a core

Page 21: State Teleportation How Hardware Transactional Memory can Improve Legacy Data Structures Maurice Herlihy and Eli Wald Brown University.

Benchmarks

21

1 2 3 4 5 6 7 8 9 10 11 120

1000000000

2000000000

3000000000

4000000000

5000000000

6000000000

7000000000

lazy lock-free lock-coupling

5-8

every threadhas a hyperthread

Page 22: State Teleportation How Hardware Transactional Memory can Improve Legacy Data Structures Maurice Herlihy and Eli Wald Brown University.

Benchmarks

22

1 2 3 4 5 6 7 8 9 10 11 120

1000000000

2000000000

3000000000

4000000000

5000000000

6000000000

7000000000

lazy lock-free lock-coupling

9-up

Page 23: State Teleportation How Hardware Transactional Memory can Improve Legacy Data Structures Maurice Herlihy and Eli Wald Brown University.

No Memory Management

23

1 2 3 4 5 6 7 8 9 10 11 120

500000000

1000000000

1500000000

2000000000

2500000000

3000000000

3500000000

4000000000

45000000008.86E+10115394692330off the charts!

lazy lock-free locking

Page 24: State Teleportation How Hardware Transactional Memory can Improve Legacy Data Structures Maurice Herlihy and Eli Wald Brown University.

Memory Management?

24

Locking:

Lazy:

Lock-Free:

immediate re-use

hazard pointers

hazard pointers

Page 25: State Teleportation How Hardware Transactional Memory can Improve Legacy Data Structures Maurice Herlihy and Eli Wald Brown University.

25

Hazard Pointers

Node* hazardRead(Node** object) { while (true) { Node* read = *object; hazard[myIndex] = read; membar(); Node* reread = *object; if (read == reread) return read; }}

Page 26: State Teleportation How Hardware Transactional Memory can Improve Legacy Data Structures Maurice Herlihy and Eli Wald Brown University.

26

Hazard Pointers

Node* hazardRead(Node** object) { while (true) { Node* read = *object; hazard[myIndex] = read; membar(); Node* reread = *object; if (read == reread) return read; }}

read pointer to object

Page 27: State Teleportation How Hardware Transactional Memory can Improve Legacy Data Structures Maurice Herlihy and Eli Wald Brown University.

27

Hazard Pointers

Node* hazardRead(Node** object) { while (true) { Node* read = *object; hazard[myIndex] = read; membar(); Node* reread = *object; if (read == reread) return read; }}

announce hazard

Page 28: State Teleportation How Hardware Transactional Memory can Improve Legacy Data Structures Maurice Herlihy and Eli Wald Brown University.

28

Hazard Pointers

Node* hazardRead(Node** object) { while (true) { Node* read = *object; hazard[myIndex] = read; membar(); Node* reread = *object; if (read == reread) return read; }} make announcement

visible (expensive)

Page 29: State Teleportation How Hardware Transactional Memory can Improve Legacy Data Structures Maurice Herlihy and Eli Wald Brown University.

29

Hazard Pointers

Node* hazardRead(Node** object) { while (true) { Node* read = *object; hazard[myIndex] = read; membar(); Node* reread = *object; if (read == reread) return read; }}

reread and validate

Page 30: State Teleportation How Hardware Transactional Memory can Improve Legacy Data Structures Maurice Herlihy and Eli Wald Brown University.

Without Memory Management

30

1 2 3 4 5 6 7 8 9 10 11 120

1000000000

2000000000

3000000000

4000000000

5000000000

6000000000

7000000000

lazy lock-free locking

Page 31: State Teleportation How Hardware Transactional Memory can Improve Legacy Data Structures Maurice Herlihy and Eli Wald Brown University.

With Memory Management

31

1 2 3 4 5 6 7 8 9 10 11 120

1000000000

2000000000

3000000000

4000000000

5000000000

6000000000

7000000000

lazy lock-free locking

Page 32: State Teleportation How Hardware Transactional Memory can Improve Legacy Data Structures Maurice Herlihy and Eli Wald Brown University.

32

Lock Teleportation

a b c d

Page 33: State Teleportation How Hardware Transactional Memory can Improve Legacy Data Structures Maurice Herlihy and Eli Wald Brown University.

33

Lock Teleportation

a b c dread transaction

Page 34: State Teleportation How Hardware Transactional Memory can Improve Legacy Data Structures Maurice Herlihy and Eli Wald Brown University.

34

Lock Teleportation

a b c dread transaction

Page 35: State Teleportation How Hardware Transactional Memory can Improve Legacy Data Structures Maurice Herlihy and Eli Wald Brown University.

35

Lock Teleportation

a b c d

no locks acquired

Page 36: State Teleportation How Hardware Transactional Memory can Improve Legacy Data Structures Maurice Herlihy and Eli Wald Brown University.

36

Hazard PointerTeleportation

a b c dread transaction

Page 37: State Teleportation How Hardware Transactional Memory can Improve Legacy Data Structures Maurice Herlihy and Eli Wald Brown University.

37

Hazard PointerTeleportation

a b c d

Page 38: State Teleportation How Hardware Transactional Memory can Improve Legacy Data Structures Maurice Herlihy and Eli Wald Brown University.

38

Hazard Pointer Teleportation

a b c dread transaction

Page 39: State Teleportation How Hardware Transactional Memory can Improve Legacy Data Structures Maurice Herlihy and Eli Wald Brown University.

39

Hazard Pointer Teleportation

a b c d

no memory barriers

Page 40: State Teleportation How Hardware Transactional Memory can Improve Legacy Data Structures Maurice Herlihy and Eli Wald Brown University.

Without Teleportation

40

1 2 3 4 5 6 7 8 9 10 11 120

1000000000

2000000000

3000000000

4000000000

5000000000

6000000000

7000000000

lazy lock-free locking

Page 41: State Teleportation How Hardware Transactional Memory can Improve Legacy Data Structures Maurice Herlihy and Eli Wald Brown University.

With Teleportation

41

lazy lock-free locking

1 2 3 4 5 6 7 8 9 10 11 120

1000000000

2000000000

3000000000

4000000000

5000000000

6000000000

7000000000

Page 42: State Teleportation How Hardware Transactional Memory can Improve Legacy Data Structures Maurice Herlihy and Eli Wald Brown University.

Speedup

42

1 2 3 4 5 6 7 8 9 10 11 120

1

2

3

4

5

6

7

8Speedup

lazy lock-free locking

Page 43: State Teleportation How Hardware Transactional Memory can Improve Legacy Data Structures Maurice Herlihy and Eli Wald Brown University.

Adaptive Jumps

43

If transaction commits …Add 1 to next distance

If transaction aborts…Cut next distance in half

Page 44: State Teleportation How Hardware Transactional Memory can Improve Legacy Data Structures Maurice Herlihy and Eli Wald Brown University.

Average Teleport Distance

44

1 2 3 4 5 6 7 8 9 10 11 120

50

100

150

200

250

300

350

400

450

lazy lock-free locking

Page 45: State Teleportation How Hardware Transactional Memory can Improve Legacy Data Structures Maurice Herlihy and Eli Wald Brown University.

Average Commit Rate

45

1 2 3 4 5 6 7 8 9 10 11 1288

90

92

94

96

98

100

lazy lock-free locking

Page 46: State Teleportation How Hardware Transactional Memory can Improve Legacy Data Structures Maurice Herlihy and Eli Wald Brown University.

82

8

6.52

72

19.5

7

Abort Reasons

46

capacity explicitconflict unknown

4 threads 8 threads

Page 47: State Teleportation How Hardware Transactional Memory can Improve Legacy Data Structures Maurice Herlihy and Eli Wald Brown University.

Conclusions

47

True cost of concurrent data structuresshould include memory management

Cost of hazard pointers can equalizelock-based and lock-free structures

Adaptive Teleportation can substantiallyimprove memory management costs forboth lock-based and lock-free structures