Tyler Crain
email: tyler.crain@irisa.fr

Vincent Gramoli
email: vincent.gramoli@sydney.edu.au

Michel Raynal
email: raynal@irisa.fr

A Contention-Friendly, Non-Blocking Skip List

Keywords: Lock-based, Lock-free, Eager abstract modification, Lazy structural adaptation mémoire transactionnelle, structures de données concurrente -∞

This paper presents a new non-blocking skip list algorithm. The algorithm alleviates contention by localizing synchronization at the least contended part of the structure without altering consistency of the implemented abstraction.

The key idea lies in decoupling a modification to the structure into two stages: an eager abstract modification that returns quickly and whose update affects only the bottom of the structure, and a lazy selective adaptation updating potentially the entire structure but executed continuously in the background. As non-blocking skip lists are becoming appealing alternatives to latch-based trees in modern main-memory databases, we integrated it into a main-memory database benchmark, SPECjbb. On SPECjbb as well as on micro-benchmarks, we compared the performance of our new non-blocking skip list against the performance of the JDK non-blocking skip list. Results indicate that our implementation is up to 2.5× faster than the JDK skip list.

Introduction

Skip lists are increasingly popular alternatives to B-trees in main-memory databases like memsql1 as they are traversed in sorted order and may not rely on latches. In short, a skip list is a linked structure that diminishes the linear big-oh complexity of a linked list by having index-items on top of nodes that together form towers with additional shortcuts pointing towards other towers located further in the list [START_REF] Pugh | Skip lists: a probabilistic alternative to balanced trees[END_REF]. These shortcuts allow operations to complete in O(log n) steps in expectation by letting traversals skip lower nodes through higher levels shortcuts. The drawback of employing shortcuts is however to require additional maintenance at multiple levels each time some data is stored or discarded. This increases the probability of multiple threads (or processes) interfering on the same shared data.

Maintaining the skip list in the case of concurrent traversals creates contention hot spots typically located at the top of the skip list towers. More specifically, the higher a tower is, the more likely it will be accessed and the more contention its update will incur. These hot spots become important bottlenecks on modern machines with a large amount of cores, which typically translates into significant performance losses.

In the light of the impact of contention on performance, we propose a new Contention-Friendly (CF) nonblocking skip list algorithm experiencing contention only at the bottom level that consists of the node list, thus avoiding the contention hot spots other concurrent skip lists suffer from. Even though this new concurrent skip list alleviates the contention of modern multi-cores, it does not relax the correctness of the abstraction it implements. To accomplish this our skip list benefits from a genuine decoupling of each update access into an eager abstract modification and a selective lazy structural adaptation.

• Concurrent eager abstract modifications consist in modifying the abstraction while minimizing the impact on the structure itself and returning as soon as possible for the sake of responsiveness.

• The lazy selective adaptation, which executes in the background, adapts the skip list structure based on abstract changes by re-arranging elements or garbage collecting and physically removing logically deleted ones.

When applying this decoupling to the map or set abstraction, it translates into: (i) splitting an element insertion into (1) the insertion phase at the bottom level of the skip list and (2) the structural adaptation responsible for updating pointers at its higher levels, and (ii) splitting an element removal into (1) a logical deletion marking phase and (2) its physical removal and garbage collection. Hence, the decoupling allows multiple threads to update the bottom-most level (i.e. the node list) of the skip list while a single thread keeps adapting higher levels in the background. Two consequences of our decoupling are low latency and low contention. First, it shortens operations in order for them to return just after the abstract access, hence diminishing their latency. Second, it postpones the structural adaptation to selected parts of the structure in order to avoid temporary load bursts and hot spots, hence diminishing contention.

The decoupling also impacts the implementation design in three main ways. First, decoupling the structural adaptations from responsive abstract operations lets us adapt deterministically the heights of the towers to obtain a more balanced structure. By contrast, traditional skip-list adaptations are tightly coupled to abstract modifications and rely on pseudo-random functions to achieve reasonable efficiency. Second, in the case where a large amount of short towers have been removed (leaving too many tall towers), we decrease the heights of all towers by removing the bottom-most index-item list of the structure rather than modifying the frequently accessed higher levels. Third, this decoupling allows us to centralize all adaptation tasks on a single thread, meaning that only accesses to the node list level need to be synchronized, hence further reducing latency.

Additionally, our CF skip list is non-blocking, ensuring that the system as a whole always makes progress. In particular, no threads ever block waiting for some resources. This property guarantees that one slow thread does not affect the overall system performance, representing an appealing feature for modern heterogeneous machines that tend to embed processors or cores of distinct clock frequencies. Finally, the non-blocking property makes our skip list fault tolerant as if one thread crashes, it neither makes the skip list inconsistent nor does it prevent other threads from accessing resources. In particular, if the adaptation thread slows down or crashes then system performance may be affected but safety and progress are preserved.

Evaluation on a micro-benchmark and on the SPECjbb main-memory database benchmark [START_REF]Standard performance evaluation corporation[END_REF] is given. More precisely, we compare our algorithm's performance against the Java adaptation by Doug Lea of Harris, Michael and Fraser's algorithms [START_REF] Fraser | Practical lock freedom[END_REF][START_REF] Harris | A pragmatic implementation of non-blocking linked-lists[END_REF][START_REF] Michael | High performance dynamic lock-free hash tables and list-based sets[END_REF]. This implementation is probably one of the most widely used non-blocking skip lists today and is distributed within the Java Development Kit (JDK). The results observed on a 24-core AMD machine shows a speedup factor of up to 2.5.

Section 2 describes the related work. Section 3 depicts how to make a skip list contention-friendly. Section 4 describes in detail our CF non-blocking skip list algorithm. Section 5 proves that the algorithm satisfies linearizability, while section 6 proves the non-blocking progress of the algorithm. Section 7 presents the experimental results. Section 8 presents extensions applicable to our algorithm and Section 9 concludes.

Related Work

Decoupling tree updates into multiple tasks has proved beneficial for memory management [START_REF] Dijkstra | On-the-fly garbage collection: an exercise in cooperation[END_REF] and efficiency [START_REF] Crain | A speculation-friendly binary search tree[END_REF][START_REF] Nurmi | Concurrency control in database structures with relaxed balance[END_REF]. In particular, the work in this paper is motivated by our previous decoupling of memory transactions updating a binary search tree [START_REF] Crain | A speculation-friendly binary search tree[END_REF]. As far as we know, this idea has never been applied to skip lists before.

