Lock-Free Concurrent Search
Total Page:16
File Type:pdf, Size:1020Kb
THESIS FOR THE DEGREE OF DOCTOR OF PHILOSOPHY Lock-free Concurrent Search BAPI CHATTERJEE Division of Networks and Systems Department of Computer Science and Engineering CHALMERS UNIVERSITY OF TECHNOLOGY Göteborg, Sweden 2017 Lock-free Concurrent Search Bapi Chatterjee Copyright c Bapi Chatterjee, 2017. ISBN: 978-91-7597-483-5 Series number: 4164 ISSN 0346-718X Technical report 136D Department of Computer Science and Engineering Distributed Computing and Systems Research Group Division of Networks and Systems Chalmers University of Technology SE-412 96 GÖTEBORG, Sweden Phone: +46 (0)31-772 10 00 Author e-mail: [email protected], [email protected] Printed by Chalmers Reproservice GÖTEBORG, Sweden 2017 Lock-free Concurrent Search Bapi Chatterjee Division of Networks and Systems, Chalmers University of Technology ABSTRACT The contemporary computers typically consist of multiple computing cores with high compute power. Such computers make excellent concurrent asyn- chronous shared memory system. On the other hand, though many celebrated books on data structure and algorithm provide a comprehensive study of se- quential search data structures, unfortunately, we do not have such a luxury if concurrency comes in the setting. The present dissertation aims to address this paucity. We describe novel lock-free algorithms for concurrent data structures that target a variety of search problems. (i) Point search (membership query, predecessor query, nearest neighbour query) for 1-dimensional data: Lock-free linked-list; lock-free internal and external binary search trees (BST). (ii) Range search for 1-dimensional data: A range search method for lock- free ordered set data structures - linked-list, skip-list and BST. (iii) Point search for multi-dimensional data: Lock-free kD-tree, specially, a generic method for nearest neighbour search. We prove that the presented algorithms are linearizable i.e. the concurrent data structure operations intuitively display their sequential behaviour to an ob- server of the concurrent system. The lock-freedom in the introduced algorithms guarantee overall progress in an asynchronous shared memory system. We present the amortized analysis of lock-free data structures to show their efficiency. Moreover, we provide sample implementations of the algorithms and test them over extensive micro-benchmarks. Our experiments demonstrate that the implementations are scalable and perform well when compared to related existing alternative implementations on common multi-core computers. Our focus is on propounding the generic methodologies for efficient lock- free concurrent search. In this direction, we present the notion of help-optimality, which captures the optimization of amortized step complexity of the operations. In addition to that, we explore the language-portable design of lock-free data structures that aims to simplify an implementation from programmer’s point of view. Finally, our techniques to implement lock-free linearizable range search and nearest neighbour search are independent of the underlying data structures and thus are adaptive to similar data structures. Keywords: Data Structure, Search, Range Search, Nearest Neighbour Search, Con- current, Concurrency, Lock-free, Lock-based, Blocking, Non-blocking, Wait-free, Lin- earizable, Linearizability, Binary Search Tree, Linked-list, kD-tree, Lock-free-kD-tree, Amortized Complexity, Help-aware, Help-optimal, Language-portable, Synchronization ii To my Mother & my late Father iii iv Dedication Acknowledgements First of all, I would like to express my gratitude to my supervisor Prof. Philippas Tsigas for his constant support and guidance. Without his generous help, this thesis would not have been possible. I also thank the graduate committee members - Prof. Thierry Coquand, As- sociate Prof. Marina Papatriantafilou, Prof. Jan Jonsson and former committee members Prof. Koen Claessen and Prof. Gerardo Schneider for their kind sup- port and helpful suggestions during the discussions in my Ph.D. study follow-up meetings. I am honored to have Prof. Pascal Felber as the opponent of my Ph.D. thesis defense. My sincere thanks to the members of the grading committee: Associate Prof. Paolo Romano, Associate Prof. Pedro Petersen Moura Trancoso, Prof. Stefanos Kaxiras, and Prof. Ulf Assarsson. I also take this opportunity to thank my previous supervisors Prof. Subodh Kumar (Dept of CS&E, IIT Delhi, India) and Prof. Aparna Mehra (Dept of Mathematics, IIT Delhi, India), whose guidance during my master’s studies helped me shape my thinking and motivated me enough to join the doctoral studies. I am extremely grateful to the Swedish Foundation for Strategic Research (SSF) who funded me as a full-time Ph.D. student for five years in the research project “Software Abstractions for Heterogeneous Computers (SCHEME)”. I thank the project co-leaders Prof. Per Stenström and Prof. Ulf Assarsson and other members in the project SCHEME with whom I truly enjoyed my collab- oration. Next, I would like to thank everybody in the Distributed Computing and Systems group, of which I am proud to be a member: Amir, Aras, Bashr, Char- alampos, Elad, Hannah, Ioannis, Iosif, Ivan, Olaf, Magnus, Thomas, and Vin- cenzo. I thank former members of the group, with whom I spent some of the most enjoyable moments during my Ph.D.: Andreas, Daniel, Farnaz, Giorgos, Oscar, Paul, and Valentin. My special thanks to my former office-mates, Nhan and Zhang, for the fun time and interesting discussions on topics confined to an v vi Acknowledgements uncountable number of domains. I also wish all the best to the youngsters in the group. It will remain incomplete without mentioning former members of the de- partment: Bhavishya, Chien-Chung, and Madhavan, with whom I shared not just many vegetarian meals but also some unforgettable moments in Göteborg. I also take this opportunity to thank the staff and the Ph.D. students at the Department of Computer Science and Engineering where I am privileged to be a member. It is thanking them for their efforts to make the department such a great place to work. I would like to especially thank Eva, Rebecca, Peter, Tiina, and Tomas for always being helpful and responsive. Bapi Chatterjee Göteborg Contents Abstract ::::::::::::::::::::::::::::::::: i Dedication :::::::::::::::::::::::::::::::: iii Acknowledgements ::::::::::::::::::::::::::: v Contents and Publications ::::::::::::::::::::::: xi Part I Introduction 1 1. Introduction ::::::::::::::::::::::::::::: 3 1.1 Search Algorithms........................3 1.1.1 Introduction to Search..................3 1.1.2 Search Data Structures..................5 1.2 Concurrent Data Structures....................8 1.2.1 Synchronization Algorithm................8 1.2.2 Concurrent Search Data Structures............ 15 1.3 Our Contributions......................... 19 2. System Model and Preliminaries :::::::::::::::::: 21 2.1 System Model........................... 21 2.2 Correctness and Complexity................... 24 2.2.1 Correctness........................ 24 2.2.2 Complexity........................ 26 Part II Lock-free 1-dimensional Point Search 29 3. Help-optimal and Language-portable Lock-free Concurrent Data Struc- tures ::::::::::::::::::::::::::::::::: 31 vii viii Contents 3.1 Introduction............................ 32 3.1.1 Overview......................... 32 3.1.2 Related Work....................... 35 3.2 Help-optimality: Motivation................... 36 3.3 Help-optimal Lock-free Linked-list................ 40 3.3.1 Design.......................... 40 3.3.2 Correctness and Lock-freedom.............. 44 3.3.3 Amortized Step Complexity............... 45 3.4 Help-optimal Lock-free BST................... 45 3.4.1 Design.......................... 47 3.4.2 Correctness and Lock-freedom.............. 52 3.5 Help-optimality: Specification.................. 53 3.6 Experimental Evaluation..................... 54 3.6.1 Experimental Set-up................... 54 3.6.2 Performance Results and Discussion........... 56 4. Amortized Complexity of Lock-Free Internal Binary Search Tree : 63 4.1 Introduction............................ 63 4.2 Preliminaries........................... 65 4.3 Our Algorithm.......................... 67 4.3.1 Design Fundamentals................... 67 4.3.2 The Lock-free Algorithm................. 68 4.4 Correctness and Complexity................... 83 4.4.1 Linearizability...................... 85 4.4.2 Lock-Freedom...................... 86 4.4.3 Complexity........................ 87 Part III Lock-free 1-dimensional Range Search 93 5. Lock-free Linearizable 1-Dimensional Range Queries ::::::: 95 5.1 Introduction............................ 95 5.1.1 Background........................ 95 5.1.2 Related work....................... 97 5.1.3 A summary of our work................. 97 5.2 The Lock-Free Range Search................... 100 5.2.1 Snap-collector implementation.............. 100 5.2.2 Lock-free linearizable range search algorithm...... 104 5.2.3 Range queries in a lock-free binary search tree..... 111 5.3 Correctness proof......................... 113 Contents ix 5.3.1 Proof........................... 113 5.4 Experimental Evaluation..................... 117 5.4.1 Experimental Setup.................... 117 5.4.2 Observations and Discussion............... 118 Part IV Lock-free Multidimensional Point Search 121 6. Concurrent Linearizable Nearest Neighbour Search in LockFree-kD- tree :::::::::::::::::::::::::::::::::: 123 6.1 Introduction............................ 123 6.1.1 Background.......................