Efficient and Reliable Lock-Free Memory Reclamation Based on - - PowerPoint PPT Presentation

efficient and reliable lock free memory reclamation
SMART_READER_LITE
LIVE PREVIEW

Efficient and Reliable Lock-Free Memory Reclamation Based on - - PowerPoint PPT Presentation

Efficient and Reliable Lock-Free Memory Reclamation Based on Reference Counting Anders Gidenstam, Marina Papatriantafilou, Hkan Sundell and Philippas Tsigas Distributed Computing and Systems group, Department of Computer Science and


slide-1
SLIDE 1

Efficient and Reliable Lock-Free Memory Reclamation

Based on Reference Counting

Anders Gidenstam, Marina Papatriantafilou, Håkan Sundell and Philippas Tsigas

Distributed Computing and Systems group, Department of Computer Science and Engineering,

Chalmers University of Technology

slide-2
SLIDE 2

2005 Anders Gidenstam, Distributed Computing and Systems, Chalmers

2

Outline

Introduction The Problem Lock-free synchronization Our solution Idea Properties Experiments Conclusions

slide-3
SLIDE 3

2005 Anders Gidenstam, Distributed Computing and Systems, Chalmers

3

The Lock-Free Memory Reclamation Problem

Concurrent shared data structure Dynamic use of shared memory Concurrent and overlapping operations by

threads or processes

A B C

Base

slide-4
SLIDE 4

2005 Anders Gidenstam, Distributed Computing and Systems, Chalmers

4

A B C

The Lock-Free Memory Reclamation Problem

Thread X Base Local variables

slide-5
SLIDE 5

2005 Anders Gidenstam, Distributed Computing and Systems, Chalmers

5

A B C

The Lock-Free Memory Reclamation Problem

Thread X Base

X has de-referenced the link (pointer) to B

slide-6
SLIDE 6

2005 Anders Gidenstam, Distributed Computing and Systems, Chalmers

6

A B C

The Lock-Free Memory Reclamation Problem

Thread X Base

Another thread, Y, finds and deletes (removes) B from the active structure

Thread Y

slide-7
SLIDE 7

2005 Anders Gidenstam, Distributed Computing and Systems, Chalmers

7

A B C

The Lock-Free Memory Reclamation Problem

Thread X Base

Thread Y wants to reclaim(/free) B

Thread Y

?

Property I: A (de-)referenced node is not reclaimed

slide-8
SLIDE 8

2005 Anders Gidenstam, Distributed Computing and Systems, Chalmers

8

A C D

The Lock-Free Memory Reclamation Problem

Thread X Base

?

The nodes B and C are deleted from the active structure.

B Property II: Links in a (de-)referenced node should always be de-referencable.

slide-9
SLIDE 9

2005 Anders Gidenstam, Distributed Computing and Systems, Chalmers

9

The Lock-Free Memory Reclamation Problem

Thread X Base

A

1

D

2

B

1

C

1

Solutions?

Garbage collection? Reference counting?

Needs to be lock-free!

slide-10
SLIDE 10

2005 Anders Gidenstam, Distributed Computing and Systems, Chalmers

10

Lock-free synchronization

A lock-free shared data structure

Allows concurrent operations without enforcing

mutual exclusion (i.e. no locks)

Guarantees that at least one operation always

makes progress

Avoids:

  • Blocking, deadlock and priority inversion

Hardware synchronization primitives

Built into CPU and memory system

  • Typically: atomic read-modify-write instructions
  • Examples
  • Test-and-set, Compare-and-Swap, Load-Linked / Store-Conditional
slide-11
SLIDE 11

2005 Anders Gidenstam, Distributed Computing and Systems, Chalmers

11

Lock-free Reference Counting Valois + Michael & Scott 1995 Detlefs et al. 2001 Herlihy et al. 2002 Remaining issues A slow thread might prevent reclamation Cyclic garbage Implementation practicality issues

Reference-count field MUST remain forever (Valois + Michael &

Scott)

Needs double word CAS (Detlefs et al.) Needs double width CAS (Herlihy, 2002) Large overhead

Previous solutions

B

1

C

1

A

1

Slow

slide-12
SLIDE 12

2005 Anders Gidenstam, Distributed Computing and Systems, Chalmers

12

Our approach – The basic idea

Combine the best of Hazard pointers (Michael 2002)

  • Tracks references from threads
  • Fast de-reference
  • Upper bound on the amount of unreclaimed deleted nodes
  • Compatible with standard memory allocators

Reference counting

  • Tracks references from links in shared memory
  • Manages links within dynamic nodes
  • Safe to traverse links (also) in deleted nodes

Practical Uses only single-word Compare-And-Swap

slide-13
SLIDE 13

2005 Anders Gidenstam, Distributed Computing and Systems, Chalmers

13

The basic idea

API DeRefLink ReleaseRef CompareAndSwapRef StoreRef NewNode DeleteNode

Hazard pointers (Thread X) Base

A

1

B

1

C

1

Thread X

Deletion list

slide-14
SLIDE 14

2005 Anders Gidenstam, Distributed Computing and Systems, Chalmers

14

The basic idea

API DeRefLink(Base) ReleaseRef CompareAndSwapRef StoreRef NewNode DeleteNode