The deletion of an element in various data structures has been decoupled to avoid blocking. Tim Harris proposed to mark elements for deletion using a single bit prior to physically removing them [START_REF] Harris | A pragmatic implementation of non-blocking linked-lists[END_REF]. This bit corresponds typically to the low-order bit of the element reference that would be unused on most modern architectures. The decoupling into a logical deletion and a physical removal allowed Harris to propose a non-blocking linked list using exclusively compare-and-swap (CAS) for synchronization. The same technique was used by Maged Michael to derive a non-blocking linked list and a non-blocking hash table with advanced memory management [START_REF] Michael | High performance dynamic lock-free hash tables and list-based sets[END_REF] and by Keir Fraser to develop a non-blocking skip list [START_REF] Fraser | Practical lock freedom[END_REF]. Doug Lea exploited these techniques to propose a non-blocking skip list implementation in the JDK [START_REF] Lea | Jsr-166 specification request group[END_REF]. For the sake of portability, an element is logically deleted by nullifying a value reference instead of incrementing a low-order bit. The resulting algorithm is quite complex and implements a map, or dictionary, abstraction. A tower of height comprises -1 index-items, one above the other with each being part of an index-item list level, under which at the bottom level a node is used as part of the node list to store the appropriate key, value pair of the corresponding element. Our implementation uses the same null marker for logical deletion, and we employ the same terminology to describe our algorithm.

Sundell and Tsigas built upon the seminal idea by Valois [START_REF] Valois | Lock-free data structures[END_REF] of constructing non-blocking dictionaries using linked structures [START_REF] Sundell | Scalable and lock-free concurrent dictionaries[END_REF]. They propose to complement Valois' thesis by specifying a practical non-blocking skip list that implements a dictionary abstraction. The algorithm exploits the logical deletion technique proposed by Harris and uses three standard synchronization primitives that are test-and-set, fetch-and-add and CAS. The performance of their implementation is shown empirically to scale well with the number of threads on an SGI MIPS machine. The logical deletion process that is used here requires that further operations help by marking the various levels of a tower upon discovering that the bottommost node is marked for deletion. Further helping operations may be necessary to physically remove the tower.

Fomitchev and Ruppert [START_REF] Fomitchev | Lock-free linked lists and skip lists[END_REF] proposed a non-blocking skip list algorithm whose lookups physically remove nodes they encounter to avoid traversing superfluous towers. This approach differs from the former one where a superfluous tower is traversed by the lookup, while marking all its nodes as deleted. Fomitchev and Ruppert also use the logical deletion mechanism for tower removal by first having its bottommost node marked for removal, then its topmost one. Other operations help removing a tower in an original way by always removing a logically deleted tower to avoid further operations to unnecessarily backtrack. We are unaware of any existing implementation of this algorithm.

In contrast with these three skip lists algorithms, our approach is to decouple the abstract modification from the selective structural adaptation, avoiding contention hot spots by having synchronisation occurring only at the bottom level of the structure.

Finally, transactional memories can be used to implement non-blocking skip list, however, they may restrict skip list concurrency [START_REF] Fraser | Practical lock freedom[END_REF] or block [START_REF] Felber | Elastic transactions[END_REF].

Towards Contention-Friendliness

In this section, we give an overview of the technique to make the skip list contention-friendly. Our CF skip list aims at implementing a correct map, or dictionary, abstraction as it represents a common key-value store example. The correctness criterion ensured here is linearizability [START_REF] Herlihy | Linearizability: a correctness condition for concurrent objects[END_REF]. For the sake of simplicity our map supports only three operations: (i) insert adds a given key-value pair to the map and returns true if the key is not already present; otherwise it returns false; (ii) delete removes a given key and its associated value from the map and returns true if the key was present, otherwise it returns false; (iii) contains checks whether a given key is present and returns true if so, false otherwise. Note that these operations correspond to the putIfAbsent, remove, and containsKey method of the java.util.concurrent.ConcurrentSkipListMap.

Eager abstract modification

Previous skip lists generally maintain a tower per height distribution so that the probability of a tower i to have height is Pr[height i = ] = 2 -O( ) , hence as part of each updating abstract operation the invariant is checked and the structure is accordingly updated. Even though an update to the abstraction may only need to modify a single location to become visible, its associated structural adaptation is a global modification that could potentially conflict with any concurrent update.

In order to avoid these additional conflicts, when a node is inserted in the CF skip list only the node list level is modified and the additional structural modification is postponed until later. This decoupling prevents an insertion from updating up to O(log n) levels, thus reducing contention and making the update cost of each operation more predictable.

As an example, consider the insertion of an element with key 12. Our insertion consists in updating only the node list level of the structure by adding a new node of height 1, leading to Figure 1(a) where dashed arrows indicate the freshly modified pointers. The key 12 now exists in the set and is visible to future operations, but the process of raising this same tower by linking at index-item levels is deferred until later.

It is noteworthy that executing multiple abstract modifications without adapting the structure does no longer guarantee the logarithmic step complexity of the accesses. Yet this happens only under contention, precisely when this big-oh complexity may not be the predominant factor of performance.

Lazy selective structural adaptation

In order to guarantee the logarithmic complexity of accesses when there is no contention the structure needs to be adapted by setting the next pointers at upper (index-item) levels as soon as possible while avoiding an increase in contention. Figure 1(b) depicts the lazy structural adaptation corresponding to the insertion of tower 12: the insertion at a higher (index-item) level of the skip list is executed as a structural adaptation (separated from the insertion), which produces eventually a good distribution of tower heights.

Laziness to avoid contention bursts The structural adaptation is lazy because it is decoupled from the abstract modifications and is executed by an independent thread. (A multi-threaded structural adaptation is discussed in Section 8.2.) Hence many concurrent abstract modifications may have accessed the skip list while no adaptations have completed yet. We say that the decoupling is postponed from the system point of view.

This postponement has several advantages whose prominent one is to enable merging of multiple adaptations in one simplified step: only one traversal is sufficient to adapt the structure after a burst of abstract modifications. Another interesting aspect is that it gives a chance for insertions to execute faster: Not only does an insert return without modifying the index-item levels, if the element to be inserted is already in the list, but is marked as logically deleted, then the insertion simply needs to logically insert the element by unmarking it. This avoids the insertion from having to allocate a new node and modify the structure. Selectivity to avoid contention hot-spots The abstract modification of a delete simply consists of marking the node as logically deleted without modifying the actual structure. Importantly, the subsequent structural adaptation selects for physical removal the nodes whose physical removal would induce the least contention. More precisely, only the nodes without towers (i.e. nodes that are not linked to index-item lists) are removed by this operation.

For example, the removal of a tall tower, say the one with value 36 in Figure 1(b), would typically induce more contention than the removal of a node with a shorter tower, say the one with value 62 spanning just the node list level. The reason is twofold. First removing a tower spanning levels boils down to updating O( ) pointers, hence removing the element with value 36 requires updating at least 3 pointers while the element with value 62 requires updating 1 pointer. Second, the organization of the skip list implies that the higher level pointers are traversed more frequently, hence the removal of tower 36 typically conflicts with every operation concurrently traversing this structure whereas the next pointer of element 62 is unlikely to be accessed by as many concurrent traversals.

The Non-Blocking Skip List

In this section, we present our CF non-blocking skip list. Algorithm 1 depicts the algorithm of the eager abstract operations while Algorithm 2 depicts the algorithm of the lazy selective adaptation. CAS operations are used for synchronization. The bottom level (the node list) of the skip list is made up of a doubly linked list of nodes as opposed to the Java ConcurrentSkipListMap, which uses a singly linked list. Each node has a prev and next pointer, a key k, a value v, an integer level indicating the number of levels of lists this node is linked into, a marker flag indicating whether the node is a marker node (used during physical removals in order to prevent lost insert scenarios).

