Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lock-Free Linked Lists Using Compare-and-Swap

Similar presentations


Presentation on theme: "Lock-Free Linked Lists Using Compare-and-Swap"— Presentation transcript:

1 Lock-Free Linked Lists Using Compare-and-Swap
Talk Title: Lock-Free Linked Lists Using Compare-and-Swap by John Valois Speaker’s Name: My name is My presentation is on lfll In this paper, the author presents new data structures and algorithms for manipulating them. These new data structures and algorithms addressed important issues in parallel computing. My presentation has 2 parts; First, I will explain to you what is a lfll what are the properties of lfll and what is the motivation behind creating these new data structures and the related algorithms? In the second part, I will show you how they work. Lock-free data structures implement concurrent objects without using mutual exclusion. Now we will break it down. Larry Bush

2 Concurrent Object Shared Memory P1 P2 Pn
A shared abstract data type that allows operations by different processors to occur at the same time. Important to applications in parallel algorithms, user-level thread implementation and multiprocessor operating systems. P1 P2 Pn

3 Lock-Free No Mutual Exclusion Appear Atomic Lamport Massalin and Pu
Massalin and Pu – coined the term lock-free – wrote multi processor os kernel using lock free stata structures. So if anyone is looking for a project, they could do this too. Lock free is an alternative to mutual exclusion. Do not require exclusive access. Lock free data structures implement concurrent objects without the use of mutual exclusion. Makes actions appear atomic. Conflicting operations do not corrupt the data structure. Allows simultaneous traversal, insertion and deletion.

4 Lock-Free Linked Lists?
Linked list data structure that implements concurrent objects without the use of mutual exclusion. This is analogous to road construction. They must figure out how to insert and delete pieces of road while cars are still going down the road.

