Fast and Lock-Free Concurrent Priority Queues for Multi-Thread Systems Håkan Sundell Philippas Tsigas.

Slides:



Advertisements
Similar presentations
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Advertisements

Wait-Free Linked-Lists Shahar Timnat, Anastasia Braginsky, Alex Kogan, Erez Petrank Technion, Israel Presented by Shahar Timnat 469-+
Wait-Free Queues with Multiple Enqueuers and Dequeuers
A Block-structured Heap Simplifies Parallel GC Simon Marlow (Microsoft Research) Roshan James (U. Indiana) Tim Harris (Microsoft Research) Simon Peyton.
Håkan Sundell, Chalmers University of Technology 1 Evaluating the performance of wait-free snapshots in real-time systems Björn Allvin.
Synchronization. How to synchronize processes? – Need to protect access to shared data to avoid problems like race conditions – Typical example: Updating.
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community.
1 Chapter 4 Synchronization Algorithms and Concurrent Programming Gadi Taubenfeld © 2014 Synchronization Algorithms and Concurrent Programming Synchronization.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
CS492B Analysis of Concurrent Programs Lock Basics Jaehyuk Huh Computer Science, KAIST.
Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
Mutual Exclusion By Shiran Mizrahi. Critical Section class Counter { private int value = 1; //counter starts at one public Counter(int c) { //constructor.
Chapter 6: Process Synchronization
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 5: Process Synchronization.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
CH7 discussion-review Mahmoud Alhabbash. Q1 What is a Race Condition? How could we prevent that? – Race condition is the situation where several processes.
Scalable and Lock-Free Concurrent Dictionaries
(C) Ph. Tsigas © Ph. Tsigas Algorithm Engineering of Parallel Algorithms and Parallel Data Structures Philippas Tsigas.
Wait-Free Reference Counting and Memory Management Håkan Sundell, Ph.D.
Håkan Sundell, Chalmers University of Technology 1 Space Efficient Wait-free Buffer Sharing in Multiprocessor Real-time Systems Based.
Data Structures: A Pseudocode Approach with C 1 Chapter 5 Contd... Objectives Explain the design, use, and operation of a linear list Implement a linear.
Parallel Processing (CS526) Spring 2012(Week 6).  A parallel algorithm is a group of partitioned tasks that work with each other to solve a large problem.
ParMarkSplit: A Parallel Mark- Split Garbage Collector Based on a Lock-Free Skip-List Nhan Nguyen Philippas Tsigas Håkan Sundell Distributed Computing.
Introduction to Lock-free Data-structures and algorithms Micah J Best May 14/09.
Computer Laboratory Practical non-blocking data structures Tim Harris Computer Laboratory.
CS510 Advanced OS Seminar Class 10 A Methodology for Implementing Highly Concurrent Data Objects by Maurice Herlihy.
CS510 Concurrent Systems Class 2 A Lock-Free Multiprocessor OS Kernel.
1 Concurrency: Deadlock and Starvation Chapter 6.
SUPPORTING LOCK-FREE COMPOSITION OF CONCURRENT DATA OBJECTS Daniel Cederman and Philippas Tsigas.
Maria-Cristina Marinescu Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology A Synthesis Algorithm for Modular Design of.
1 Lock-Free Linked Lists Using Compare-and-Swap by John Valois Speaker’s Name: Talk Title: Larry Bush.
Practical and Lock-Free Doubly Linked Lists Håkan Sundell Philippas Tsigas.
CS510 Concurrent Systems Introduction to Concurrency.
Parallel Programming Philippas Tsigas Chalmers University of Technology Computer Science and Engineering Department © Philippas Tsigas.
Simple Wait-Free Snapshots for Real-Time Systems with Sporadic Tasks Håkan Sundell Philippas Tsigas.
CS510 Concurrent Systems Jonathan Walpole. A Lock-Free Multiprocessor OS Kernel.
Håkan Sundell, Chalmers University of Technology 1 Using Timing Information on Wait-Free Algorithms in Real-Time Systems (2 papers)
Håkan Sundell, Chalmers University of Technology 1 NOBLE: A Non-Blocking Inter-Process Communication Library Håkan Sundell Philippas.
November 15, 2007 A Java Implementation of a Lock- Free Concurrent Priority Queue Bart Verzijlenberg.
Håkan Sundell, Chalmers University of Technology 1 Applications of Non-Blocking Data Structures to Real-Time Systems Seminar for the.
Håkan Sundell, Chalmers University of Technology 1 Simple and Fast Wait-Free Snapshots for Real-Time Systems Håkan Sundell Philippas.
1 Announcements The fixing the bug part of Lab 4’s assignment 2 is now considered extra credit. Comments for the code should be on the parts you wrote.
Challenges in Non-Blocking Synchronization Håkan Sundell, Ph.D. Guest seminar at Department of Computer Science, University of Tromsö, Norway, 8 Dec 2005.
Optimistic Design 1. Guarded Methods Do something based on the fact that one or more objects have particular states  Make a set of purchases assuming.
Non-blocking Data Structures for High- Performance Computing Håkan Sundell, PhD.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Mutual Exclusion.
Maged M.Michael Michael L.Scott Department of Computer Science Univeristy of Rochester Presented by: Jun Miao.
Wait-Free Multi-Word Compare- And-Swap using Greedy Helping and Grabbing Håkan Sundell PDPTA 2009.
Skiplist-based Concurrent Priority Queues Itay Lotan Stanford University Nir Shavit Sun Microsystems Laboratories.
A Simple Optimistic skip-list Algorithm Maurice Herlihy Brown University & Sun Microsystems Laboratories Yossi Lev Brown University & Sun Microsystems.
CS510 Concurrent Systems Jonathan Walpole. A Methodology for Implementing Highly Concurrent Data Objects.
CS510 Concurrent Systems Jonathan Walpole. RCU Usage in Linux.
November 27, 2007 Verification of a Concurrent Priority Queue Bart Verzijlenberg.
SkipLists and Balanced Search The Art Of MultiProcessor Programming Maurice Herlihy & Nir Shavit Chapter 14 Avi Kozokin.
Slides created by: Professor Ian G. Harris Operating Systems  Allow the processor to perform several tasks at virtually the same time Ex. Web Controlled.
1 Critical Section Problem CIS 450 Winter 2003 Professor Jinhua Guo.
CS510 Concurrent Systems Jonathan Walpole. Introduction to Concurrency.
Håkan Sundell Philippas Tsigas
Lock-Free Linked Lists Using Compare-and-Swap
A Lock-Free Algorithm for Concurrent Bags
Anders Gidenstam Håkan Sundell Philippas Tsigas
Concurrent Data Structures Concurrent Algorithms 2017
Designing Parallel Algorithms (Synchronization)
Data Structures and Algorithms
NOBLE: A Non-Blocking Inter-Process Communication Library
A Concurrent Lock-Free Priority Queue for Multi-Thread Systems
Kernel Synchronization II
Multicore programming
CSE 153 Design of Operating Systems Winter 19
CSE 451 Section 1/27/2000.
Presentation transcript:

Fast and Lock-Free Concurrent Priority Queues for Multi-Thread Systems Håkan Sundell Philippas Tsigas

Outline Synchronization Methods Priority Queues Concurrent Priority Queues Lock-Free Algorithm: Problems and Solutions Experiments Conclusions

Synchronization Shared data structures needs synchronization Synchronization using Locks Mutually exclusive access to whole or parts of the data structure P1 P2 P3 P1 P2 P3

Blocking Synchronization Drawbacks Blocking Priority Inversion Risk of deadlock Locks: Semaphores, spinning, disabling interrupts etc. Reduced efficiency because of reduced parallelism

Non-blocking Synchronization Lock-Free Synchronization Optimistic approach Assumes its alone and prepares operation which later takes place (unless interfered) in one atomic step, using hardware atomic primitives Interference is detected via shared memory and the atomic primitives Retries until not interfered by other operations Can cause starvation

Non-blocking Synchronization Lock-Free Synchronization Avoids problems with locks Simple algorithms Fast when having low contention Wait-Free Synchronization Always finishes in a finite number of its own steps. Complex algorithms Memory consuming Less efficient in average than lock-free

Priority Queues Fundamental data structure Works on a set of pairs Two basic operations: Insert(v,p): Adds a new element to the priority queue v=DeleteMin(): Removes the element with the highest priority

Sequential Priority Queues All implementations involves search phase in either Insert or DeleteMin Arrays. Maximum complexity O(N) Ordered Lists. O(N) Trees. O(log N) Heaps. O(log N) Advanced structures (i.e. combinations)

Randomized Algorithm: Skip Lists William Pugh: Skip Lists: A Probabilistic Alternative to Balanced Trees, 1990 Layers of ordered lists with different densities, achieves a tree-like behavior Time complexity: O(log 2 N) – probabilistic! HeadTail 50% 25% …

Why Skip Lists for Concurrent Priority Queues? Ordered Lists is simpler than Trees Easier to make efficient concurrently Search complexity is important Skip Lists is an alternative to Trees Lotan and Shavit: Skiplist-Based Concurrent Priority Queues, 2000 Implementation using multiple locks L L LL L LL L L LL L LL LLLLLLL

Our Lock-Free Concurrent Skip List Define node state to depend on the insertion status at lowest level as well as a deletion flag Insert from lowest level going upwards Set deletion flag. Delete from highest level going downwards DDDDDDD p p D

Overlapping operations on shared data Example: Insert operation - which of 2 or 3 gets inserted? Solution: Compare-And-Swap atomic primitive: CAS(p:pointer to word, old:word, new:word):boolean atomic do if *p = old then *p := new; return true; else return false; Insert 3 Insert 2

Dynamic Memory Management Problem: System memory allocation functionality is blocking! Solution (lock-free), IBM freelists: Pre-allocate a number of nodes, link them into a dynamic stack structure, and allocate/reclaim using CAS HeadMem 1Mem 2Mem n … Used 1 Reclaim Allocate

Concurrent Insert vs. Delete operations Problem: - both nodes are deleted! Solution (Harris et al): Use bit 0 of pointer to mark deletion status Delete Insert a) b) * a) b) c)