As depicted in Figure 2, the upper levels are made up of singly linked lists of items called index-items. Each of these items has a next pointer that points to the next item in the linked list, a down pointer that points to the linked list of index-items one level below (the bottom level of index-items have ⊥ for their down pointers), and a node pointer that points to the corresponding node in the doubly linked list. The list is initialized with a single dummy node with a tower of the maximum starting height. The pointer top always points to the first element of the highest index-item list, all traversals start from this pointer.

We use the logical deletion technique [START_REF] Harris | A pragmatic implementation of non-blocking linked-lists[END_REF] by nullifying the v field used to hold the value of the node. If v = ⊥, then we say that the node is logically deleted. After logical deletion, in order to indicate that a node has been (or is in the process of being) physically removed from the list, the v field is set to point to the node itself (for example a node n has been or is being physically removed if n.v = n). This technique is used to ensure the safety of the non-blocking protocol, the details of which are discussed in Section 4.2. In Figure 2 the third node is in the process of being removed and the fourth node is a marker.

Abstract operations

Algorithm 1 depicts operations contains, insert and delete. These operations traverse the skip list by executing the same procedure do_operation until line 84 where they execute a specific procedure finish(contains, * ), finish(delete, * ) or finish(insert, * ). Due to concurrent modifications to the skip-list, these procedures might not be able to complete their abstract operation at the current node. In this case ⊥ is returned to do_operation and the traversal continues (line 87), otherwise true or false is returned and the operation is completed.

The traversal

The skip list traversal classically executes from left to right and from top to bottom. More precisely, the do_operation procedure starts by executing the while loop (lines 63-73) which traverses the towers starting from the highest level pointed to by the top pointer. Each index-item list is traversed by following the right pointers of index-items moving towards increasingly larger keys. A traversal of a level stops either if it reaches the end of the list at the current level or if it reaches a tower linking to a node with a key larger than k (line 65). At this point the traversal continues on the index-item list level below by following the down pointer of the current index-item (line 66). If there are no index-item lists below then the while loop is exited (line 69) and the traversal continues on the list of nodes. The index-item list traversal stops immediately if a node with key k is found (lines 70-72).

The traversal then continues on the doubly linked list of nodes (cf. the while loop on lines 74-88) by following the current node's next pointer. However, the traversal may reach a node that has been concurrently physically removed (node.v = node), in which case it backtracks by following the node's prev pointer until it reaches a node guaranteed to be in the list (node.v = node) this ensures the traversal does not miss newly inserted nodes. In order to ensure non-blocking progress the traversal may also help with the physical removal of the next node if it detects that next.v = next (line 80).

The finish

Once the traversal has found the end of the list or a node with key larger than k then the appropriate finish is executed for the current operation type. The finish(contains, * ) simply checks whether node has key k (line 33). A node with value ⊥ indicates a logically deleted node in which case it is known that k is not in the set. finish(contains, * ) returns true if key k is found at a non-deleted node.

The finish(delete, * ) looks for a non-logically deleted node (n.v = ⊥) (line 42) with key k (line 39). If such a node is not found false is returned, otherwise the node is marked as deleted using CAS (line 43). If the CAS fails, the traversal continues as this indicates a concurrent modification. If the CAS succeeds, remove is called to physically remove the node (line 44). This operation will only physically remove nodes of height 1 (i.e. nodes not linked to any index-items lists), other physical removals are dealt with by the adapting thread, the details of this operation is described in section 4.2.

The finish(insert, * ) operation starts by checking if a node with key k is already in the list (line 50). An interesting implication of separating the structural adaptation is the ability to have lighter insertions. An insert is executed "logically" if it encounters a node with key k that is marked as logically deleted (lines 51) by unmarking it using a CAS (line 52), returning true on success. Otherwise if the node has not been marked as deleted then false is returned (line 54). If no node with key k is found then a new node is allocated (line 56), has its pointers and values set (lines 21-23) and is added to the list using a CAS. If the CAS succeeds the prev pointer of the next node is set to point to the new node (note that synchronization is not needed here as prev is only used by traversals for backtracking to the list). If either of the CAS operations fails then a concurrent operation has modified the list and ⊥ is returned (line 60) allowing the traversal to continue.

Structural adaptation

The structural adaptation is executed continuously by a dedicated thread, called the adapting thread, that repeatedly cleans up the structure by physically removing deleted nodes and adapts the structure by raising or lowering towers appropriately. Even though a failure of the adapting thread does not impact the correctness of our algorithm, a distributed adaptation is discussed in Section 8.2.

Physical removal

The first task of the adapting thread lies in physically removing marked deleted nodes of height 1 who were not removed during the delete operation. This task is executed continuously by the adapting thread while traversing the list. The remove operation is more difficult than the abstract logical delete operation as it requires three CAS operations. To illustrate why three CAS operations are necessary, assume that node n with predecessor node prev and successor node next, is to be removed. If a CAS is performed on prev.next in order to remove n by changing the pointer's value from n to next then a concurrent insert operation could have added a new node in between n and next, leading to a lost update problem [START_REF] Valois | Lock-free data structures[END_REF]. In order to avoid such cases, physical removals are broken into two steps.

In the first step the v field of the node to be removed is CASed from ⊥ to point to the node itself (line 92). This indicates to other threads that the node is going to be removed. Following this, the removal is completed in a separate help-remove procedure (which might also be called by a concurrent operation performing a traversal).

We encompass lost insert scenarios by using a special marked node, which is inserted into the list directly after the node to be removed using a CAS during the help-remove procedure (lines 102-103). Additionally, during the insert operation, before adding a new node to the list a validation is performed ensuring that neither the predecessor nor the successor node is marked (resulting in the fact that new nodes are never inserted before or after markers), therefore preventing lost inserts (lines 75 and 79 of the do_operation procedure). In order to distinguish a marked node from other nodes it has its marked flag set to true and its v field pointing to itself. To complete the removal a CAS is performed on the predecessor's next pointer (line 107) removing both the node and its marker node from the list. This is similar to the process done in Lea's ConcurrentSkipListMap.

Raising towers

In the second task of the adapting thread the upper levels of the skip list (i.e. the index-item lists) are modified in order to ensure the O(log n) expected traversal time. Interestingly, calculating the height of a node cannot be done similarly to traditional skip lists due to the fact that only nodes with a height of 1 are removed. Traditional skip list algorithms favor probabilistic balancing using a random function to calculate the heights of towers as it was more efficient in sequential executions, while here heights are computed deterministically. This deterministic rebalancing is done using the procedure raise-index which is repeatedly called by the adapting thread. This procedure starts by setting up an array called first so that it contains the first element of every list level. Following this, the raise-nlevel (line 123) procedure is called to raise towers from nodes of height 1 into the index-item list above, followed by raise-ilevel which is called at each index-item list level from the bottom level upwards selecting towers to raise higher one level (lines 124-125).

