A Simple Optimistic skip-list Algorithm Maurice Herlihy Brown University & Sun Microsystems Laboratories Yossi Lev Brown University & Sun Microsystems.

Slides:



Advertisements
Similar presentations
CS16: Introduction to Data Structures & Algorithms
Advertisements

David Luebke 1 6/7/2014 CS 332: Algorithms Skip Lists Introduction to Hashing.
Fast and Lock-Free Concurrent Priority Queues for Multi-Thread Systems Håkan Sundell Philippas Tsigas.
The Dictionary ADT: Skip List Implementation
Multicore Programming Skip list Tutorial 10 CS Spring 2010.
Wait-Free Linked-Lists Shahar Timnat, Anastasia Braginsky, Alex Kogan, Erez Petrank Technion, Israel Presented by Shahar Timnat 469-+
Alon Efrat Computer Science Department University of Arizona SkipList.
Stacks & Their Applications COP Stacks  A stack is a data structure that stores information arranged like a stack.  We have seen stacks before.
Chapter 4: Trees Part II - AVL Tree
Scalable and Lock-Free Concurrent Dictionaries
Data Structures: A Pseudocode Approach with C
Linked Lists: Lazy and Non-Blocking Synchronization Based on the companion slides for The Art of Multiprocessor Programming (Maurice Herlihy & Nir Shavit)
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.
Universidad Nacional de Colombia Facultad de Ingeniería Departamento de Sistemas nalysis of lgorithms.
SKIPLISTS A Probabilistic Alternative to Balanced Trees.
© 2004 Goodrich, Tamassia Skip Lists1  S0S0 S1S1 S2S2 S3S3    2315.
Linked Lists: Locking, Lock- Free, and Beyond … Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit.
Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit Concurrent Skip Lists.
Skip Lists1 Skip Lists William Pugh: ” Skip Lists: A Probabilistic Alternative to Balanced Trees ”, 1990  S0S0 S1S1 S2S2 S3S3 
Introduction To Algorithms CS 445 Discussion Session 2 Instructor: Dr Alon Efrat TA : Pooja Vaswani 02/14/2005.
1 Search Trees - Motivation Assume you would like to store several (key, value) pairs in a data structure that would support the following operations efficiently.
CSCE 3110 Data Structures & Algorithm Analysis Binary Search Trees Reading: Chap. 4 (4.3) Weiss.
Copyright 2007 Sun Microsystems, Inc SNZI: Scalable Non-Zero Indicator Yossi Lev (Brown University & Sun Microsystems Laboratories) Joint work with: Faith.
November 15, 2007 A Java Implementation of a Lock- Free Concurrent Priority Queue Bart Verzijlenberg.
Linked Lists: Locking, Lock- Free, and Beyond … Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit.
CSC 211 Data Structures Lecture 13
Linked Lists: Optimistic, Lock-Free, … Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit Modified by Pavol Černý,
Linked Lists: Locking, Lock- Free, and Beyond … Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit Modified by.
Formal verification of skiplist algorithms Student: Trinh Cong Quy Supervisor: Bengt Jonsson Reviewer: Parosh Abdulla.
Concurrent Linked Lists and Linearizability Proofs Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit Modified.
Skip Lists 二○一七年四月二十五日
Advanced Locking Techniques
Skiplist-based Concurrent Priority Queues Itay Lotan Stanford University Nir Shavit Sun Microsystems Laboratories.
Range Queries in Non-blocking k-ary Search Trees Trevor Brown Hillel Avni.
CMSC 341 Skip Lists. 8/3/2007 UMBC CMSC 341 SkipList 2 Looking Back at Sorted Lists Sorted Linked List What is the worst case performance of find( ),
Chapter 12 Heaps & HeapSort © John Urrutia 2014, All Rights Reserved1.
HEAPS. Review: what are the requirements of the abstract data type: priority queue? Quick removal of item with highest priority (highest or lowest key.
AVL Trees and Heaps. AVL Trees So far balancing the tree was done globally Basically every node was involved in the balance operation Tree balancing can.
Priority Queues Dan Dvorin Based on ‘The Art of Multiprocessor Programming’, by Herlihy & Shavit, chapter 15.
Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit Concurrent Skip Lists.
Linked Lists: Locking, Lock-Free, and Beyond … Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit.
SkipLists and Balanced Search The Art Of MultiProcessor Programming Maurice Herlihy & Nir Shavit Chapter 14 Avi Kozokin.
2/19/2016 3:18 PMSkip Lists1  S0S0 S1S1 S2S2 S3S3    2315.
An algorithm of Lock-free extensible hash table Yi Feng.
1 Linked List. Outline Introduction Insertion Description Deletion Description Basic Node Implementation Conclusion.
Linked Lists: Locking, Lock- Free, and Beyond … Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit.
Linked Lists: Locking, Lock- Free, and Beyond … Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit.
1 Chapter 4 Unordered List. 2 Learning Objectives ● Describe the properties of an unordered list. ● Study sequential search and analyze its worst- case.
2 Binary Heaps What if we’re mostly concerned with finding the most relevant data?  A binary heap is a binary tree (2 or fewer subtrees for each node)
Linked Lists Chapter Introduction To The Linked List ADT Linked list: set of data structures (nodes) that contain references to other data structures.
Course: Programming II - Abstract Data Types HeapsSlide Number 1 The ADT Heap So far we have seen the following sorting types : 1) Linked List sort by.
Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit Concurrent Skip Lists.
Skip Lists. Linked Lists Fast modifications given a pointer Slow traversals to random point.
Lecture 9 : Concurrent Data Structures Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit.
6.852 Lecture 21 ● Techniques for highly concurrent objects – coarse-grained mutual exclusion – read/write locking – fine-grained locking (mutex and read/write)
Linked Lists: Locking, Lock-Free, and Beyond …
Lecture 6-1 : Concurrent Data Structures (Concurrent Linked Lists)
Linked Lists: Locking, Lock-Free, and Beyond …
Chapter 20: Binary Trees.
Monday, April 16, 2018 Announcements… For Today…
Chapter 21: Binary Trees.
Linked Lists: Locking, Lock-Free, and Beyond …
Concurrent Data Structures Concurrent Algorithms 2017
Linked Lists: Locking, Lock-Free, and Beyond …
A Robust Data Structure
Multicore programming
A Concurrent Lock-Free Priority Queue for Multi-Thread Systems
Multicore programming
Linked Lists: Locking, Lock-Free, and Beyond …
EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019
Presentation transcript:

