Download presentation
Presentation is loading. Please wait.
1
Contention in shared memory multiprocessors Multiprocessor synchronization algorithms (20225241) Lecturer: Danny Hendler Definitions Lower bound for consensus Lower bounds for counters, stacks and queues
2
Contention in shared-memory systems Contention: the extent to which processes access the same memory locations simultaneously When multiple processes simultaneously write to the same memory location, they are being stalled High contention hurts performance!
3
Memory Stalls & Write-Contention variable p0p0 p1p1 p2p2 pjpj Stalls# j 2 1 0 Write-contention is the maximum number of processes that can be enabled to perform a write or read-modify-write operation to the same memory location simultaneously.
4
Recall the consensus implementation we saw… Decide(v) ; code for p i, i=0,1 1.CAS(C, null, v) 2.return C Initially C=null We use a single object, C, that supports the compare&swap and read operations. What is the write-contention of this algorithm? n It can be shown that this is the write- contention of any consensus algorithm
5
What can we say about the worst-case time complexity of objects such as counters, stacks and queues?
6
Naïve Counter Implementation 3 4 6 5 2 1 FAI Last processes to succeed incur θ(n) time complexity! FAI Can we do much better? FAI object
7
We will see a time lower bound of √n on non-blocking implementations of: counters, stacks, queues… Any algorithm either (a) suffers high contention or (b) suffers high latency
8
The Memory-Steps Metric #read-variables - the number of distinct base objects read by an operation Memory stalls – The total number of memory stalls incurred by an operation memory-steps = #read-objects + memory-stalls We investigate the worst-case number of memory-steps incurred by a single high-level operation.
9
Capture Influence between processes 3 5 1 4 2 6 Time complexity is determined by the extent by which operations by different processes influence each other.
10
Influence-level Shared Counter 17 Each of us may precede you and modify the value you will get! Influence level (w.r.t. p) FAI Hmmm… I will soon request a value p
11
Modifying Steps Shared Counter 17 FAI Hmmm… I will soon request a value Each of us may precede you! p q
12
Modifying Steps Shared Counter 17 Hmmm… I will soon request a value Each of us may precede you! p q FAI
13
Modifying Steps Shared Counter 17 FAI Hmmm… I will soon request a value Each of us may precede you! p q
14
Modifying Steps Shared Counter 18 Hmmm… I will soon request a value Each of us may precede you! p q 17 There’s an atomic step in which q modifies p’s return value. We bring all the ‘Influencers’ to be on the verge of performing a modifying step FAI
15
Space/Write-contention tradeoff We bring all Influencers to be on the verge of a modifying step Each modifying step is necessarily a write/RMW operation S ≥S ≥ I C Space complexity Influence-level Write-contention
16
Latency/Contention tradeoff Base-objects on which there are outstanding modifying steps Shared Counter 17 FAI Hmmm… I will soon request a value p Process p can be made to read all these variables in the course of its operation! LR ≥LR ≥ I C # of read base objects Influence-level Write-contention
17
Time lower bound LRC ≥LRC ≥ I Time complexity is at least I
18
Influence(n) Objects Class Definition: The Influence-function, I o (n), of a generic object O, is defined as follows: I o (n)= k, if the influence-level of any n-process nonblocking implementation of O is at least k. Influence(n) includes: stacks, queues, hash-tables, pools, linearizable counters, consensus, approximate-agreement… Definition: Influence(n) is the class of generic objects whose Influence-function is in (n)
19
Concurrent Counter is in Influence(n) Shared Counter 17 Each of us may precede you! FAI Hmmm… I will soon request a value p Influence-level is (n-1): every q ≠ p can influence p
20
Stack is in Influence(n) Each of us may precede you! Hmmm… I will soon attempt to pop a value. p 1 2 3 n Top of stack Influence-level is (n-1), e.g. if every q ≠ p has a pending pop operation.
21
Approximate Agreement is in Influence(n) P1P1 0 2ε2ε2ε 2ε2ε Influence-level is (n-1) If p 1 runs first, it must return 0. If it is preceded by an execution where some q ≠ p 1 terminates, p 1 must return a value no less than ε. P2P2 P3P3 P4P4 P5P5 PnPn In approximate agreement, each process proposes its value. Validity: Each process must decide on a value that is legal (in the range of proposed values). Approximate agreement: The values decided by any two processes must be no more than ε apart.
22
The First-Generation Problem Every process calls a First operation once. We say an operation is in the first generation of execution E if it is not preceded in E by any other operation All operations not in the first generation of the execution must return false. In quiescence, at least one operation from the first generation must have returned true. Lemma The First-Generation object is in Influence(n), and for this problem our bound is tight. The bound for Influence(n) is tight
23
The mark array of n multi-reader multi-writer atomic variables An Optimal Implementation for the First Generation Problem Groups of n processes
24
A linear lower bound on the number of Stalls for long-lived objects The following material is not required for the exam/assignments.
26
Theorem: Consider any n-process implementation of an obstruction-free counter, then the worst-case number of stalls incurred by a process as it performs a fetch&increment operation is at least n-1.
27
Worst-case stalls number ≥ n-1 Start from an initial state. Fix a process p about to perform a fetch&increment operation. Consider the path it takes if it runs uninterrupted when only first-accesses to shared words are considered. p
28
Worst-case stalls number ≥ n-1 Start from an initial state. Fix a process p about to perform a fetch&increment operation. Consider the path it takes if it runs uninterrupted when only first-accesses to shared words are considered. p 2
29
Worst-case stalls number ≥ n-1 Start from an initial state. Fix a process p about to perform a fetch&increment operation. Consider the path it takes if it runs uninterrupted when only first-accesses to shared words are considered. p 2 3
30
Worst-case stalls number ≥ n-1 Start from an initial state. Fix a process p about to perform a fetch&increment operation. Consider the path it takes if it runs uninterrupted when only first-accesses to shared words are considered. p 2 34
31
Worst-case stalls number ≥ n-1 p 2 34 Let O1 be the first word along p's path that is written by some other process in any p-free execution There must be such a word. O1O1
32
Worst-case stalls number ≥ n-1 p 2 34 O1O1 Let E1 be an execution that maximizes the number of processes that are about to write to O1 over all p-free executions.
33
Worst-case stalls number ≥ n-1 p 2 34 O1O1 If (k 1 =n-1) then we are done. Otherwise, we show that p must access yet another word that may be written by other processes.
34
Worst-case stalls number ≥ n-1 p 2 34 O1O1 What happens if p incurs the stalls on O1?
35
Worst-case stalls number ≥ n-1 p 2 34 O1O1 What happens if p incurs the stalls on O1?
36
Worst-case stalls number ≥ n-1 p 2 34 O1O1 What happens if p incurs the stalls on O1?
37
Worst-case stalls number ≥ n-1 p 2 34 O1O1 What happens if p incurs the stalls on O1?
38
Worst-case stalls number ≥ n-1 p 2 34 O1O1 What happens if p incurs the stalls on O1?
39
Worst-case stalls number ≥ n-1 p 2 34 O1O1 What happens if p incurs the stalls on O1?
40
Worst-case stalls number ≥ n-1 p 2 34 O1O1 What happens if p incurs the stalls on O1? But now the rest of the path may change....
41
Worst-case stalls number ≥ n-1 p 2 34 O1O1 What happens if p incurs the stalls on O1? But now the rest of the path may change.... 3
42
Worst-case stalls number ≥ n-1 p 2 34 O1O1 What happens if p incurs the stalls on O1? But now the rest of the path may change.... 3
43
Worst-case stalls number ≥ n-1 p 24 O1O1 What happens if p incurs the stalls on O1? But now the rest of the path may change.... 3 Assume p gets value v
44
Worst-case stalls number ≥ n-1 24 O1O1 3 v: the value returned by p if we let it run and incur the stalls c: the number of fetch&increment operations completed before p starts its operation We have: v {c,…,c+K1} p
45
Worst-case stalls number ≥ n-1 v: the value returned by p if we let it run and incur the stalls c: the number of fetch&increment operations completed before p starts its operation We have: v {c,…,c+K1}
46
Worst-case stalls number ≥ n-1 24 O1O1 3 v: the value returned by p if we let it run and incur the stalls c: the number of fetch&increment operations completed before p starts its operation p We select some process q G 1 {p} We let q perform K 1 +1 fetch&increment operations q must write to a word read by p after O1
47
Worst-case stalls number ≥ n-1 24 O1O1 3 v: the value returned by p if we let it run and incur the stalls c: the number of fetch&increment operations completed before p starts its operation p We select some process q G 1 {p} We let q perform K 1 +1 fetch&increment operations q must write to a word read by p after O1 q
48
Worst-case stalls number ≥ n-1 v: the value returned by p if we let it run and incur the stalls c: the number of fetch&increment operations completed before p starts its operation We let q perform K 1 +1 fetch&increment operations q must write to a word read by p after O1
49
Worst-case stalls number ≥ n-1 24 O1O1 3 p Let O 2 be first word that will be accessed by p after it incurs the K 1 stalls that is written by some process G 1 {p} Let E 2 be an execution that maximizes the number of processes that are about to write to O 2 over all (G1 {p})-free executions.
50
Worst-case stalls number ≥ n-1 O1O1 p Continuing with this construction we get: O2O2 |G 2 | = K 2 |G m | = K m OmOm
51
Conclusion: “Naïve ” implementation is best possible! 3 4 6 5 2 1 FAI FAI object
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.