Concurrent Tries with Efficient Non-blocking Snapshots Aleksandar Prokopec Phil Bagwell Martin Odersky École Polytechnique Fédérale de Lausanne Nathan.

Slides:



Advertisements
Similar presentations
Planar point location -- example
Advertisements

Enabling Speculative Parallelization via Merge Semantics in STMs Kaushik Ravichandran Santosh Pande College.
Network Algorithms, Lecture 4: Longest Matching Prefix Lookups George Varghese.
CS412/413 Introduction to Compilers Radu Rugina Lecture 37: DU Chains and SSA Form 29 Apr 02.
Inpainting Assigment – Tips and Hints Outline how to design a good test plan selection of dimensions to test along selection of values for each dimension.
Concurrency The need for speed. Why concurrency? Moore’s law: 1. The number of components on a chip doubles about every 18 months 2. The speed of computation.
Scalable and Lock-Free Concurrent Dictionaries
Data Structures: A Pseudocode Approach with C
Certification of Computational Results Greg Bronevetsky.
Locality-Conscious Lock-Free Linked Lists Anastasia Braginsky & Erez Petrank 1.
On-the-Fly Garbage Collection: An Exercise in Cooperation Edsget W. Dijkstra, Leslie Lamport, A.J. Martin and E.F.M. Steffens Communications of the ACM,
1 Accessing nearby copies of replicated objects Greg Plaxton, Rajmohan Rajaraman, Andrea Richa SPAA 1997.
Multiversion Access Methods - Temporal Indexing. Basics A data structure is called : Ephemeral: updates create a new version and the old version cannot.
Threading Part 3 CS221 – 4/24/09. Teacher Survey Fill out the survey in next week’s lab You will be asked to assess: – The Course – The Teacher – The.
CS 315 March 24 Goals: Heap (Chapter 6) priority queue definition of a heap Algorithms for Insert DeleteMin percolate-down Build-heap.
Temporal Indexing MVBT. Temporal Indexing Transaction time databases : update the last version, query all versions Queries: “Find all employees that worked.
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.
Temporal Indexing MVBT. Temporal Indexing Transaction time databases : update the last version, query all versions Queries: “Find all employees that worked.
Binary Search Introduction to Trees. Binary searching & introduction to trees 2 CMPS 12B, UC Santa Cruz Last time: recursion In the last lecture, we learned.
CS 333 Introduction to Operating Systems Class 18 - File System Performance Jonathan Walpole Computer Science Portland State University.
CS510 Concurrent Systems Class 2 A Lock-Free Multiprocessor OS Kernel.
CSE 373 Data Structures Lecture 12
Language Support for Lightweight transactions Tim Harris & Keir Fraser Presented by Narayanan Sundaram 04/28/2008.
Chapter 12 Trees. Copyright © 2005 Pearson Addison-Wesley. All rights reserved Chapter Objectives Define trees as data structures Define the terms.
Wide-area cooperative storage with CFS
CSE 326: Data Structures Binomial Queues Ben Lerner Summer 2007.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 Tree-Structured Indexes Chapter 9.
Tree-Structured Indexes. Range Searches ``Find all students with gpa > 3.0’’ –If data is in sorted file, do binary search to find first such student,
Maria-Cristina Marinescu Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology A Synthesis Algorithm for Modular Design of.
Chapter 61 Chapter 6 Index Structures for Files. Chapter 62 Indexes Indexes are additional auxiliary access structures with typically provide either faster.
Symbol Table (  ) Contents Map identifiers to the symbol with relevant information about the identifier All information is derived from syntax tree -
Practical and Lock-Free Doubly Linked Lists Håkan Sundell Philippas Tsigas.
Database Management 8. course. Query types Equality query – Each field has to be equal to a constant Range query – Not all the fields have to be equal.
Tolerating Faults in Distributed Systems
CS510 Concurrent Systems Jonathan Walpole. A Lock-Free Multiprocessor OS Kernel.
Computer Algorithms Submitted by: Rishi Jethwa Suvarna Angal.
Sándor Héman Marcin Zukowski Niels Nes Lefteris Sidirourgos Peter Boncz Positional Update Handling in Column Stores.
A Consistency Framework for Iteration Operations in Concurrent Data Structures Yiannis Nikolakopoulos A. Gidenstam M. Papatriantafilou P. Tsigas Distributed.
Apr 17, 2013 Persistent Data Structures. Definitions An immutable data structure is one that, once created, cannot be modified Immutable data structures.
Recap form last time How to do for loops map, filter, reduce Next up: dictionaries.
Amortized Algorithm Analysis COP3503 July 25, 2007 Andy Schwartz.
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.
Range Queries in Non-blocking k-ary Search Trees Trevor Brown Hillel Avni.
Ordered Linked Lists using Abstract Data Types (ADT) in Java Presented by: Andrew Aken.
Hazard Pointers: Safe Memory Reclamation for Lock-Free Objects Maged M. Michael Presented by Abdulai Sei.
CS333 Intro to Operating Systems Jonathan Walpole.
Software Transactional Memory Should Not Be Obstruction-Free Robert Ennals Presented by Abdulai Sei.
Binary Search Trees (BSTs) 18 February Binary Search Tree (BST) An important special kind of binary tree is the BST Each node stores some information.
CS510 Concurrent Systems Jonathan Walpole. RCU Usage in Linux.
November 27, 2007 Verification of a Concurrent Priority Queue Bart Verzijlenberg.
Linked Lists (continued). Maintaining Order Creating an ordered list 3 Baltimore head Rome Seattle Toronto  (1) Insert node containing (reference to.
Effective C# Item 10 and 11. Understand the Pitfalls of GetHashCode Item 10.
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,
An Exact Algorithm for Difficult Detailed Routing Problems Kolja Sulimma Wolfgang Kunz J. W.-Goethe Universität Frankfurt.
(c) University of Washington20c-1 CSC 143 Binary Search Trees.
Database Applications (15-415) DBMS Internals- Part III Lecture 13, March 06, 2016 Mohammad Hammoud.
Disk Cache Main memory buffer contains most recently accessed disk sectors Cache is organized by blocks, block size = sector’s A hash table is used to.
Jonathan Walpole Computer Science Portland State University
[Chapter 4; Chapter 6, pp ] CSC 143 Linked Lists (cont) [Chapter 4; Chapter 6, pp ]
Binomial Heaps On the surface it looks like Binomial Heaps are great if you have no remove mins. But, in this case you need only keep track of the current.
Persistent data structures
Multicore programming
Database Systems (資料庫系統)
Multicore programming
Multicore programming
CSC 143 Binary Search Trees.
Presentation transcript:

Concurrent Tries with Efficient Non-blocking Snapshots Aleksandar Prokopec Phil Bagwell Martin Odersky École Polytechnique Fédérale de Lausanne Nathan Bronson Stanford

Motivation val numbers = getNumbers() // compute square roots numbers foreach { entry => x = entry.root n = entry.number entry.root = 0.5 * (x + n / x) if (abs(entry.root - x) < eps) numbers.remove(entry) }

Hash Array Mapped Tries (HAMT)

0 =

Hash Array Mapped Tries (HAMT) 0

0 16 =

Hash Array Mapped Tries (HAMT) 016

Hash Array Mapped Tries (HAMT) =

Hash Array Mapped Tries (HAMT) =

Hash Array Mapped Tries (HAMT) 16 04

Hash Array Mapped Tries (HAMT) =

Hash Array Mapped Tries (HAMT) =

Hash Array Mapped Tries (HAMT)

Hash Array Mapped Tries (HAMT)

Hash Array Mapped Tries (HAMT)

Hash Array Mapped Tries (HAMT)

Hash Array Mapped Tries (HAMT)

Hash Array Mapped Tries (HAMT)

Immutable HAMT used as immutable maps in functional languages

Immutable HAMT updates rewrite path from root to leaf insert(11)

Immutable HAMT updates rewrite path from root to leaf insert(11) efficient updates - log k (n)

Node compression BITPOP(((1 > lev) & 1F)) – 1) & BMP)

