240 likes | 368 Views
Contention Management and Obstruction-free Algorithms. Niloufar Shafiei. Agenda. Introduction Non-blocking approaches Contention management Two obstruction-free shared deque algorithms. Distributed shared memory systems. Mutual exclusion (using locks) Delay of processes
E N D
Contention Management and Obstruction-free Algorithms Niloufar Shafiei
Agenda • Introduction • Non-blocking approaches • Contention management • Two obstruction-free shared deque algorithms
Distributed shared memory systems • Mutual exclusion (using locks) • Delay of processes • Not fault-tolerant (failure of processes) • Deadlock • Priority inversion • Non-blocking • Delay and failure of processes do not cause performance problems
Non-blocking • Wait-free • All processes complete in a finite number of steps. • Lock-free • Some processes complete in a finite number of steps. • Significant overhead • Complex and subtle
Non-blocking • Obstruction-free • Each process completes if it runs without interference for sufficiently long. • Not guarantee the progress • Simpler • Easier to design
Contention management Decide which process can take steps at a time A simple method is back-off when they encounter interference. Contention management policy: • Guarantee the progress of all process
Contention Management Obstruction-free Algorithms + Wait-free Algorithms =
Contention Management Policies • Aggressive • Always abort • Polite • Exponential back-off • KillBlocked • Abort if an operation is blocked or waits for maximum waiting time • Karma • Set a priority (priority = amount of work + number of retries)
Contention Management Policies • Eruption • Set a priority and increase priority of running operation • Randomized • Flip a coin • Kindergarten • Keep a list • Timestamp • Abort earlier timestamp • QueueONBlock • Set a flag of waiting operation
Obstruction-free Deque on Linear Array LN … LN RN … RN 0 1 … MAX+1 value counter Invariant: array always consists of at least one LN, followed by zero or more data values, followed by at least one RN.
Rightpush(v) • Change the leftmost RN to v • Find index of leftmost RN LN … LN RN … RN k
2. Check if k=MAX+1 then deque is full 3. Increase the counter of A[k-1] LN … … … … RN K=MAX+1 A[k-1] LN … … RN … RN k
4. Change A[k] to v and increase its counter value LN … … v … RN k
Rightpop • Change the rightmost data value to RN. • Find index of leftmost RN LN LN RN RN k
2. Check if deque is empty 3. Increase the counter of A[k] LN LN LN LN RN RN k-1 k A[k] LN LN RN RN k
4. Change A[k-1] to RN and increase its counter value and return the popped value LN LN RN RN RN k
Problem: • push on one end and pop from the other end LN LN LN LN LN RN
Obstruction-free Deque on Circular Array DN LN RN LN RN LN RN LN Invariants: All null values are in a contiguous sequence of locations. The sequence consists of zero or more RN, followed by zero or one DN, followed by zero or more LN. At least two different null values are in the sequence.
Rightpush(v) • Change the leftmost RN to v • Find index of leftmost RN DN LN RN LN RN LN k v1 v2
2. Read A[k+1] • If A[k+1] = RN DN LN k+1 RN LN RN LN k v1 v2 k-1 Increase the counter value of A[k-1] Change A[k] to v
If A[k+1] = LN LN LN k+1 LN LN RN LN k v1 v2 k-1 Increase the counter value of A[k] Change A[k+1] to DN
If A[k+1] = DN and A[k+2] Null k+2 v6 v5 k+1 DN v4 RN v3 k v1 v2 k-1 Return FULL
If A[k+1] = DN and A[k+2] = LN k+2 LN v5 k+1 DN v4 RN v3 k v1 v2 k-1 Increase the counter value of A[k+2] Change A[k+1] to RN
Conclusion • Obstruction-free weakens the progress property but it is simpler. • Contention management policies improve the progress of obstruction-free algorithms. • Obstruction-free algorithms with appropriate contention management policy can perform like wait-free algorithms in practice.