The ABA problem Problem: Because of concurrency (pre-emption in particular), same pointer value does not always mean same node (i.e. CAS succeeds)!!! Step 1: Step 2:

The ABA problem Solution: (Valois et al) Add reference counting to each node, in order to prevent nodes that are of interest to some thread to be reclaimed until all threads have left the node 1*6* ??? 1 CAS Failes! New Step 2:

Helping Scheme Threads need to traverse safely Need to remove marked-to-be-deleted nodes while traversing – Help! Finds previous node, finish deletion and continues traversing from previous node 1 42* 1 42* or ? ? 1 42*

Back-Off Strategy For pre-emptive systems, helping is necessary for efficiency and lock-freeness For really concurrent systems, overlapping CAS operations (caused by helping and others) on the same node can cause heavy contention Solution: For every failed CAS attempt, back-off (i.e. sleep) for a certain duration, which increases exponentially

Our Lock-Free Algorithm Based on Skip Lists Treated as layers of ordered lists Uses CAS atomic primitive Lock-Free memory management IBM Freelists Reference counting Helping scheme Back-Off strategy All together proved to be linearizable

Experiments 1-30 threads on platforms with different levels of real concurrency Insert vs. DeleteMin operations by each thread. 100 vs initial inserts Compare with other implementations: Lotan and Shavit, 2000 Hunt et al An Efficient Algorithm for Concurrent Priority Queue Heaps, 1996