Node compression

Ctrie Can mutable HAMT be modified to be thread-safe?

Ctrie insert =

Ctrie insert = ) allocate

Ctrie insert = ) CAS

Ctrie insert =

Ctrie insert =

Ctrie insert = ) allocate

Ctrie insert = ) CAS

Ctrie insert = ) CAS Unless…

Ctrie insert = T1-1) allocate Unless… 28 = T1 T2

Ctrie insert = T1-1) allocate Unless… 28 = T1 T T2-1) allocate

Ctrie insert = T1-1) allocate = T1 T T2-2) CAS

Ctrie insert = T1-2) CAS = T1 T T2-2) CAS

Ctrie insert = = T1 T Lost insert!

Ctrie insert – 2 nd attempt Solution: I-nodes

Ctrie insert – 2 nd attempt = = T1 T2

Ctrie insert – 2 nd attempt T1 T = = T2-1) allocate T1-1) allocate

Ctrie insert – 2 nd attempt T1 T T2-2) CAS T1-2) CAS

Ctrie insert – 2 nd attempt

Ctrie insert – 2 nd attempt Idea: once added to the Ctrie, I-nodes remain present.

Ctrie insert – 2 nd attempt Remove operation supported as well - details in the paper.

Ctrie size

Ctrie size size = 0