A Simple Optimistic skip-list Algorithm Maurice Herlihy Brown University & Sun Microsystems Laboratories Yossi Lev Brown University & Sun Microsystems Laboratories Victor Luchangco Sun Microsystems Laboratories Nir Shavit Tel-Aviv University & Sun Microsystems Laboratories Assaf Shemesh

Talk outline  Introduction.  What is skip-list?  The Algorithm.  Add operation.  Remove operation.  Contains operation.  Correctness.  Performance.  Conclusions.

Why use skip-list on Concurrent Programming? Why not use trees? like Red-Black trees, AVL trees, etc… Because trees need to be rebalanced after adding and removing items. This operations are GLOBAL.

Introduction Important data structure for storing and retrieving ordered in-memory data. This algorithm VS Implementation by Pugh and by Doug Lea. Main keys of this algorithm: Optimistic - The methods traverse the list without acquiring locks. In addition Only when a method discovers the items it is seeking, does it lock the item and its predecessors. Lazy - removing an item involves logically deleting it by marking it before it is physically removed. A typical pattern is 90% search operations, 9% inserts, and only 1% deletes Works as well as the Lea’s algorithm under this common usage pattern, and much better only under uncommon conditions of extreme contention in multi programmed environments. This algorithm provide a viable alternative to Lea algorithm.

What is skip-list? Linked list sorted by keys. Each node is assigned a random height, up to maximum for some fixed probability P. The number of nodes at any height decreases exponentially with that height. Each node has one successor at each level of height. INVARIENT: Each list is a sub list of the list at the layer beneath it. Usually there is a left sentinel and right sentinel at the beginning and the end of the lists with maximum height.

What is skip-list? Operations on skip-list   S1S1 S2S2 S3S3  31  64  3134    S0S0  Searching – search 78 in the set O(logn)

The algorithm Class Node{ int key ; int topLayer ; Node** nexts ; bool marked ; bool fullyLinked; Lock lock ; }; Lazy list at each layer. The key of each node is strictly greater than the key of its predecessor. The value of the height of the node. Array in size of top layer. For each layer the node contain his successor. Boolean value which is used to make remove operations appear atomic. Boolean value which is set to true after a node has been linked in at all its layers The value of the node.

