computer laboratory practical non-blocking linked lists tim harris [email protected] computer...

18
Computer Laboratory Practical non- blocking linked lists Tim Harris [email protected] Computer Laboratory

Post on 22-Dec-2015

222 views

Category:

Documents


0 download

TRANSCRIPT

Computer Laboratory

Practical non-blocking linked lists

Tim [email protected]

Computer Laboratory

Computer Laboratory

Overview: lists using CAS

• Insert 20:

H 10 30 T

20

30 20

10 30

20

30 20

Computer Laboratory

Overview: lists using CAS

• Insert 20:

H 10 30 T

20

30 20

25

30 25

10 30

20

30 20

25

30 25

Computer Laboratory

Overview: lists using CAS

• Delete 10:

H 10 30 T

10 30

H 10 30

10 30

Computer Laboratory

Overview: lists using CAS

• Delete 10 & insert 20:

H 10 30 T

10 30

H 10 30

10 30

20

30 20

H 10 30

10 30

H 10 30

10 30

20

30 20

Computer Laboratory

What can you do?

• Stronger primitives, e.g. DCAS

H 10

10 30 30 XX

H 10

10 30 30 XX30 T

Computer Laboratory

What can you do?

• Extra indirection:

H 10 30 T

30 1010 b

10 d

b10 30

30 10

10 d

b

caH 10

10 b

a

Computer Laboratory

Logical vs physical deletion

• Use a ‘spare’ bit to indicate logically deleted nodes:

H 10 30 T

20

10 30

30 30X

30 20H 10 30

20

10 30

30 30X

30 20

Computer Laboratory

H

Storage management

• Must control memory re-use while

threads hold pointers to it

H 10 30 T10 30

Computer Laboratory

Storage management (2)

Time

A

B

C

• Ref counting, tracing GC, time-based re-use

Add object toA’s deferred

free list

A finishes.C not complete:

can’t free object yet

Add object toC’s deferred

free listC finishes

A can now re-usethe object it removed:

B&C can’t havepointers to itDelayed threads

can prevent anyre-use

Computer Laboratory

Storage management (3)

• Also need to consider visibility of updates

H 10 30 T

20

30 20

Write-write

10 30

20

30 20Write-write

Computer Laboratory

Storage management (4)

• …and re-ordering of dependent reads

H 10 30 T

2020

10 30

while (val < seek) {

p = p->next;

val = p->val;

}

val = ???

Computer Laboratory

Random insert/deletePer-

thre

ad

CPU

-tim

e /

s

Valois (ref-counted)

New (ref-counted)

Valois

0

10

20

30

40

50

60

70

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

Number of threads

Valois, ref-counting

New, ref-counting

Valois

New

Mutex

Computer Laboratory

Random insert/delete (2)Per-

thre

ad

CPU

-tim

e /

s

Valois (ref-counted)

New (ref-counted)

Valois

Number of threads

Valois, ref-counting

New, ref-counting

Valois

New

Mutex

0

2

4

6

8

10

12

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

Mutex

Valois

New

Computer Laboratory

0

500

1000

1500

2000

2500

3000

3500

10 100 1000 10000 100000

Successful insertionsO

ccu

ran

ces

Duration / cycles

Mutex

New

Valois

Computer Laboratory

Unsuccessful insertions

Duration / cycles

Mutex

New

0

500

1000

1500

2000

2500

3000

3500

10 100 1000 10000 100000

New

Mutex

Valois

Occ

ura

nce

s

Computer Laboratory

Delete greater-than

H 10 30 T

• DeleteGE 20

10 30

20

• Insert 20

30 T

T TX

• Insert 30

30?

Computer Laboratory

Delete greater-than (2)

H 10 30 T

• Insert 20:

3020

T 20X

30 T

3020

T 20X