Ctrie size size = 0

Ctrie size size = 0

Ctrie size size = 0

Ctrie size size = 1

Ctrie size size = 2

Ctrie size size = 3

Ctrie size size = 5

Ctrie size size = 5 actual size = 12

Ctrie size size = 5 01 actual size = 12

Ctrie size size = 5 01 CAS actual size = 11

Ctrie size size = 5 01 actual size = 11

Ctrie size size = 6 01 actual size = 11

Ctrie size size = 6 01 actual size = 11 19

Ctrie size size = 6 01 actual size =

Ctrie size size = 6 01 actual size = CAS

Ctrie size size = 6 01 actual size =

Ctrie size size = 6 01 actual size =

Ctrie size size = 7 01 actual size =

Ctrie size size = 8 01 actual size =

Ctrie size size = 9 01 actual size =

Ctrie size size = actual size =

Ctrie size size = actual size =

Ctrie size size = actual size =

Ctrie size size = actual size =

Ctrie size size = actual size = But the size was never 13!

Global state information size find filter iterator

Global state information size find filter iterator  snapshot

Snapshot using locks

Snapshot using locks copy expensive

Snapshot using locks copy expensive not lock-free

Snapshot using locks copy expensive not lock-free can insert or remove remain lock-free? 01 2 CAS

Snapshot using locks copy expensive not lock-free can insert or remove remain lock-free? 01 2 CAS

Snapshot using logs keep a linked list of previous values in each I-node

Snapshot using logs keep a linked list of previous values in each I-node

Snapshot using logs keep a linked list of previous values in each I-node when is it safe to delete old entries? 01 2

Snapshot using immutability root

Snapshot using immutability #1 root

Snapshot using immutability #1 snapshot! root

Snapshot using immutability #1 snapshot! #2 root 1) create new I-node at #2

Snapshot using immutability #1 snapshot! #2 root 2) set snapshot snapshot #1

Snapshot using immutability #1 snapshot! #2 root 3) CAS root to new I-node snapshot #1

Snapshot using immutability #1 subsequent insert #2 rootsnapshot #1 2

Snapshot using immutability #1 subsequent insert #2 rootsnapshot #1 2 generation #2 - ok!

Snapshot using immutability #1 subsequent insert #2 rootsnapshot #1 2 generation #1 not ok, too old!