The algorithm A key is in the abstract set if and only if there is an unmarked, fully linked node with that key in the list. changes are made to the list structure only when locks are acquired for all nodes that need to be modified. Use LSentinel and RSentinel with the values MININT-1 and MAXINT+1. MININT - The lowest value that can enter the set. MAXINT - The highest value that can enter the set.

The algorithm Searching the set us accomplished by the findNode helper function. findNode – Input: A key v and two arrays of node pointers, “preds” and “succs”. Output: Returns the height if the node if it was found, otherwise, it returns -1. sets “preds” and “succs” accordantly. findNode searches exactly as in a sequential skip-list. findNode does not acquire any locks. findNode don’t retry in case of conflicting access with some other thread. “findNode” helper function

The algorithm int findNode ( int v,Node* preds [ ],Node* succs [ ] ) { int lFound = -1; Node* pred = &LSentinel ; for (int layer = MaxHeight -1;layer > 0 ;layer--) { Node* curr = pred->nexts [ layer ] ; while ( v > curr->key ) { pred = curr ; curr = pred->nexts [ layer ] ; } if ( lFound == -1 && v == curr->key ) { lFound = layer ; } preds [ layer ] = pred ; succs [ layer ] = curr ; } return lFound ; } “findNode” helper function

The algorithm - add add(v) adds v to the set and returns true iff v was not already in the set. Calls findNode to determine whether a node with the key is already in the list. General Description int topLayer = randomLevel ( MaxHeight ) ; Node* preds [ MaxHeight ], succs [MaxHeight ] ; while ( true ) { int lFound = findNode ( v, preds, succs ) ; if ( lFound != -1) { Node* nodeFound = succs [ lFound ] ; if ( ! nodeFound->marked ) { while ( ! nodeFound->fullyLinked ) { ; } return false ; } continue ; } STEP 1

The algorithm - add Example – add 6 to the set - Marked flag - Fullylinked flag

The algorithm - add Example – add 6 to the set - Marked flag - Fullylinked flag STEP 1

The algorithm - add add(v) adds v to the set and returns true iff v was not already in the set. locks and validates all the predecessors returned by findNode up to the height of the new node. General Description Int highestLocked = -1; try { Node *pred, *succ, *prevPred = null ; bool valid = true ; for ( int layer = 0 ; valid && ( layer <= topLayer ) ;layer++) { pred = preds [ layer ] ; succ = succs [ layer ] ; if ( pred != prevPred ) { pred->lock. lock ( ) ; highestLocked = layer ; prevPred = pred ; } valid = ! Pred->marked && ! Succ->marked && pred¡>nexts [ layer]==succ ; } If ( ! valid ) continue; STEP 2

The algorithm - add Example – add 6 to the set - Marked flag - Fullylinked flag STEP 2

The algorithm - add add(v) adds v to the set and returns true iff v was not already in the set. allocates a new node with the appropriate key and height and links it in. General Description Node* newNode = new Node ( v, topLayer ) ; for ( int layer = 0 ;layer <= topLayer ;layer++) { newNode->nexts [ layer ] = succs [ layer ] ; preds [ layer]->nexts [ layer ] = newNode ; } newNode->fullyLinked = true; return true ; }//end of try finally { unlock ( preds, highestLocked ) ; } }//end of function STEP 3

The algorithm - add Example – add 6 to the set - Marked flag - Fullylinked flag STEP Fullylinked = true

The algorithm - add Example – add 6 to the set - Marked flag - Fullylinked flag Success!

The algorithm - remove removes v from the set and returns true iff v was in the set. okToDelete function General Description bool okToDelete ( Node¤ candidate, int lFound ) { return ( candidate->fullyLinked && candidate->topLayer==lFound && !Candidate->marked ) ; }

The algorithm - remove removes v from the set and returns true iff v was in the set. determine whether a node with the appropriate key is in the list General Description Node* nodeToDelete = null ; bool isMarked = false ; int topLayer = -1; Node* preds [ MaxHeight ], succs [ MaxHeight ] ; while ( true ) { int lFound = findNode ( v, preds, succs ) ; if ( isMarked || ( lFound != -1 && okToDelete ( succs [ lFound ], lFound ) ) ) { if ( ! isMarked ) { nodeToDelete = succs [ lFound ] ; topLayer = nodeToDelete->topLayer ; nodeToDelete->lock. lock ( ) ; if ( nodeToDelete¡>marked ) { nodeToDelete->lock. unlock ( ) ; return false ; } nodeToDelete->marked = true ; isMarked = true ; } STEP 1

The algorithm - remove Example – remove 6 from the list Marked flag - Fullylinked flag

The algorithm - remove Example – remove 6 from the list - Marked flag - Fullylinked flag STEP 1

The algorithm - remove removes v from the set and returns true iff v was in the set. locking its predecessors at all layers up to the height of the deleted node General Description int highestLocked = -1; try { Node *pred, *succ, *prevPred = null ; bool valid = true ; for ( int layer = 0 ;valid && ( layer <= topLayer ) ;layer++) { pred = preds [ layer ] ; succ = succs [ layer ] ; if ( pred != prevPred ) { pred->lock. lock ( ) ; highestLocked = layer ; prevPred = pred ; } valid = ! Pred->marked && pred->nexts [ layer]==succ ; } if ( ! valid ) continue ; STEP 2

The algorithm - remove Example – remove 6 from the list - Marked flag - Fullylinked flag

The algorithm - remove removes v from the set and returns true iff v was in the set. splicing the node out one layer at a time General Description for (int layer = topLayer ; layer >=0 ; layer--) { preds [ layer]->nexts [ layer ] = nodeToDelete->nexts [ layer ] ; } nodeToDelete->lock. unlock ( ) ; return true ; }//end of try finally { unlock ( preds, highestLocked ) ; } }//end of if(true) else return false ; }//end of while }//end of function STEP 3

The algorithm - remove Example – remove 6 from the list - Marked flag - Fullylinked flag STEP 3

The algorithm - remove Example – remove 6 from the list - Marked flag - Fullylinked flag STEP 3

The algorithm - remove Example – remove 6 from the list - Marked flag - Fullylinked flag STEP 3

The algorithm - remove Example – remove 6 from the list - Marked flag - Fullylinked flag STEP 3

The algorithm - remove Example – remove 6 from the list - Marked flag - Fullylinked flag STEP 3

The algorithm - contains returns true iff v is in the set General Description calls findNode and returns true if and only if it finds a unmarked, fully linked node with the appropriate key.

Correctness Linearzability Linearizability: (an intuitive definition) Can find a point within the time-interval of each operation, where the operation took place, such that the operations order is legal. an operation (or set of operations) is linearizable if it appears to the rest of the system to occur instantaneously. time q.enq(x) q.enq(y)q.deq(x) q.deq(y) q.enq(x) q.enq(y)q.deq(x) q.deq(y) time

Correctness Linearzability point of REMOVE is when MARKED bit is set. Linearzability point of ADD is when FULLYLINKED bit is set. Linearzability time Add(v) Remove(v) time newNode->fullyLinked = true ; nodeToDelete->marked = true ;

Correctness Maintaining the skip-list invariant skip-list invariant - the list at each layer is a sub list of the lists at lower layers. Add operation - linking new nodes into the skip list always proceeds from bottom to top. Remove operation - the higher layers are unlinked before the lower layers.

Correctness Dead lock freedom a thread always acquires locks on nodes with larger keys first. if a thread holds a lock on a node with key v then it will not attempt to acquire a lock on a node with key greater than or equal to v. acquiring locks on the predecessor nodes from the bottom layer up Contains operation is: a.Wait-freedom b.Lock-freedom c.Obstruction-freedom (if every operation has a bound on the number of steps the algorithm will take before the operation completes) (if it satisfies that when the program threads are run sufficiently long at least one of the threads make progress) (if at any point, a single thread executed in isolation)

Performance This algorithm VS Concurrent skip-list written by Doug Lea Throughput in operations per millisecond of 1,000,000 operations 90% search operations, 9% inserts, and only 1% deletes. Different versions of Experiments

Conclusions A scalable highly concurrent skip-list using a simple algorithm. Support operations - Add, Remove, Contains. Simple correctness prove For most uses, it offers an interesting viable alternative to the Concurrent Skip List by Doug Lea.