Hazard Pointers: Safe Memory Reclamation for Lock-Free Objects MAGED M. MICHAEL PRESENTED BY NURIT MOSCOVICI ADVANCED TOPICS IN CONCURRENT PROGRAMMING,

Slides:



Advertisements
Similar presentations
Bounded Model Checking of Concurrent Data Types on Relaxed Memory Models: A Case Study Sebastian Burckhardt Rajeev Alur Milo M. K. Martin Department of.
Advertisements

Singly linked lists Doubly linked lists
Hazard Pointers: Safe Memory Reclamation of Lock-Free Objects
Garbage collection David Walker CS 320. Where are we? Last time: A survey of common garbage collection techniques –Manual memory management –Reference.
Wait-Free Queues with Multiple Enqueuers and Dequeuers
Hazard Pointers: Safe Memory Reclamation for Lock-Free Objects
Introduction to Linked Lists In your previous programming course, you saw how data is organized and processed sequentially using an array. You probably.
Chapter 17 Linked List Saurav Karmakar Spring 2007.
CS510 – Advanced Operating Systems 1 The Synergy Between Non-blocking Synchronization and Operating System Structure By Michael Greenwald and David Cheriton.
Maged M. Michael, “Hazard Pointers: Safe Memory Reclamation for Lock- Free Objects” Presentation Robert T. Bauer.
Scalable and Lock-Free Concurrent Dictionaries
Wait-Free Reference Counting and Memory Management Håkan Sundell, Ph.D.
Review of Stacks and Queues Dr. Yingwu Zhu. Our Focus Only link-list based implementation of Stack class Won’t talk about different implementations of.
Data Structures: A Pseudocode Approach with C
Linked Lists Compiled by Dr. Mohammad Alhawarat CHAPTER 04.
Scalable Synchronous Queues By William N. Scherer III, Doug Lea, and Michael L. Scott Presented by Ran Isenberg.
E81 CSE 532S: Advanced Multi-Paradigm Software Development Chris Gill Department of Computer Science and Engineering Washington University in St. Louis.
Locality-Conscious Lock-Free Linked Lists Anastasia Braginsky & Erez Petrank 1.
CPSC 388 – Compiler Design and Construction
Multi-Object Synchronization. Main Points Problems with synchronizing multiple objects Definition of deadlock – Circular waiting for resources Conditions.
Progress Guarantee for Parallel Programs via Bounded Lock-Freedom Erez Petrank – Technion Madanlal Musuvathi- Microsoft Bjarne Steensgaard - Microsoft.
Introduction to Lock-free Data-structures and algorithms Micah J Best May 14/09.
CS510 Advanced OS Seminar Class 10 A Methodology for Implementing Highly Concurrent Data Objects by Maurice Herlihy.
Simple, Fast, and Practical Non- Blocking and Blocking Concurrent Queue Algorithms Presenter: Jim Santmyer By: Maged M. Micheal Michael L. Scott Department.
CS510 Concurrent Systems Class 2 A Lock-Free Multiprocessor OS Kernel.
Chapter 3: Arrays, Linked Lists, and Recursion
Simple, Fast and Practical Non- Blocking and Blocking Concurrent Queue Algorithms Maged M. Michael & Michael L. Scott Presented by Ahmed Badran.
Stacks, Queues, and Deques
Algorithms for Synchronization and Consistency in Concurrent System Services Anders Gidenstam Distributed Computing and Systems group, Department of Computer.
October 18, Algorithms and Data Structures Lecture V Simonas Šaltenis Nykredit Center for Database Research Aalborg University
Nachos Phase 1 Code -Hints and Comments
CS510 Concurrent Systems Jonathan Walpole. A Lock-Free Multiprocessor OS Kernel.
Håkan Sundell, Chalmers University of Technology 1 NOBLE: A Non-Blocking Inter-Process Communication Library Håkan Sundell Philippas.
A Qualitative Survey of Modern Software Transactional Memory Systems Virendra J. Marathe Michael L. Scott.
Lists 1. Introduction Data: A finite sequence of data items. Operations: Construction: Create an empty list Empty: Check if list is empty Insert: Add.
November 15, 2007 A Java Implementation of a Lock- Free Concurrent Priority Queue Bart Verzijlenberg.
ICOM 4035 – Data Structures Lecture 3 – Bag ADT Manuel Rodriguez Martinez Electrical and Computer Engineering University of Puerto Rico, Mayagüez ©Manuel.
Maged M.Michael Michael L.Scott Department of Computer Science Univeristy of Rochester Presented by: Jun Miao.
11/18/20151 Operating Systems Design (CS 423) Elsa L Gunter 2112 SC, UIUC Based on slides by Roy Campbell, Sam.
A Methodology for Creating Fast Wait-Free Data Structures Alex Koganand Erez Petrank Computer Science Technion, Israel.
CSS446 Spring 2014 Nan Wang.  To understand the implementation of linked lists and array lists  To analyze the efficiency of fundamental operations.
Practical concurrent algorithms Mihai Letia Concurrent Algorithms 2012 Distributed Programming Laboratory Slides by Aleksandar Dragojevic.
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.
Gal Milman Based on Chapter 10 (Concurrent Queues and the ABA Problem) in The Art of Multiprocessor Programming by Herlihy and Shavit Seminar 2 (236802)
1 Linked Lists (Lec 6). 2  Introduction  Singly Linked Lists  Circularly Linked Lists  Doubly Linked Lists  Multiply Linked Lists  Applications.
An algorithm of Lock-free extensible hash table Yi Feng.
Processes 2 Introduction to Operating Systems: Module 4.
Distributed Algorithms (22903) Lecturer: Danny Hendler Lock-free stack algorithms.
Data Structures and Algorithm Analysis Dr. Ken Cosh Linked Lists.
List Structures What is a list? A homogeneous collection of elements with a linear relationship between the elements linear relationship - each element.
Lecture 6 of Computer Science II
Hazard Pointers C++ Memory Ordering Issues
Background on the need for Synchronization
Concepts of programming languages
CS510 Concurrent Systems Jonathan Walpole.
Practical Non-blocking Unordered Lists
LINKED LISTS CSCD Linked Lists.
Anders Gidenstam Håkan Sundell Philippas Tsigas
Introduction to Linked Lists
Lists.
Arrays and Linked Lists
CS510 Concurrent Systems Jonathan Walpole.
CS510 - Portland State University
Linked Lists.
CS212D: Data Structures Week 5-6 Linked List.
CS510 Advanced Topics in Concurrency
CS510 Concurrent Systems Jonathan Walpole.
EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019
Presentation transcript:

Hazard Pointers: Safe Memory Reclamation for Lock-Free Objects MAGED M. MICHAEL PRESENTED BY NURIT MOSCOVICI ADVANCED TOPICS IN CONCURRENT PROGRAMMING, TECHNION, WINTER

Motivation o Many lock-free algorithms dynamically allocate memory o Reclamation is difficult with no Garbage Collection o In lock-free algorithms any thread can operate on any part of the object at any time. 2

Memory Reclamation o Reclamation for reuse by algorithm: o May corrupt object (ABA) o Reclamation for return to OS: o May cause violation error 3

Memory Reclamation o Reclamation for reuse by algorithm: o May corrupt object (ABA) o Reclamation for return to OS: o May cause violation error 4

ABA problem o Common in lock-free algorithms when memory is released and then reused. o Some ABA problems fixed by safe memory reclamation o Common misconception: All ABA can be fixed this way A P1 B P2 P2: Read val=A Write val = B Write val = A 5 Val

Example – Lock-Free Queue 6 Access Hazard! ABA Hazard!ABA Hazard! ABA Hazard! Access+ ABA Hazard! ABA Hazard! Structure: Head, Tail Node: {Data, Next}

What do we want? o Lock-freedom: tolerate thread delays and failures o Bounded un-reclaimable memory o Enable reuse of memory/return to OS o Easily applicable to existing algorithms o Portability: No need for special HW/kernel support o Efficiency 7

Agenda o Previous Solutions o Hazard Pointers: Basic Solution o Correctness o Using Hazard Pointers o Hazard Pointers: Extended Solution o Results 8

Previous Solutions 9

Non-Blocking Solutions ABA-Prevention Tags o Requires double-width atomic operations o Often does not allow return to OS Lock-Free Reference Counting o Two options: o Use DCAS (mostly unsupported) o Independently CAS pointers and counter non-atomically (hinders reclamation) 10 A12 Cas(&Val,, ) B13 A34