5 Compare&Swap Synchronization Primitive
bool Compare&Swap ( Type * x, Type old, Type new) { // BEGIN ATOMIC if *x != old { *x = new; return TRUE; } else { return FALSE } // END ATOMIC Compare&Swap is a synchronization primitive that is guaranteed to execute atomically. It works as follows. If you want to increment a variable from 6 to 7, You read the variable, and find out it is 6, Then you call Compare&Swap( ptr, 6, 7 ). Pass in pointer to shared variable, old value and new value. Compare&Swap will look at the old number you passed in and if the shared variable has not yet changed, it will update it to 7. Herlihy did research on universal synchronization primitives. Compare&Swap is universal primitive. A universal primitive is one that solves the consensus problem. Herlihy showed that a universal primitive is necessary and sufficient to implement lock free ADTs. An algorithm that provides lock free functionality for ANY generic ADT is also called universal. Universal meaning “for any.” Doing this requires a powerful synchronization primitive. Going backwards, and primitive powerful enough to solve this problem is subsequently called universal. It just so happens that this problem is analogous to the consensus problem and therefore, if it can solve the consensus problem, it can do lock free data structures.

6 Why is this important ? Avoids Mutual Exclusion Problems Convoying
Deadlock Priority Inversion Blocking So, whenever you have multi-processing, parallel processing or distributed computing you have synchronization problems. The objective of lock-free data structures is to avoid performance delays while objects are in the critical section. Lock-free data structures can guarantee a particular level of performance even if the concurrent objects halt (that’s why they are called wait-free). There are basically 2 types of mutual exclusion. And they both have their problems. Convoying – one slow process (delayed for whatever reason) affects the processes waiting for it. As in a FIFO scheduling mechanism (vs. shortest job first). Deadlock – 2 (or more) processes are waiting for a resource the other has (like buying a house). Priority Inversion – if the mutual exclusion uses busy waiting, and a lower priority process is in the critical region, and a higher priority process is waiting for it, then the scheduler gives the higher priority process the cpu and the lower priority process can never get out of the critical region. Lamport – Discovered that these problems can be avoided using lock-free methods. 27 years of considering the benefits of avoiding mutual exclusion – gave the first lock-free algorithm for the single writer/ multiple reader shared variable. This created much more research and improvements on the topic. Busy Waiting

7 Limitations of current implementations
Universal methods are not efficient (Herlihy). Massalin and Pu’s method required the uncommon double word Compare&Swap. There are currently universal (for any ADT) wait free methods but they have too much overhead to be efficient. Therefore, this paper shows a direct implementation that is more efficient. Valois’ uses a single word version of Compare&Swap which is commonly available on most systems.

8 Benefits of new implementation
As quick as spin locks Without blocking or busy waiting (wait free)

9 Part 2 Concurrent Linked List
Cursor More than one processor, each with a its own cursor, can be traversing and manipulating the linked list. Present algorithms and data structures that directly implement a non-blocking singly-linked list. Allows multiple processes to traverse, insert and delete. Using only commonly available Compare&Swap. Cursor

10 Traversal ( no problem )
Cursor Traversal What is it. Steps. If insert – there is always a path for the traversing process. If delete – there is always a path – the deleted node maintains a forward path – In a garbage collection system, that node will continue to exist until there are no more pointers to it. Cursor

11 Insert ( small problem )
Say we want to insert a new node q between p and s. Steps. q next points to s p next points to q BUT – if another process deletes node s in between, then q will be following a deleted node. THEREFORE - (swing pointer using Compare&Swap) To do this - Set p->next to point to q, in one atomic statement, only if p has not changed (compare) since p was last read. q

12 Insert ( small problem )
q

13 Insert ( small problem )
swing pointer q

14 Delete a b d Delete Simple delete looks like this.
a->next = a->next->next BUT – what happens if there is a concurrent insert? We are going to delete b while inserting c. Delete (with concurrent insert) Steps. 1 - C next = d (c insert) 2 - a next = d (b delete) (cursor also moves) 3 - b next = c (c insert) pointed at by a deleted node If insert – there is always a path for the traversing process. If delete – there is always a path – the deleted node maintains a forward path – In a garbage collection system, that node will continue to exist until there are no more pointers to it.

15 Delete a b d

16 Delete ( big problem ) a d b c Cursor Cursor

17 Delete ( big problem ) a d b c Cursor Cursor

18 Delete ( big problem ) Cursor a d b c Cursor

19 Delete ( big problem ) Cursor a d b c Cursor

20 Iterator ( at node b ) pre_aux a b c d pre_cell target
To solve this problem, we use auxiliary nodes. An auxiliary node is a node with only a next pointer, no data. We put an auxiliary node in between each cell in the list. Repeat last example - Delete (with concurrent insert using auxiliary nodes) We are going to delete b while inserting c. Steps. 1 - C next = d (c insert) 2 - a next = auxiliary node 3 - auxiliary node next = node c If insert – there is always a path for the traversing process. If delete – there is always a path – the deleted node maintains a forward path – In a garbage collection system, that node will continue to exist until there are no more pointers to it. pre_cell target

21 Auxiliary nodes a b c d To solve this problem, we use auxiliary nodes.
An auxiliary node is a node with only a next pointer, no data. We put an auxiliary node in between each cell in the list. Repeat last example - Delete (with concurrent insert using auxiliary nodes) We are going to delete b while inserting c. Steps. 1 - C next = d (c insert) 2 - a next = auxiliary node 3 - auxiliary node next = node c If insert – there is always a path for the traversing process. If delete – there is always a path – the deleted node maintains a forward path – In a garbage collection system, that node will continue to exist until there are no more pointers to it.

22 Step One a b d c

23 Step Two a b d c

24 Step Three a b d c

25 Step Four a b d c

26 Conclusion Allows concurrent operations Good for: parallel processing
distributed memory Should be used everywhere These are the best thing since sliced bread. These should be implemented on every parallel and multi-processing system, every OS, every network and distributed memory systems.

27 Questions/Facts

28 Why do you say this is lock-free if it uses a mutual exclusion primitive?
Limited to atomic actions provided by the hardware. Only when swinging pointers. Allows simultaneous traversal, insertion and deletion. Lamport (made the distinction) Massalin and Pu (coined the term) The use of synchronization primitives implies that we still use mutual exclusion, although it is restricted to atomic actions provided by the hardware. Lock-Free makes limited use of mutual exclusion to provide atomicity at the hw level to swing pointers.

29 Universal Universal Algorithm (a.k.a. Universal Method)
An algorithm that provides lock-free functionality for ANY generic ADT is called universal. Universal meaning “for any.” This requires a powerful synchronization primitive. This is an application that defines a primitives strength. Universal Primitive A universal primitive can be used to provide lock-free functionality for any generic Data Type. A universal primitive can also solve the consensus problem. Analogous Problems Generic Lock-Free ADT is analogous to the consensus problem. If a primitive is powerful enough to solve one it can also solve the other. An algorithm that provides lock free functionality for ANY generic ADT is also called universal. Universal meaning “for any.” Doing this requires a powerful synchronization primitive. Going backwards, and primitive powerful enough to solve this problem is subsequently called universal. It just so happens that this problem is analogous to the consensus problem and therefore, if it can solve the consensus problem, it can do lock free data structures.

30 Wait-Free An implementation is wait-free if every process finishes in a bounded number of steps, regardless of interleaving.

31 Aux Nodes Insertion of new cells takes place between an auxiliary node and an existing regular cell. Chains of auxilary nodes are allowed. An auxilary node is not required to have a real cell node before and after it.

32 Swinging the Pointer ptr = find ptr of interest repeat
old = Read( ptr ); new = compute new pointer value r = Compare&Swap(ptr, old, new) until ( r = TRUE )} For an insert, ptr could be the pointer to the preceeding cell. Compare&Swap fails if the ptr object was altered in between.