Full Concurrency

Medium Pre-emption

High Pre-emption

Conclusions Our work includes a Real-Time extension of the algorithm, using time-stamps and a time-stamp recycling scheme Our lock-free algorithm is suitable for both pre-emptive as well as systems with full concurrency Will be available as part of NOBLE software library, See Technical Report for full details,

Questions? Contact Information: Address: Håkan Sundell vs. Philippas Tsigas Computing Science Chalmers University of Technology cs.chalmers.se Web:

Semaphores

Back-off spinlocks

Jones Skew-Heap

The algorithm in more detail Insert: 1. Create node with random height 2. Search position (Remember drops) 3. Insert or update on level 1 4. Insert on level 2 to top (unless already deleted) 5. If deleted then HelpDelete(1) All of this while keeping track of references, help deleted nodes etc.

The algorithm in more detail DeleteMin 1. Mark first node at level 1 as deleted, otherwise HelpDelete(1) and retry 2. Mark next pointers on level 1 to top 3. Delete on level top to 1 while detecting helping, indicate success 4. Free node All of this while keeping track of references, help deleted nodes etc.

The algorithm in more detail HelpDelete(level) 1. Mark next pointer at level to top 2. Find previous node (info in node) 3. Delete on level unless already helped, indicate success 4. Return previous node All of this while keeping track of references, help deleted nodes etc.

Correctness Linearizability (Herlihy 1991) In order for an implementation to be linearizable, for every concurrent execution, there should exist an equal sequential execution that respects the partial order of the operations in the concurrent execution

Correctness Define precise sequential semantics Define abstract state and its interpretation Show that state is atomically updated Define linearizability points Show that operations take effect atomically at these points with respect to sequential semantics Creates a total order using the linearizability points that respects the partial order The algorithm is linearizable

Correctness Lock-freeness At least one operation should always make progress There are no cyclic loop depencies, and all potentially unbounded loops are gate-keeped by CAS operations The CAS operation guarantees that at least one CAS will always succeed The algorithm is lock-free

Real-Time extension DeleteMin operations should ignore nodes that are inserted after the DeleteMin operation started Nodes are inserted together with a timestamp Because timestamps are only used for relative comparisons, no need for a real-time clock Generate time-stamps by increasing function

Real-Time extension Timestamps are potentially unbounded and will overflow Recycle wrapped-over timestamp values by having TagFieldSize=MaxTag*2 Timestamps at nodes can stay forever (MaxTag => unlimited) Every operation traverses one step through the Skiplist and updates too old timestamps