Scheduler-Dependent and Blocking Methods 11

Hazard Pointers 12

Assumptions o For now, assume number of threads is known to be N o Assume each thread has exactly K unsafe references o Unsafe reference: may cause problems if used without validation o Observation: most lock-free algorithms use only a small number of unsafe references per thread. 13

General Idea null C B C ABC … D 14

null General Idea Using Memory: o Must store references in hazard pointers before accessing memory. Reclaiming Memory: o Check hazard pointers of all other threads o Reclamation is forbidden if node referenced by some hazard pointer. A B null C B C ABC … D AB 15

Data Structures o Shared Data: o HPList: Linked list of HPRecords containing hazard pointers o Private (per-thread) Data: o RList: List of nodes the thread has retired from the structure, but has not yet released. AB HPList Head … (N records) C E RList CB 16

Algorithm Algorithm consists of two parts: 1. Algorithm for processing retired nodes o Can be used as-is in every lock-free data structure 2. Condition: an invariant that must be upheld when adding hazard pointers to existing code. o Requires understanding of target lock-free data structure o Must be specially adjusted for every such data structure 17

Part 1: Retiring a Node 18 AFB HPList Head … (N records) C E RList CB F

Scan: Phase 1 o Create temporary local hash table o Iterate over all HPRecs in HPList o Add every non-NULL Hazard Pointer to hash table 19 AFB HPList Head … (N records) C E RList CB F A FB C H G

Scan: Phase 2 o Copy Rlist to temporary new local list o Iterate over tempList and search for each node in hash table o Found: return to Rlist until next scan o Not Found: Call function to release/reuse node o Free the temporary hash table and list 20 RList C E F A FB C H G C E F C F

Complexity of Retiring a Node 21

Complexity of Retiring a Node 22

Some Definitions 23 Head

Safety 24

Some More Definitions 25

Condition for correctness 26 What does this give us?

Correctness 27

A Quick Sketch of Correctness 28

Which gives us: 29

Using Hazard Pointers 30

So, How Do We Apply Hazard Pointers? 31

Back to the Lock-Free Queue 32 Access Hazard! ABA Hazard!ABA Hazard! ABA Hazard! Access+ ABA Hazard! ABA Hazard! Structure: Head, Tail Node: {Data, Next}

What About Dequeue? 33 ABA Hazard!ABA Hazard! Access Hazard! ABA Hazard!

What About Dequeue? 34 ABA Hazard!ABA Hazard! Access Hazard! ABA Hazard!

What About Dequeue? 35 ABA Hazard!ABA Hazard! Access Hazard! ABA Hazard! Access Hazard!

What Now? 36

Applying Hazard Pointers to Enqueue 37 ABA Hazard!ABA Hazard!

Applying Hazard Pointers to Dequeue 38 ABA Hazard!ABA Hazard!

Hazard Pointer Application o Hazard Pointer algorithm can be applied by algorithm designers o Cannot easily be done automatically (by a compiler) o Requires a good understanding of the semantics of the algorithm 39

List-Based Set 40 ABA Hazard!ABA Hazard!

List-Based Set: Adding Hazard Pointers 41 ABA Hazard!ABA Hazard! Assume prev holds head, and so is safe here.

List-Based Set 42 ABA Hazard!ABA Hazard! Search( head, key ) return Find( head, key )

Extended Version 43

Unknown Number of Threads o Allow threads to push new records to global list o Can also be used to make K dynamic o Wait free, as number of threads is finite* 44 HPList Head null

Unknown Number of Threads o Allow threads to push new records to global list o Can also be used to make K dynamic o Wait free, as number of threads is finite* 45 HPList Head null

Unknown Number of Threads o Allow threads to push new records to global list o Can also be used to make K dynamic o Wait free, as number of threads is finite* 46 HPList Head null

Dynamic Join and Leave of Threads Allow reuse of HPs : o Add active indicator flag to each HP record o Acquire inactive record using TAS on flag o Only allocate new record if all existing records are active o Save retired list in record, so retiring thread can pass on it’s un-reclaimed nodes 47 HPList Head null

Guarantee Freeing of All Nodes 48 HPList Head null

Results 49

Results o Same as lock-based implementation under no contention o Better than or equal to ABA-tags and reference counting 50

Questions? 51