Snapshot using immutability #1 subsequent insert #2 root 1) create updated node at #2 snapshot #1 2 #2

Snapshot using immutability #1 subsequent insert #2 root 2) CAS to the updated node snapshot #1 2 #2

Snapshot using immutability #1 subsequent insert #2 rootsnapshot #1 2 #2 #1 too old!

Snapshot using immutability #1 subsequent insert #2 rootsnapshot #1 2 # #2 1) create updated node at #2

Snapshot using immutability #1 subsequent insert #2 rootsnapshot #1 2 # #2 2) CAS

Snapshot using immutability #1 subsequent insert #2 rootsnapshot #1 # # finally, create a new leaf and CAS

Snapshot using immutability #1 another insert #2 rootsnapshot #1 # #

Snapshot using immutability #1 another insert #2 rootsnapshot #1 # #

Snapshot using immutability #1 But... this won't really work... why? #2 rootsnapshot #1 # #

Snapshot using immutability #1 #2 rootsnapshot #1 # # T2: remove

Snapshot using immutability #1 #2 rootsnapshot #1 # # T2: remove CAS

Snapshot using immutability #1 #2 rootsnapshot #1 # # T2: remove CAS How to fail this last CAS?

Snapshot using immutability #1 #2 rootsnapshot #1 # # T2: remove DCAS How to fail this last CAS? DCAS

Snapshot using immutability #1 #2 rootsnapshot #1 # # T2: remove How to fail this last CAS? DCAS - software based DCAS

Snapshot using immutability #1 #2 rootsnapshot #1 # # T2: remove How to fail this last CAS? DCAS - software based...creates intermediate objects DCAS

GCAS - generation-compare-and-swap #1 #2 rootsnapshot #1 # # T2: remove prev 1) set prev field

GCAS - generation-compare-and-swap #1 #2 rootsnapshot #1 # # T2: remove prev 2) CAS

GCAS - generation-compare-and-swap #1 #2 rootsnapshot #1 # # T2: remove prev 3) read root generation

GCAS - generation-compare-and-swap #1 #2 rootsnapshot #1 # # prev 4) if root generation changed CAS prev to FailedNode(prev) FN

GCAS - generation-compare-and-swap #1 #2 rootsnapshot #1 # # prev 4) if root generation changed CAS prev to FailedNode(prev) FN

GCAS - generation-compare-and-swap #1 #2 rootsnapshot #1 # # prev 5) CAS to previous value FN

GCAS - generation-compare-and-swap #1 #2 rootsnapshot #1 # # prev 4) if root generation unchanged CAS prev to null

GCAS - generation-compare-and-swap #1 #2 rootsnapshot #1 # # ) if root generation unchanged CAS prev to null

GCAS - generation-compare-and-swap #1 #2 rootsnapshot #1 # # ) Replace all CAS with GCAS 2) Replace all READ with GCAS_READ (which checks if prev field is null)

Snapshot-based iterator def iterator = if (isSnapshot) new Iterator(root) else snapshot().iterator()

Snapshot-based size def size = { val sz = 0 val it = iterator while (it.hasNext) sz += 1 sz }

Snapshot-based size def size = { val sz = 0 val it = iterator while (it.hasNext) sz += 1 sz } Above is O(n). But, by caching size in nodes - amortized O(log k n)! (see source code)

Snapshot-based atomic clear def clear() = { val or = READ(root) val nr = new INode(new Gen) if (!CAS(root, or, nr)) clear() } (roughly)

Evaluation - quad core i7

Evaluation – UltraSPARC T2

Evaluation – 4x 8-core i7

Evaluation – snapshot

Conclusion snapshots are linearizable and lock-free snapshots take constant time snapshots are horizontally scalable snapshots add a non-significant overhead to the algorithm if they aren't used the approach may be applicable to tree-based lock-free data-structures in general (intuition)

Thank you!