Each iteration of these procedures traverses the entire list level, during which each time it observes 3 consecutive nodes/towers whose height is equal to that of the level being traversed (lines 142-144) it increments the height of the middle node/tower by 1 (line 150) (Note that raise-nlevel is not included in the pseudo code because it follows the same structure as raise-ilevel with the only difference being that the nodes level is traversed instead of index-item levels). Such a technique approximates the targeted number of nodes present at each level, balancing the structure. Given that physical removals can happen concurrently with the raising of a nodes level, a node that was physically removed might exist as a tower in an index level. When the raise-index-level notices such a situation it simply removes the corresponding index-item (lines 136-141). Following the traversals, if there is at least one node in the highest index level then a new index level is needed (i.e. the last call of raise-index-level returned true), this is done by the adapting thread by simply adding a new index node to the top of the dummy node's tower and modifying the top pointer (lines 126-128).

Lowering towers

The final task of the adapting thread is due to the fact that only nodes of height 1 (i.e. short towers) are physically removed and is necessary in the case that "too many" tall towers are marked as deleted while most of the short towers between them have been physically removed. If the number of logically deleted towers of height greater than 1 passes some threshold (based on the number of logically deleted nodes and the total number of nodes) then the lower-index-level procedure is called. This procedure simply removes the entire bottom index-item list level of the skip list by changing the down pointers of each index-item of the level above to ⊥ (line 114). Doing this avoids modification to the taller (i.e. contended) towers in the list and helps ensure there are not too many marked deleted nodes left in the list. Importantly because of this there is no frequent re-balancing of the towers going on, tall towers will remain tall, resulting in less contention at the frequently traversed locations of the structure.

Proof of Correctness

Here we show that skip list is non-blocking and implements a map that is linearizable [START_REF] Herlihy | Linearizability: a correctness condition for concurrent objects[END_REF].

Definitions The skip list presented here represents the set (or map) abstract data type. A key k is in the set if there is a path from the field top to a node with key equal to k with a non-⊥ value, otherwise it is not in the set. Therefore a valid skip list has the following properties: (i) the nodes in the skip list are sorted by their keys in ascending order, (ii) there is a path from the field top to at most one node with a key k at any point in time and (iii) every node with value v = node has a path to it from top. We consider that an operation contains, insert, and delete is a success if it returns true, otherwise it fails.

For the sake of simplicity the structure is initialized with a single node with key -∞ and a tower of maximum height. Each of the IndexItems of the tower have their right pointer initialized to ⊥ and the node's next pointer is also initialized to ⊥.

Lemma 1

The key k of a node never changes.

Proof. The key of a node is set once during creation in the setup_node procedure and is never modified afterwards.

2

Lemma 2 In a valid list, any node n in the list remains in the list at least until v = n is true.

Proof. A node that is in the list can only be removed from the list by changing the value of the next pointer of the node that points to it. There are three places where a node's next pointer is modified. First on line 57 of the insert operation. This is done by a CAS operation changing node's next pointer from next to a new node, but this new node's next pointer is set to next on line 23 so next must still be in the list after the CAS. The second place a next pointer is changed is on line 103 of the help_remove procedure. This is done by a CAS operation changing node's next pointer from n to a marker node, but this marker node's next pointer is set to n on line 23 so n must still be in the list after the CAS. The third place is on line 107 of the help_remove procedure. The purpose of this CAS is to remove node and its subsequent marker from the list. First notice that on line 96 node.v = node must be true and this must remain be true at the time of the CAS because once a nodes value v is set to point to itself it is never changed (this is ensured by all changes to a nodes value v being done by CAS operations). Also line 99 ensures that n is a marker node which must have n.v = n because all markers have their value v set to themselves (line 101) before the are inserted in the list. Following this, in order for the lemma to hold true we must show that node and n are the only nodes removed by the CAS. The semantics of the CAS operation ensures that there are no nodes between pred and node. Now to complete the proof it is enough to show that node.next always points to a marker node (in this case n) and a marker node's next pointer (in this case n) never changes from when it was first set on line 23. A node's next pointer can be changed at three places in the code. First line 57 of the insert operation the next pointer of node is changed from value next, but due to the checks on lines 75 and 79 neither node nor next is a marker. Second on line 103 of the help_remove procedure node's next pointer is changed from value n, but due to the checks on lines 96 and 99 neither node nor n is a marker. Finally on line 107 of the help_remove procedure pred's next pointer is changed from node, but due to the checks on line 96 and 105 neither pred nor node is a marker. 2

Lemma 3 For a valid list, the following is true for the values of the parameters that are input to the finish operation: node.key ≤ k, val = node, next.key > k, next_val = next.

Proof. The condition of val = node is ensured by the check on line 75, while next_val = next is ensured by the check on 79. These conditions also ensure that neither node nor next is a marker node (as markers have values v that point to themselves) meaning that both nodes are nodes that were previously added to the list by the insert operation, and since the list is valid these nodes will be sorted by their keys in ascending order. Lemma 1 also ensures that these keys will never change. Following this, the check on line 82 ensures that next.key > k. In order to show that node.key ≤ k we must look at the four places where pointer node is set in do_operation. First on line 71, but here line 70 ensures that node.key = k. Second on line 68, but the check on line 65 ensures that the key of item is not larger then k. Third on line 88, but here the check on line 82 ensures that the key of next is not bigger then k. The fourth place is on line 76 where node is set by using the prev pointer. To complete the proof of this condition we will now show that the prev pointers traversed always point to nodes with smaller keys. Let us first consider the prev pointers of non-marker nodes. These pointers are set in two places. First when a new node is created on line 22 of the setup_node procedure before it is added to the list, but the use of a CAS and the conditions of this lemma (node.key ≤ k, val = node) ensure that prev points to node which is a non-marker node with a key that is smaller then k. prev is also set on line 58 of the finish_insert operation where next.prev is set to point to node new. In this case, before finish_insert is called, line 82 ensures that the key of next is larger then k (which is used as the key for new), ensuring that the prev pointer of a node always points to a non-marker node with a smaller key. Now let us consider the prev pointers of marker nodes. Thanks to the check on line 79 of do_operation, when traversing forward in the list, node will never be set to a marker node, also we just previously showed that the prev pointers of non-marker nodes will never point to marker nodes. Due to this the prev pointers of marker nodes are never traversed. 2

Lemma 4 A call to the remove operation on a node of a valid skip list results in a valid skip list. A successful operation results with the node physically removed from the list (i.e. no path from top to the node exists). In either case he state of the elements in the abstraction is left unchanged.

Proof. The operation starts by performing a CAS on the v field of the node, changing it from ⊥ to point to the node. Atomically changing the value from ⊥ ensures that the key of this node was not in the set when the removal starts. If this CAS succeeds then the help-remove procedure is called. This procedure starts by ensuring a marker node is the following node in the list. If not (i.e. the check on line 99 fails) then such marker node is allocated and added to the list using a CAS (lines 102-103). The CAS ensures that the pointer has not changed since it was first read on line 98 or 104 so that no newly inserted nodes are lost. Adding the marker node does not effect the validity of the list as lemma 3 shows that marker nodes are never used as input to the finish operation. The last modification done by the removal operation is the CAS on line 107 which unlinks node and its successor (the marker node) from the list. To complete the proof we need to show that the only two nodes removed from the list are node and the marker following it, but we have already shown this in the proof of lemma 2. 2

