1 / 22

Hazard Pointers: Safe Memory Reclamation for Lock-Free Objects

Hazard Pointers: Safe Memory Reclamation for Lock-Free Objects. Lock-Free Algorithms. Guarantee that when a thread executes some arbitrary, finite number of steps, some thread (potentially a different thread) makes progress Synthesis CAS-based algorithms LL/SC-based algorithms.

pervin
Télécharger la présentation

Hazard Pointers: Safe Memory Reclamation for Lock-Free Objects

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Hazard Pointers: Safe Memory Reclamation for Lock-Free Objects

  2. Lock-Free Algorithms • Guarantee that when a thread executes some arbitrary, finite number of steps, some thread (potentially a different thread) makes progress • Synthesis • CAS-based algorithms • LL/SC-based algorithms

  3. Problems with Lock-Free Algorithms • In order to provide Lock-Free progress, each thread must have unrestricted access to shared objects at any time • If one thread removes an object while another is reading it, it could result in corrupted data or invalid reference to a null pointer. • Memory Reclamation: how do you allow the memory of removed nodes to be freed while guaranteeing no thread accesses the freed memory? • How can this be done while maintaining the Lock-Free property?

  4. Wait-Free No Special HW/Kernel Support + Memory Reclamation - ABA Problem Hazard Pointers • List of Pointers • Readable by all threads • Writable by one thread • Retirement List

  5. Hazard Pointers: Data Thread 1 . . . Thread N Hazard Ptr List Hazard Ptr List Retirement List Retirement List

  6. Hazard Pointers: Safe Access Thread A Thread B RetList B RetList A Object A

  7. Hazard Pointers: Safe Access Thread A Thread B RetList B RetList A Thread A allocates obj B Object A Object B

  8. Hazard Pointers: Safe Access Thread A Thread B RetList B RetList A Thread B references obj B with a Hazard Pointer Object A Object B

  9. Hazard Pointers: Safe Access Thread A Thread B RetList B RetList A Thread A “Retires” obj B to its Retirement List Object A Object B

  10. Hazard Pointers: Safe Access Thread A Thread B RetList B RetList A Thread B can still safely access obj B, as it will not be freed or reused until no Hazard Pointers point to it. Object A Object B

  11. Hazard Pointers: Safe Access Thread A Thread B RetList B RetList A When will it be freed? Object A Object B

  12. Retirement • Once a threshold R is met (max size of RetList), scan Hazard Pointer Lists for non Null values • Make local list 'plist' consisting of those values • Compare with RetList • For all matches • That means there exists a hazard pointer still pointing to that object • No match? • Then no pointer pointing to object • Free, Reuse, etc.

  13. Retirement t2 … tN t1 RetList len(RetList) == R

  14. Retirement pList t2 … tN t1 RetList len(RetList) == R

  15. Retirement Matches?

  16. Retirement Matches? Yes. -Node1 (P3) -Node2 (P2)

  17. Retirement Matches? Yes. -Node1 (P3) -Node2 (P2) These objects in the RetList are referenced by other threads. Can not free these nodes!

  18. Retirement The Remaining Nodes Can Be Freed or Reused!

  19. Implementing Hazard Pointers

  20. Implementing Hazard Pointers

  21. Performance Hash Table

  22. Conclusions • Adds Memory Reclamation to lock-free and wait-free algorithms • Retains lock-free/wait-free property if already exists in algorithm • Solves ABA problem • Performs Well • Portable

More Related