1 / 19

Hazard Pointers: Safe Memory Reclamation for Lock-Free Objects

Hazard Pointers: Safe Memory Reclamation for Lock-Free Objects. Maged M. Michael Presented by Abdulai Sei. Recap. So far we have seen many lock-free dynamic objects algorithms How many reclaim memory of reused nodes? How many of these return memory to the operating system?

abby
Download Presentation

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 Maged M. Michael Presented by Abdulai Sei

  2. Recap • So far we have seen many lock-free dynamic objects algorithms • How many reclaim memory of reused nodes? • How many of these return memory to the operating system? • What happens if a thread frees a node and another thread has a pointer to that node?

  3. Related paper -Type Stable Memory (TSM) • Similar concept to HP, non-blocking • Three basic extension to conventional type implementation • type descriptor remains a valid instance of the type even when inactive (in the free list) • allows multiple memory allocation for the same type • type change over time (descriptor has to be inactive before reallocation) • Guarantee a pointer to point to a descriptor of the type • readers can continue reading but does not guarantee correct data

  4. Hazard Pointers (HP) • A memory management methodology that allows memory reclamation for arbitrary reuse • Memory is finite and needs to be reused • Thread failures and dead lock leave chunks of memory unclaimed for reuse by the operating system

  5. HP Claims • Suitable for user-level application as well as system level program without dependency on kernel or scheduler • Very efficient algorithm for dynamic lock-free object • Requires only single-word reads and writes • Solves the ABA problem • Wait-free

  6. ABA Problem • Common problem with CAS, CAS2, DCAS • Affects almost all lock-free algorithms • Thread A reads a value (XX) from a shared memory, then another thread B reads the same value XX, change it to XY and then back to XX. When thread A reads the value for the second time, it sees XX and assume it was not changed • Must be prevented regardless of memory reclamation • Applying HP to ABA-safe algorithm makes it safe

  7. Methodology • Based on the observation that • A thread holds a small number of references • References do not need further validation for accessing the content of dynamic nodes • References are not ABA-prone • Core ideas • Single-writer multi-reader shared pointers called HP • HP varies among threads – typically one to two • Communicates with the algorithm through HP • Consists of two parts • One for processing retired nodes • Memory reclamation and ABA prevention

  8. Algorithm – (reader only) HP List READER (add2) – dereference add1 add1* add2

  9. Algorithm – (reader + writer) HP List WRITER READER (add2) – dereference add1 allocate add3 Deference add1 copy add2 to add3 modify add3 add1* add3 add2

  10. Algorithm (reader + writer) HP List WRITER READER (add2) – reader has already deference add1* before writer start allocate add3 copy add2 to add3 modify add3 CAS retired add2 add1* add3 add2

  11. Questions for class • Is the reader reading the right data after the writer perform CAS? See slide 13, the conditions • Can the garbage collector free add2? • Any new problems? • yes, readers have to write to the HP list • others?

  12. Code

  13. The Condition • A thread announces to other threads when it assigns a reference to one of it HP • Other threads refrain from reclaiming or reusing node • At time t, each node n is in one of the states • Allocated, reachable, removed, retired, free, unavailable, undefined • A thread holds a reference to a node when it is safe • Question: • Can a thread create a new hazardous reference to a node when it is retired?

  14. Applying HP • Apply to existing lock-free algorithms based on conditions • Examine the target algorithm • Identify HP and hazard reference they use • Determine where hazard reference is created and last hazard pointer that uses it • Determine the max # that can be hazardous • Insert the following in target algorithm • Write the address of nodes that are target for reference to an unavailable hazard reference • Validate the node is safe • Example of existing algorithms to apply the use of HP • FIFO Queues • LIFO Stacks • List-Based Sets and Hash Tables • Single-Writer Multireader Dynamic Structures

  15. Applications – FIFO queues

  16. Applications – Lock-free stack using HP

  17. Experiment • Comparing performance of new methodology to lock-free memory management system • FIFI queues, LIFO stacks, chaining hash table – all implemented using HP • Comparison with commonly use locks • Using test-and-test and set with exponential backoff • Hash table with 100 separate locks • IBM RS /6000 multiprocessor with 4 processors • Align cache data structure • Locks, single-word, double-word CAS implemented using LL/SC • All implementation compiled at highest optimization • Ran each experiment 5 times and reported the average

  18. Performance Comparison Hash tables load factor 1 FIFO Queue LIFO stacks Hash tables load factor 5

  19. Conclusion • HP provided unrestricted memory reclamation for dynamic lock-free objects • Takes constant amortized time per retired node • Uses only single-word instructions • Comparable performance to that of lock-based implementation • Both under no contention and no multiprogramming • Outperform them significantly under moderate multiprogramming and/or contention • Guarantee progress even if a thread fails or delays (prevent deadlock)

More Related