Lemma 5 The successful contains and failed insert operations on a valid list are linearizable.

Proof. First note that neither of these operations make modifications to the list so they result in a valid list. For these operations we must have a node node with node.k = k, node.v = ⊥, and node.v = node at the point of linearization. The linearization point is when the node's value is read on line 75. The check on this same line ensures that the value read is not node. Next line 33 (resp. line 50) of the contains (resp. insert) along with lemma 1 ensure that node.k = k. Then the check on line 34 (resp. line 51) of the contains (resp. insert) operation ensure that the value read is not ⊥. Finally lemma 2 ensures that node is in the list and since the list is valid it is the only node with key k in the list. 2

Lemma 6 The failed contains and failed delete operations on a valid list are linearizable.

Proof. First note that neither of these operations make modifications to the list so they result in a valid list. For these operations we have two cases possible cases for the point of linearization. Note that lemma 3 ensures that these are the only two possible cases.

Case 1 We must have a node node with node.k = k and node.v = ⊥ at the point of linearization. The linearization point is when the node's value is read on line 75. The check on this same line ensures that the value read is not node. Next line 33 (resp. line 39) of the contains (resp. delete) along with lemma 1 ensure that node.k = k. Then the check on line 34 (resp. line 42) of the contains (resp. delete) operation ensure that the value read is ⊥. Finally lemma 2 ensures that node is in the list and since the list is valid it is the only node with key k in the list.