33 ABA problem p s swing pointer q
If s is deleted, put in a node recycling queue, and reinserted in the same spot, then Compare&Swap will not detect this. swing pointer q

34 ABA Solutions Double Compare&Swap No Cell Reuse Memory Management
Double C&S – test a pointer incrementer too, every time a pointer accesses the cell, it is incremented – but double c&s isn’t available on most machines. No Cell Reuse – No aba is possible MM – safe read and release – uses refct like a semafore to determinge how many cursors are pointing to the cell.

35 Insert ( p, x ) q = new cell Repeat
r = SafeRead ( p -> next ) Write ( q -> next, r ) until Compare&Swap( p -> next, r, q ) For an insert, ptr could be the pointer to the preceeding cell. Compare&Swap fails if the ptr object was altered in between.

36 struct Cursor { }; node * target; // -> data
node * pre_aux; // -> preceding auxiliary node node * pre_cell; // -> previous cell For an insert, ptr could be the pointer to the preceeding cell. Compare&Swap fails if the ptr object was altered in between.

37 Update(cursor c) { }; // Updates pointers in the cursor so that it becomes valid. // removes double aux_node. For an insert, ptr could be the pointer to the preceeding cell. Compare&Swap fails if the ptr object was altered in between.

38 Try_delete(cursor c) { };
c.pre_cell = next // deletes cell back_link = c->pre_cell delete pre_aux Concurrent deletions may stall process and create chains of aux nodes. The last deletion follows the back_links of the deleted cells. After all deletions the list will have no extra aux_nodes For an insert, ptr could be the pointer to the preceeding cell. Compare&Swap fails if the ptr object was altered in between.

39 Test&Set Fetch&Add Can be implemented using Compare&Swap Test&Set
Sets new value to TRUE. Fetch&Add Adds an arbitrary value to shared variable. For an insert, ptr could be the pointer to the preceeding cell. Compare&Swap fails if the ptr object was altered in between.

40 Valois Created algorithms and data structures that directly implement a non-blocking singly-linked list. Allows multiple processes to traverse, insert and delete. Using only commonly available Compare&Swap. Single word version Commonly available on most systems

41 Contributions Lock-Free Structures & Memory Management Techniques for linked list, dictionary and tree.

42 Related Work Lamport Herlihy Massalin and Pu
Herlihy showed that a universal primitive is necessary and sufficient. Lock-Free makes limited use of mutual exclusion to provide atomicity at the hw level to swing pointers. Massalin and Pu – coined the term lock-free – wrote multi processor os kernel using lock free stata structures. Lamport – 27 years of considering the benefits of avoiding mutual exclusion – gave the first lock-free algorithm for the single writer/ multiple reader shared variable. This created much more research and improvements on the topic.

43 Lamport Discovered that mutual exclusion problems can be avoided using lock-free methods. Gave the first lock-free algorithm for the single writer/ multiple reader shared variable. Led to more research on the topic. 27 years


Download ppt "Lock-Free Linked Lists Using Compare-and-Swap"

Similar presentations


Ads by Google