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

Preview:

Citation preview

State Teleportation

How Hardware Transactional Memory can Improve Legacy Data

Structures

Maurice Herlihy and Eli Wald

Brown University

Transactional Memory

2

Concurrent Data Structure = State Machine

3

atomicstep

memorybarrier

atomicstep

memorybarrier

atomicstep

memorybarrier

Concurrent Data Structure = State Machine

4

atomicstep

memorybarrier

atomicstep

memorybarrier

atomicstep

memorybarrier

critical section,CAS, load/store

State Teleportation

5

atomicstep

memorybarrier

atomicstep

memorybarrier

atomicstep

memorybarrierHardware Transaction

“as if” sequence of transitions

Three Concurrent Lists

6

lazy

lock-free

locking

wait-free traversal + locks

lock-free everything

hand-over-hand locking

7

Hand-Over-Hand Locking

a b c d

remove(b)

8

Hand-Over-Hand Locking

a b c d

remove(b)

9

Hand-Over-Hand Locking

a b c d

remove(b)Found

it!

10

Hand-Over-Hand Locking

a b c d

remove(b)

11

Lazy List

a b c

remove(b)

12

Lazy List

a b c

remove(b)

13

Lazy List

a b c

remove(b)

14

Lazy List

a b c

remove(b)

15

Lazy List

a b c

validate …

remove(b)

16

Lazy List

a b c

Logical delete

remove(b)

17

Lazy List

a b c

Physical delete

bCAS

18

Lock-Free List

a c d

remove(c)

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

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

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

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

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

Memory Management?

24

Locking:

Lazy:

Lock-Free:

immediate re-use

hazard pointers

hazard pointers

25

Hazard Pointers

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

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

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

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)

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

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

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

32

Lock Teleportation

a b c d

33

Lock Teleportation

a b c dread transaction

34

Lock Teleportation

a b c dread transaction

35

Lock Teleportation

a b c d

no locks acquired

36

Hazard PointerTeleportation

a b c dread transaction

37

Hazard PointerTeleportation

a b c d

38

Hazard Pointer Teleportation

a b c dread transaction

39

Hazard Pointer Teleportation

a b c d

no memory barriers

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

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

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

Adaptive Jumps

43

If transaction commits …Add 1 to next distance

If transaction aborts…Cut next distance in half

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

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

82

8

6.52

72

19.5

7

Abort Reasons

46

capacity explicitconflict unknown

4 threads 8 threads

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

Recommended