Case 2 We must have no node node in the list with node.k = k and node.v = ⊥ at the point of linearization. The linearization point is line 77 where node's next pointer is read. By lemma 2 we know that node is in the list at the time its value was read (line 75). Later, on line 78 the next node's value is read which must not have value equal to next (line 79) meaning that it is not a marker nodes (marker node's always have values that are pointers to themselves). From the description of the help-remove procedure we know that before a node is removed it must have its next pointer set to point to a marker node following which the next pointer is never changed (this is due to to all operations using CAS to change next pointers), therefore at line 77 node must still be in the list. Also by lemma 2 we know that next is in the list when its value was read (line 78), but since a node can only be removed once (only newly allocated nodes are inserted), then next must also be in the list at the linearization point (line 77). Finally (using lemmas 1 and 3) we know that from line 82 next.k > k and from line line 33 (resp. line 50) of the contains (resp. insert) node.k < k. Given the fact that the list is valid we know that there is no node with key k in the list at the linearization point. 2

Lemma 7

The successful insert operations on a valid list are linearizable.

Proof. For this operation we have two possible cases (limited to these cases by 3). The postcondition of node.k = k by lemma 1. Lemma 3 along with the CAS ensures that the precondition of node.v = ⊥ is true and adding lemma 2 we know that node is in the list immediately before and after the CAS. Finally the CAS ensures the postcondition of node.v = v is true and that the list is still valid.

Case 2 Here the precondition is that there is no node in the list with key k. The post condition is a valid list with a node new in the list with key k and value v. The linearization point is the successful CAS changing node's next pointer on line 57. By lemma 2 we know that node is in the list at line 75 where its value is read. We also know that next is not a marker node (checked on line 78) and given that the CAS will only succeed if node's next pointer has not changed we know that node is still in the list at the linearization point (before a node is removed its next pointer must be changed to point to a marker). Since node is in the list next is also obviously in the list at the time of the CAS. Given that these nodes are in the list and the list is valid, using lemma 3 and line 50 we have node.k < k as well as next.k > k meaning no node with key k is in the list at the time of the CAS. The post condition is ensured simply by the CAS which adds a node with key k (line 21), value v (line 21), and next pointer pointing to next (line 23) to the list after node. 2

Lemma 8

The successful delete operations on a valid list are linearizable.

Proof. This operation has a precondition of a node node in the list with key k, node.v = ⊥, and node.v = node. The postcondition is having the same node node in the list with key k and node.v = ⊥. The linearization point is the successful CAS changing the node's value on line 43. node.k = k is ensured by line 39 along with lemmas 1, 3. node.v = ⊥ of the precondition is ensured by the CAS along with line 42. node.v = node is also ensured by the CAS and line 75, this along with lemma 2 ensures that node is in the list just before and after the linearization point. The CAS ensures the postcondition of node.v = ⊥ and that the list is still valid. 2

Theorem 9 The skip list satisfies linearizability for the map abstraction.

Proof. This follows from lemmas 4, 5, 6, 7, and 8. 2

6 Proof of Non-Blockingness Theorem 10 The skip list is non-blocking.

Proof. In order to prove this we will show that a call to do_operation never completes only if infinite other concurrent calls to do_operation complete successfully. This is broken into two parts, first to show that when performed on a valid list the finish procedure is called repeatedly until the operation finishes unless there are other concurrent operations finishing successfully. And second to show that a call to the finish procedure returns ⊥ only in the case that some other concurrent operation has finished successfully. For finish to be called two while loops must first be exited. The first while loop on lines 63-73 traverses the index-item towers created by the adapting thread in the raise-index-level operation. The towers are created by linking index-items to nodes while traversing the next pointers of the nodes of the list (lines 133-141). Since we know the list is valid, when creating the towers, each index-item's right pointer will point to a tower of a node with a larger key. Given that the keys grow, as do_operation traverses the towers by following the right and down pointers it will continually traverse larger and larger keys until it reaches a key equal to or larger then k and exit the while loop (lines 70-72 and 66-69).

The second while loop is on lines 75-76 where do_operation traverses the list backwards in the list following prev pointers. The while loop exits when it encounters a node where node.v = node. In the proof of lemma 3 we showed that the traversed prev pointers always point to a node with a smaller key meaning that these pointers do not from a cycle, therefore if this while loop continues infinitely there must be infinite operations successfully adding nodes to the list.

We now need to show that the finish operation will be called eventually unless concurrent operations are completing. In each iteration of the while loop on lines 74-88 there are two cases in which finish will not be called. The first case is when next.v = next. When the while loop on line 75 exits we have node.v = node. Then after the next pointer and the next node's value is read (lines 77 and 78) if next is in the process of being removed (next.v = next) then help_remove is called (lines 79-80). What is important here is that when a node is in the process of being removed exactly one call (out of a possible many calls) to help_remove on that node is guaranteed to succeed. The only time all calls will fail is if a node (marker or normal) was concurrently added to the list in-between prev and node causing the CAS on line 107 to fail, but this means that some other operation has been successful. The second case finish is not called is when next.k ≤ k. Given that the list is valid and do_operation traverses forward in the list (line 88) the traversal will eventually reach a node with key larger then k, except in the cases where the condition of the while loop on line 75 is satisfied (node.v = node) causing the traversal to go backwards or while the condition on line 79 is satisfied (next.v = next), but for ether of these conditions to be satisfied some concurrent operation must have completed successfully by changing the value of node to point to node.

Finally to complete the proof we must show that a call to the finish procedure returns ⊥ only in the case that some other concurrent operation has finished successfully. By looking at the preconditions for the linearization points of the operations it is easy to see that lemma 3 ensures that finish is always called with input satisfying these preconditions. finish_contains never returns ⊥. finish_insert and finish_delete only return ⊥ in the case that a CAS has failed, but since the values input satisfy the preconditions of the linearization point, then one of these values must have changed by the time the CAS was called, meaning some other operations has completed successfully in the meantime. 2

Inria

Evaluation

Here we compare our skip list to the java.util.concurrent skip list on a multi-core machine. We evaluate their tolerance to contention and their scalability but also dissect the performance of two variants of the contention-friendly skip list and test them under shrink and grow workloads to better assess the reason of the results. We complete our evaluations by comparing the two non-blocking skip lists within the SPECjbb main-memory database benchmark.

Settings

The machine used for the tests runs two AMD 12-core processors, comprising 24 hardware threads in total. The tests were done using a microbench with each program thread repeatedly calling insert, remove, and contains operations. The ratio of update operations (insert, remove) to contains is set depending on the test. Insertions and deletions are executed with the same probability so that the data structure size remains constant in expectation with small variations due to concurrency. For each run we averaged the number of executed operations per millisecond over 5 runs of 5 seconds. The five runs execute successively as part the same JVM for the sake of warmup. We used Java SE 1.6.0 12-ea in server mode and HotSpot JVM 11.2-b01.

The JDK skip list is Doug Lea's Java implementation relying on Harris, Michael and Fraser algorithms [START_REF] Fraser | Practical lock freedom[END_REF][START_REF] Harris | A pragmatic implementation of non-blocking linked-lists[END_REF][START_REF] Michael | High performance dynamic lock-free hash tables and list-based sets[END_REF]. It comes with JDK 1.6 as part of the java.util.concurrent package. We compare this implementation to our contention-friendly skip list (CF) as given in Section 4 -both implementations are non-blocking.

Tolerance to contention

Figure 3(a) depicts the tolerance to contention of the algorithms, by increasing the percent of update operations from 0 to 100 (i.e., between 0% and 50% effective structure updates) with a thread count of 24. The approximate number of elements in the set abstraction is 5 thousand with operations choosing from a range of 10 thousand keys. We can see that the contention-friendly (CF) skip list has significantly higher performance (up to 2.5×) than the Java skip list (JDK) especially at high update ratio, indicating that the former better tolerates contention than the latter.

An interesting result is the performance gain when there is no contention (0% update). As the CF skip list does not have contention hot spots, it can afford maintaining indices for half of the nodes, so that half of the node have multiple levels. In contrast, JDK skip list maintains the structure so that only one quarter of the nodes have indices, to balance artificially the traversal complexity with the cost induced by hot spots. Not only does our strategy better tolerates contention, but it also improves performance in the absence of contention.

Figure 3(b) compares the performance of the skip list algorithms, run with 20% of update operations (i.e., 10% effective structure updates). Although the JDK skip list scales well with the number of threads, the contentionfriendly skip list scales better. In fact, the decoupling of the later allows to tolerate the contention raise induced by the growing amount of threads, leading to a performance speedup of up to 1.8×.

On the effect of maintenance and removal

In this section we present additional results in order to better assess the the performance benefits of the contentionfriendly skip list. For these experiments we include the following two skip list algorithms that are based on the contention-friendly methodology, using certain parts, but not all of it.

• Non-removal contention-friendly version (CF-NR): This version of the algorithm does not perform any physical removals. A node that is deleted is only marked as deleted, staying in the skip list forever. This algorithm helps us examine the cost of contention caused by physical removals. A dedicated adapting thread takes care of raising the towers.

• Non-adapting contention-friendly version (CF-NA): This version of the algorithm has no dedicated adapting thread. It only uses the selective removal concept of contention friendliness; only nodes of height 1 are physically removed. This version helps us examine the benefits of using an adapting thread. Given that there is no adapting thread, modifications to the upper list levels are done as part of the abstract operations using CAS operations for synchronization. A node's height, like in a traditional skip list, is chosen during the insert operation by a pseudo-random function with the one exception that a height greater than 1 will only be chosen if both of the node's neighbors have a height of 1. This avoids having "too many" tall nodes due to the fact that only nodes of height 1 are physically removed.

Table 1: Slowdown of increasing update ratio % using our CF skip lists against the JDK skip list with a set size of 64 or 64k elements and a small (S) or large (L) range of keys (24 threads). 1 depicts the slowdown due to contention by comparing the performance to the non-contended case (0% update ratio) always with 24 threads running. The update ratio is shown at values between 5% and 100% (50% effective). Two set sizes are used, one containing approximately 64 elements and the other containing 64 thousand elements. The range of keys the abstract operations can choose from is either 128 (S) or 128 thousand (L) for the 64 element set size and 128 thousand (S) or 128 million (L) for the 64 thousand element set size. The smaller range allows for higher contention on specific keys in the set while the larger range allows for more variation in the keys in the set.

Update

Considering the 64 element set size, for both ranges the slowdown is much greater using the JDK skip list compared to any of the other algorithms. For the JDK skip list we see up to nearly an 18× slowdown at 100% update with the large range while any of the others is always less than 10×. Between the CF versions we see that CF-NR provides the best performance which can be explained as follows. As the set size is small, performing marked removals induces much less contention than performing physical removals. CF performs better than CF-NA and JDK, with a maximum slowdown of about 6×.

For the 64 thousand element set size CF shows both good performance and small slowdown while CF-NA shows performance in-between CF and the JDK skip list. CF-NR shows the best performance with the range of 128 thousand elements, but performs poorly when the range is set to 128 million elements. In this case it has a slowdown of over 4× compared to the other CF algorithms which have slowdowns of around 2×. This must be due to the very large range: since CF-NR does not perform any physical removal the number of logically deleted nodes in the skip list grows so large that the cost of traversing them become significant. In particular, we saw in this benchmark a skip list of up to 6 million nodes.

Evaluating scalability

Table 2 displays the scalability of the algorithms by showing the effect of increasing the number of threads from 1 to 24. The tests were done with 10% and 100% update ratios with a set size of approximately 64 elements or 64 thousand elements. The small set size was tested with a range of 128 (S) and 128 thousand (L) keys while the large set size used a range of 128 thousand (S) and 128 million (L). Inria Table 2: Throughput of increasing thread number using our CF skip lists against the JDK skip list with a set size of 64k elements, an update percentage of 10% or 10% elements, and a small (S) or large (L) range of keys. First consider the 64 element set size. At 10% update all algorithms show good scalability for both ranges with CF showing the best performance of all algorithms. Things get more interesting at 100% update. For both range options (S and L) the JDK skip list starts loosing scalability after 12 cores, while CF performs well all the way up to 24-cores. For example, when using the large range (L) the JDK skip list has a speedup of 1.08× when going from 12 to 24 cores, while CF has a speed up of 1.76×. CF-NA scales well, but does not perform quite as well as CF, showing the advantage of having the adapting thread. CF-NR performs well when the range of 128 thousand is used, but performs poorly when the range is set to 128 million, again this is due to not physically removing nodes resulting in a very large list size.

Quality of the structural adaptation

The purpose of Figures 4(a)-4(b) is to test whether or not the adapting thread is effective when the number of elements in the set changes drastically. This is done by the following: In the grow benchmark the size of the set starts at 0 elements and grows until a size of 500 thousand elements, while the shrink benchmark starts with a set of size 500 thousand elements and ends with 2,500 elements. Like before the duration of these benchmarks is 5 seconds and they use 24 threads. Both benchmarks are executed with a 50% update ratio.

In the grow benchmark (Figure 4(a)) all algorithms show good scalability with a small performance advantage going to the algorithms with adapting threads (CF, CF-NR). This is likely due to the fact that these algorithms do not requiring synchronization operations on the towers.

In the shrink benchmark (Figure 4(b)) we see that the JDK skip list performs best at small thread counts while the contention-friendly algorithms show better scalability. Due to the decreasing list size CF calls the lower-index-level procedure on average 4 times per run of the benchmark and at the end of the benchmark the skip list contains around 15 thousand marked deleted nodes. Here lower-index-level is called by the adapting thread when it discovers that there are at least 10 times more marked deleted nodes than non-marked deleted ones. This number can be tuned so that the procedure is called more or less often, resulting in a skip list with a larger or smaller amount of marked deleted nodes.

SPECjbb 2005 as a main-memory database benchmark

SPECjbb 2005 [START_REF]Standard performance evaluation corporation[END_REF] is a highly scalable Java server benchmark designed to test different components, mainly focusing on the JVM. It is a multi-threaded benchmark but threads share very little data. The benchmark is based on the emulation of a three-tier client/server system using an in-memory database backed by Java collections. In addition to accessing a concurrent collection the benchmark also performs (among other things) Java BigDecimal computations, XML processing, and accesses to thread local collections. The collections implement the Java Map interface so they can be swapped for the JDK skip list or the CF skip list. Unfortunately in the default benchmark these collections are all thread local but not accessed concurrently. For the sake of concurrency, we replaced certain thread local collections (specifically the collections used to store orders and order history) with a single concurrent collection (a similar technique was used in [START_REF] Carlstrom | Transactional collection classes[END_REF] to test the scalability of transactional memory). It should be noted that this took a fair bit of modification so the results here should not be compared to other SPECjbb results, our goal here is to test if contention-friendly data structures show an improvement when they a small part of a larger program.

The scalability results of running the modified benchmark from 1 to 24 threads are shown in Figure 5. The first thing that should be noticed is that both skip list implementations show very good scalability. At 23 cores the JDK skip list skip list benchmark shows a 12.3× speed-up over a single core, while the contention-friendly skip list benchmark shows a 14.6× speed-up. There is obviously very little contention on the concurrent map, likely comparable to 1% or 2% update ratio of the micro-benchmark as at 5% we are already seeing large slowdowns (Table 1 at 24 threads). This is probably due to the fact that the accesses to the concurrent map are only part of the program that is performing many other actions. Even so, we do see a separation between the speedups of the skip lists, with increasingly higher speedups for contention-friendly skip list as the core count approaches 23. At 23 cores the JDK skip list version performs 747730 business operations per second (bops), the instrument of measure for SPECjbb performance, while the contention-friendly version performs 777662 bops. Overall this is a small performance difference, yet it is unsurprising given the already good scalability of the benchmark and the fact that the concurrent map accesses are only one piece of the benchmark.

Interestingly at 1 core the JDK skip list version has a small, but significant (7000 bops) performance advantage over the contention-friendly one which diminishes until 19 cores when the contention-friendly skip list takes over in performance. We believe this to be due to the fact that the JDK skip list is optimized for the JVM, minimizing the cost of loading the skip-list back to a thread's memory after it had been executing other tasks. Unsurprisingly the contention-friendly version takes a large performance hit when going from 23 to 24 cores because at that point the adapting thread and program threads must compete for processor time. Such observations tend to indicate that the contention-friendly skip list is really beneficial when there are less application threads running than available cores.

8 Extending the CF Skip List

Memory management

Nodes that are physically removed from the data structures must be garbage collected. Once a node is physically removed it will no longer be reachable by future operations.

Concurrent traversal operations could be preempted on a removed node so the node cannot be freed immediately. In languages with automatic garbage collection these nodes will be freed as soon as all preempted traversals continue past this node. If automatic garbage collection is not available then some additional mechanisms can be used. One simple possibility is to provide each thread with a local operation counter and a boolean indicating if the tread is currently performing an abstract operation or not. Then any physically removed node can be safely freed as long as each thread is either not performing an abstract operation or if it has increased its counter since the node was removed. This can be done by the adapting thread. Other garbage collection techniques can be used such as reference counting described in [START_REF] Detlefs | Lock-free reference counting[END_REF].

Distributing the structural adaptation

The algorithm we have presented exploits the multiple computational resources available on today's multicore machines by having a separate adapting thread. It could be adapted to support multiple adapting threads or to make each application thread participate into a distributed structural adaptation (if for example computational resources get limited). Although this second approach is appealing to maintain the big-oh complexity despite failures, it makes the protocol more complex.

To keep the benefit from the contention-friendliness of the protocol, it is important to maintain the decoupling between the abstract modifications and the structural adaptations. Distributing the tasks of the adapting thread to each application threads should not force them to execute a structural adaptation systematically after each abstract modification. One possible solution is that each application thread tosses a coin after each of its abstract modification to decide whether to run a structural adaptation. This raises an interesting question on the optimal proportion of abstract modifications per adaptation.

Another challenge of having concurrent structural adaptation is to guarantee that concurrent structural adaptations execute safely. This boils down into synchronizing the higher levels of the skip list by using CAS each time a pointer of the high level lists is adapted. An important note is that given the probability distribution of nodes per level in the skip list, the sum of the items in the upper list levels is approximately equal to the number of nodes in the bottom list level. On average the amount of conflicts induced by the skip list with a distributed adaptation could be potentially twice the one of the centralized adaptation. This exact factor depends, however, on the frequency of the distributed structural adaptation.

Finally, to distribute the structural adaptation each thread could no longer rely on the global information regarding the heights of other nodes. To recover to the probability distribution of item to levels without heavy inter-threads synchronization, a solution would be to give up the deterministic level computation adopted in the centralized version and to switch back to the traditional probabilistic technique: each application thread inserting a new node would simply choose a level with probability 2 -O( ) .

In the case where there additional resources available it might be interesting to assign multiple threads to separate adapting tasks. For example one thread could be responsible for choosing the heights of the nodes, with another responsible for the upper level modifications, and a third responsible for physical deletions.

Conclusion

Multicore programming brings new challenges, like contention, that programmers have to anticipate when developing every day applications. We explore the design of a contention-friendly and non-blocking skip list, keeping in mind that contention is an important cause of performance drops.

As future work, we would like to derive new contention-friendly data structures.

  (b) Adapting vertically the skip list structure

Figure 1 :

 1 Figure 1: Decoupling the eager abstraction insertion from the lazy selective adaptation

Figure 2 :

 2 Figure 2: The contention-friendly non blocking skip list structure

Case 1

 1 We have a precondition of having a node node with node.k = k and node.v = ⊥. The postcondition is a valid list containing the same node node with node.k = k and node.v = v. The linearization point is the successful CAS changing the node's value on line 52. The precondition of node.k = k is ensured by line 50 and lemma 1.

Figure 3 :

 3 Figure 3: Comparison of our CF skip list against the JDK concurrent skip list

Figure 4 :Figure 5 :

 45 Figure 4: Comparison of the scalability of our CF skip lists against the JDK concurrent skip list using the grow and shrink benchmarks (20% updates)

  Algorithm 1 Contention-friendly non-blocking skip list -abstract operations by process p 1: State of node: : finish(delete, k, v, node, val, next, next_val) p : Contention-friendly non-blocking skip list -structural adaptation by process p 90: remove(pred, node) p :

	2:	node a record with fields:		38:	result ← ⊥
	3:	k ∈ N, the node key		39:	if node.k = k then	£ node not found
	4:	v, the node's value, a value of ⊥ indicates	40:	result ← false
	5:	the node is logically deleted		41:	else
	6: 7: 8: 9: 10: 11: Algorithm 2 91: marker ∈ {true, false}, indicates if this is a marker node next, pointer to the next node in the list prev, pointer to the previous node in the list level, integer indicating the level of the node, initialized to 0 if node.level = 0 then £ only remove short nodes 42: 43: 44: 45: 46: 117: 47: 92: CAS(node.v, ⊥, node) £ mark for removal 118: 93: if node.v = node then 119:	if val = ⊥ then if CAS(node.v, val, ⊥) then remove(node.prev, node) result ← true else result ← false max ← -1 next ← top return result while next = ⊥ do	£ check for logical delete £ mark as deleted £ physical removal £ logically deleted £ add leftmost idx-items to array
	94: 12: State of index-item: help_remove(pred, node) 13: item a record with fields: 14: right, pointer to the next		120: 121: 122:	max ← max + 1 first[max] ← next next ← next.down
	15:	item in the SkipList		123:
	16: 97:	down, pointer to the IndexItem return
	17: 98:	one level below in the SkipList		53:	result ← true
	18: 19: 101: 102:	node, pointer a node in the list at the bottom of the SkipList new.v ← new new.marker ← true		54: 55: 56:	else result ← false else	£ not logically deleted
	22: 103: 104:	new.prev ← node CAS(node.next, n, new) n ← node.next		58: £ insert the marker 59: 130:	next.prev ← new result ← true raised ← false	£ raise index £ safe
	23: 24: 105: 106:	new.next ← next return new return		60: 131: 132:	index ← prev.right return result while true do
	107:	CAS(pred.next, node, n.next)		£ remove the nodes 133:	next ← index.right	£ traverse the list
				62: 134: 63: 135:	item ← top if next = ⊥ then while true do break()	£ start traversing from the top
	109:	index ← top		64:	next_item ← item.right	£ traverse the list
	110: 111:	while index.down.down = ⊥ do index ← index.down		65: 66: 137: £ get to the 2 nd lowest level 138:	next_item ← item.down prev.right ← next if next = ⊥ then	£ go down a level £ skip removed nodes
	112:	while index = ⊥ do		67: 139:	if next_item = ⊥ then break()	£ bottom level reached
	113:	index.down ← ⊥	68: £ remove the index-level below 140:	node ← item.node index ← next
	114:			69: 141:	break() next ← next.right
				70: 142:	else if next_item.node.k = k then
				71:	node ← item.node	£ found the node
				72:	break()
	32:	result ← false		73: 145:	item ← next_item raised ← true
	33:	if node.k = k then		74: 146:	while true do new.down ← index	£ while undone £ allocate a index-item: new
	34:	if (v = ⊥) then		£ check for logical delete 147: 75:	while node = (val ← node.v) do new.node ← index.node
	35: 36:	result ← true return result		76: 148: 77: 149: 78: 150: 79: 151:	node ← node.prev new.right ← prev-tall.right next ← node.next prev-tall.right ← new index.node.level ← height + 1 next_val ← next.v prev-tall ← new	£ Go to still present nodes £ raise the tower £ load the next node
				80: 152:	help-remove(node, next) prev ← index	£ continue the traversal
				81: 153:	continue() index ← index.right
				82: 154:	if (next = ⊥ ∨ next.k > k) then return raised
				83:	result ←	£ finish the contains/delete/insert
				84:	finish(op-type, k, v, node, val, next, next_val)
				85:	if result = ⊥ then
				86:	break()	£ done!
				87:	continue()	£ cannot finish due to concurrency
				88:	node ← next	£ continue traversal
				89:	return result

20: setup-node(node, next, k, v) p : 21: new.k ← k; new.v ← v 25: contains(k) p : 26: return do_operation(contains, k, * ) 27: delete(k) p : 28: return do_operation(delete, k, * ) 29: insert(k, v) p : 30: return do_operation(insert, k, v) 31: finish(contains, k, v, node, val, next, next_val) p : 3748: finish(insert, k, v, node, val, next, next_val) p : 49: result ← ⊥ 50: if node.k = k then 51: if val = ⊥ then £ check for logical delete 52: if CAS(node.v, ⊥, v) then £ logical insertion new ← setup_node(node, next, k, v) 57: if CAS(node.next, next, new) then £ insertion 61: do_operation(op-type, k, v) p : if next_item = ⊥ ∨ next_item.node.k > k then if (next = ⊥ ∧ next_val = next) then 95: help-remove(pred, node) p : 96: if (node.val = node ∨ node.marker) then n ← node.next 99: while ¬n.marker do £ marker to prevet lost inserts 100: new ← setup_node(node, n, ⊥, ⊥) if (pred.next = node ∨ pred.marker) then 108: lower-index-level() p : index.node.height ← index.node.height -1 115: index ← index.next 116: raise-index() p : inc-lvl ← raise-nlevel(first[max].node, first[max], 0) 124:

for (i ← max; i > 0; i ← i -1) do £ traverses indices 125: inc-lvl ← raise-ilevel(first[i], first[i -1], maxi) 126: if inc-

level then 127: new.down ← top £ allocate an index-item: new 128: top ← new £ add a new index-level 129: raise-ilevel(prev, prev-tall, height) p : 136: while index.node.v = index.node do if (prev.node.level ≤ height 143: ∧ index.node.level ≤ height 144: ∧ next.node.level ≤ height) then Inria RESEARCH CENTRE RENNES -BRETAGNE ATLANTIQUE Campus universitaire de Beaulieu 35042 Rennes Cedex Publisher Inria Domaine de Voluceau -Rocquencourt BP 105 -78153 Le Chesnay Cedex inria.fr ISSN 0249-6399

http://developers.memsql.com/docs/1b/indexes.html RR n°7969

RR n°7969