Hazard Pointers: Safe Memory Reclamation for Lock-Free Objects

Slides:



Advertisements
Similar presentations
Linked Lists CSE 2451 Matt Boggus. Dynamic memory reminder Allocate memory during run-time malloc() and calloc() – return a void pointer to memory or.
Advertisements

Hazard Pointers: Safe Memory Reclamation of Lock-Free Objects
Wait-Free Queues with Multiple Enqueuers and Dequeuers
TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: A A A AAA A A A AA A Proving that non-blocking algorithms don't block.
CS492B Analysis of Concurrent Programs Lock Basics Jaehyuk Huh Computer Science, KAIST.
Dynamic Memory Allocation (also see pointers lectures) -L. Grewe.
CS510 – Advanced Operating Systems 1 The Synergy Between Non-blocking Synchronization and Operating System Structure By Michael Greenwald and David Cheriton.
Memory management.
Maged M. Michael, “Hazard Pointers: Safe Memory Reclamation for Lock- Free Objects” Presentation Robert T. Bauer.
Wait-Free Reference Counting and Memory Management Håkan Sundell, Ph.D.
McRT-Malloc: A Scalable Non-Blocking Transaction Aware Memory Allocator Ali Adl-Tabatabai Ben Hertzberg Rick Hudson Bratin Saha.
Scalable Synchronous Queues By William N. Scherer III, Doug Lea, and Michael L. Scott Presented by Ran Isenberg.
Locality-Conscious Lock-Free Linked Lists Anastasia Braginsky & Erez Petrank 1.
10/31/20111 Relativistic Red-Black Trees Philip Howard 10/31/2011
Template class Wrapper { public: T* operator->() { return &myT; } private: T myT; }; int main() { Wrapper wThing; wThing- >Foo(); // calls Thing::Foo()...
Memory Allocation and Garbage Collection. Why Dynamic Memory? We cannot know memory requirements in advance when the program is written. We cannot know.
What is RCU, fundamentally? Sri Ramkrishna. Intro RCU stands for Read Copy Update  A synchronization method that allows reads to occur concurrently with.
CS510 Concurrent Systems Class 13 Software Transactional Memory Should Not be Obstruction-Free.
Insertion into a B+ Tree Null Tree Ptr Data Pointer * Tree Node Ptr After Adding 8 and then 5… 85 Insert 1 : causes overflow – add a new level * 5 * 158.
1 I/O Management in Representative Operating Systems.
Algorithms for Synchronization and Consistency in Concurrent System Services Anders Gidenstam Distributed Computing and Systems group, Department of Computer.
Real-Time Concepts for Embedded Systems Author: Qing Li with Caroline Yao ISBN: CMPBooks.
1 Lock-Free Linked Lists Using Compare-and-Swap by John Valois Speaker’s Name: Talk Title: Larry Bush.
Simulated Pointers Limitations Of Java Pointers May be used for internal data structures only. Data structure backup requires serialization and deserialization.
Hazard Pointers: Safe Memory Reclamation for Lock-Free Objects Maged M. Michael Presented by Abdulai Sei.
The read-copy-update mechanism for supporting real-time applications on shared-memory multiprocessor systems with Linux Guniguntala et al.
CS510 Concurrent Systems Jonathan Walpole. A Methodology for Implementing Highly Concurrent Data Objects.
Software Transactional Memory Should Not Be Obstruction-Free Robert Ennals Presented by Abdulai Sei.
CS510 Concurrent Systems Jonathan Walpole. RCU Usage in Linux.
November 27, 2007 Verification of a Concurrent Priority Queue Bart Verzijlenberg.
Tornado: Maximizing Locality and Concurrency in a Shared Memory Multiprocessor Operating System Ben Gamsa, Orran Krieger, Jonathan Appavoo, Michael Stumm.
Distributed Algorithms (22903) Lecturer: Danny Hendler The wait-free hierarchy and the universality of consensus This presentation is based on the book.
Simulated Pointers Limitations Of C++ Pointers May be used for internal data structures only. Data structure backup requires serialization and deserialization.
An algorithm of Lock-free extensible hash table Yi Feng.
Hazard Pointers: Safe Memory Reclamation for Lock-Free Objects MAGED M. MICHAEL PRESENTED BY NURIT MOSCOVICI ADVANCED TOPICS IN CONCURRENT PROGRAMMING,
CS510 Concurrent Systems Tyler Fetters. A Methodology for Implementing Highly Concurrent Data Objects.
Distributed Algorithms (22903) Lecturer: Danny Hendler Lock-free stack algorithms.
Read-Copy-Update Synchronization in the Linux Kernel 1 David Ferry, Chris Gill CSE 522S - Advanced Operating Systems Washington University in St. Louis.
MIT Lincoln Laboratory XYZ 3/11/2005 Introduction to a Wait-Free Hash Table Hash Table Key-Value pair stores and retrieves data Three Core Functions:
Multiprocessors – Locks
Distributed Algorithms (22903)
Linked List ADT used to store information in a list
Data Structures Using C, 2e
Module 9: Memory and Resource Management
Hazard Pointers C++ Memory Ordering Issues
Håkan Sundell Philippas Tsigas
Lock-Free Linked Lists Using Compare-and-Swap
Lectures Queues Chapter 8 of textbook 1. Concepts of queue
Distributed Algorithms (22903)
Distributed Algorithms (22903)
Expander: Lock-free Cache for a Concurrent Data Structure
CS510 Concurrent Systems Jonathan Walpole.
Distributed Algorithms (22903)
Anders Gidenstam Håkan Sundell Philippas Tsigas
Dynamic Memory Allocation
CS510 Concurrent Systems Jonathan Walpole.
Kernel Synchronization II
CS510 - Portland State University
Multicore programming
Virtual Memory Hardware
Distributed Algorithms (22903)
Distributed Algorithms (22903)
Lecture 2 Part 2 Process Synchronization
Software Transactional Memory Should Not be Obstruction-Free
Created By: Asst. Prof. Ashish Shah, J.M.Patel College, Goregoan West
CS510 Advanced Topics in Concurrency
Virtual Memory: Policies (Part II)
CS510 Concurrent Systems Jonathan Walpole.
EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019
Internal Representation of Files
Presentation transcript:

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

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?

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

Hazard Pointers: Data Thread 1 . . . Thread N Hazard Ptr List ... pN p0 p1 p2 p3 ... pN Retirement List Retirement List node0 ... nodeR node0 ... nodeR

Hazard Pointers: Safe Access Thread A Thread B RetList B RetList A p0 p1 p2 p3 ... pN p0 p1 p2 p3 ... pN node0 node1 ... node0 node1 ... Object A

Hazard Pointers: Safe Access Thread A Thread B RetList B RetList A p0 p1 p2 p3 ... pN p0 p1 p2 p3 ... pN node0 node1 ... node0 node1 ... Thread A allocates obj B Object A Object B

Hazard Pointers: Safe Access Thread A Thread B RetList B RetList A p0 p1 p2 p3 ... pN p0 p1 p2 p3 ... pN node0 node1 ... node0 node1 ... Thread B references obj B with a Hazard Pointer Object A Object B

Hazard Pointers: Safe Access Thread A Thread B RetList B RetList A p0 p1 p2 p3 ... pN p0 p1 p2 p3 ... pN node0 node1 ... node0 node1 ... Thread A “Retires” obj B to its Retirement List Object A Object B

Hazard Pointers: Safe Access Thread A Thread B RetList B RetList A p0 p1 p2 p3 ... pN p0 p1 p2 p3 ... pN node0 node1 ... node0 node1 ... 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

Hazard Pointers: Safe Access Thread A Thread B RetList B RetList A p0 p1 p2 p3 ... pN p0 p1 p2 p3 ... pN node0 node1 ... node0 node1 ... When will it be freed? Object A Object B

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.

Retirement t1 t2 … tN p0 p1 p2 p3 ... pN p0 p1 p2 p3 ... pN p0 p1 p2 RetList node0 ... nodeR len(RetList) == R

Retirement pList t1 t2 … tN p0 p1 p2 p3 ... pN p0 p1 p2 p3 ... pN p0 RetList node0 ... nodeR len(RetList) == R

Retirement Matches? P0 (0x11) P1 (0x0b) Node0 (0x0a) Node1 (0x33) P2 (0xFF) P3 (0x33) P4 (0x20) Matches? Node0 (0x0a) Node1 (0x33) Node2 (0xFF) Node3 (0xF1)

Retirement Matches? Yes. -Node1 (P3) -Node2 (P2) P0 (0x11) P1 (0x0b) (0xFF) P3 (0x33) P4 (0x20) Matches? Yes. -Node1 (P3) -Node2 (P2) Node0 (0x0a) Node1 (0x33) Node2 (0xFF) Node3 (0xF1)

Retirement Matches? Yes. -Node1 (P3) -Node2 (P2) (0x11) P1 (0x0b) P2 (0xFF) P3 (0x33) P4 (0x20) Matches? Yes. -Node1 (P3) -Node2 (P2) Node0 (0x0a) Node1 (0x33) Node2 (0xFF) Node3 (0xF1) These objects in the RetList are referenced by other threads. Can not free these nodes!

Retirement The Remaining Nodes Can Be Freed or Reused! P0 (0x11) P1 (0x0b) P2 (0xFF) P3 (0x33) P4 (0x20) The Remaining Nodes Can Be Freed or Reused! Node0 (0x0a) Node1 (0x33) Node2 (0xFF) Node3 (0xF1)

Implementing Hazard Pointers

Implementing Hazard Pointers

Performance Hash Table

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