Hazard pointers (Thread X) Base

A

1

B

1

C

1 Deletion list

Thread X R

slide-15
SLIDE 15

2005 Anders Gidenstam, Distributed Computing and Systems, Chalmers

15

Thread X R

The basic idea

API DeRefLink ReleaseRef(R) CompareAndSwapRef StoreRef NewNode DeleteNode

Hazard pointers (Thread X) Base

A

1

B

1

C

1 Deletion list

slide-16
SLIDE 16

2005 Anders Gidenstam, Distributed Computing and Systems, Chalmers

16

Thread X new

The basic idea

API DeRefLink ReleaseRef CompareAndSwapRef StoreRef NewNode DeleteNode

Hazard pointers (Thread X) Base

A

1

B

1

C

1 Deletion list

D

slide-17
SLIDE 17

2005 Anders Gidenstam, Distributed Computing and Systems, Chalmers

17

Thread X

C

new R

The basic idea

API DeRefLink ReleaseRef CompareAndSwapRef StoreRef(new.next, R) NewNode DeleteNode

C

Hazard pointers (Thread X) Base

A

1

B

1

C

2 Deletion list

D

slide-18
SLIDE 18

2005 Anders Gidenstam, Distributed Computing and Systems, Chalmers

18

Thread X

A B

new prev

  • ld

The basic idea

API DeRefLink ReleaseRef

CompareAndSwapRef(prev.next, old, new)

StoreRef NewNode DeleteNode

B A

Hazard pointers (Thread X) Base

A

1

B C

2 Deletion list

D

1

slide-19
SLIDE 19

2005 Anders Gidenstam, Distributed Computing and Systems, Chalmers

19

Thread X

A _

new prev

  • ld

The basic idea

API DeRefLink ReleaseRef CompareAndSwapRef StoreRef NewNode DeleteNode(old)

Hazard pointers (Thread X) Base

A

1

B C

2 Deletion list

D

1

slide-20
SLIDE 20

2005 Anders Gidenstam, Distributed Computing and Systems, Chalmers

20

Breaking chains of garbage

Hazard pointers (Thread Y) Base

A

1

D

1

E

2

Thread X

Deletion list

B C

1

Clean-up deleted nodes Update links to point to

live nodes

Performed on nodes in

  • Own deletion list
  • All deletion lists
slide-21
SLIDE 21

2005 Anders Gidenstam, Distributed Computing and Systems, Chalmers

21

Breaking chains of garbage

Clean-up deleted nodes Update links to point to

live nodes

Performed on nodes in

  • Own deletion list
  • All deletion lists

Hazard pointers (Thread Y) Base

A

1

D

1

E

3

Thread X

Deletion list

B C

slide-22
SLIDE 22

2005 Anders Gidenstam, Distributed Computing and Systems, Chalmers

22

Bound on unreclaimed nodes

A deleted node can be reclaimed when The reference count is zero and No hazard pointer is pointing to it and There is no ongoing clean-up of this node With a rate relative to the number of threads of Scanning hazard pointers Cleaning up nodes as needed Then the maximum size of each deletion list depends on The number of hazard pointers The number of links per node The number of threads

slide-23
SLIDE 23

2005 Anders Gidenstam, Distributed Computing and Systems, Chalmers

23

Experimental evaluation

Lock-free deque (Sundell and Tsigas 2004)

(deque – double-ended queue)

The algorithm needs traversal of deleted nodes Time for 10000 random operations/thread Tested memory reclamation schemes Reference counting, Valois et al. The new algorithm Systems 4 processor Xeon PC / Linux (UMA) 8 processor SGI Origin 2000 / IRIX (NUMA)

slide-24
SLIDE 24

2005 Anders Gidenstam, Distributed Computing and Systems, Chalmers

24

Experimental evaluation

slide-25
SLIDE 25

2005 Anders Gidenstam, Distributed Computing and Systems, Chalmers

25

Experimental evaluation

slide-26
SLIDE 26

2005 Anders Gidenstam, Distributed Computing and Systems, Chalmers

26

Conclusions

First lock-free memory reclamation scheme

that

Only uses atomic primitives available in

contemporary architectures

Guarantees safety of

  • Local and
  • Global references

Has an upper bound on the amount of deleted

but unreclaimed nodes

Allows arbitrary reuse of reclaimed memory

slide-27
SLIDE 27

2005 Anders Gidenstam, Distributed Computing and Systems, Chalmers

27

Questions?

Contact Information:

Address:

Anders Gidenstam, Computer Science & Engineering, Chalmers University of Technology, SE-412 96 Göteborg, Sweden

Email:

andersg @ cs.chalmers.se

Web:

http://www.cs.chalmers.se/~dcs http://www.cs.chalmers.se/~andersg

Implementation

http://www.noble-library.org/

slide-28
SLIDE 28

2005 Anders Gidenstam, Distributed Computing and Systems, Chalmers

28

Conclusions

First lock-free memory reclamation scheme

that

Only uses atomic primitives available in

contemporary architectures

Guarantees safety of

  • Local and
  • Global references

Has an upper bound on the amount of deleted

but unreclaimed nodes ( Bound: N * N * (k + L_max + a + 1) )

Allows arbitrary reuse of reclaimed memory