A TwoLock Concurrent Queue Algorithm Maged M Michael

  • Slides: 15
Download presentation
A Two-Lock Concurrent Queue Algorithm Maged M. Michael, Michael L. Scott University of Rochester

A Two-Lock Concurrent Queue Algorithm Maged M. Michael, Michael L. Scott University of Rochester Presented by Hussain Tinwala

Two-Lock Algorithm Goals • Provide a higher degree of concurrency • Use better blocking

Two-Lock Algorithm Goals • Provide a higher degree of concurrency • Use better blocking techniques • Improve performance on shared memory multiprocessor machines

Queue Operations: Enqueue • Enqueue Head (1) Node (2) Node (3) Tail (4) 1)

Queue Operations: Enqueue • Enqueue Head (1) Node (2) Node (3) Tail (4) 1) Create a new node Node (5) 2) Insert the node and update the T� ail Head (1) Node (2) Node (3) Node (4) Tail (5)

Queue Operations: Dequeue • Dequeue Head (1) Node (2) Node (3) Node (4) Tail

Queue Operations: Dequeue • Dequeue Head (1) Node (2) Node (3) Node (4) Tail (5) 1) Update the Head Node (1) Head (2) 2) Free the first node Node (2) Node (3) Node (4) Tail (5)

What do single-lock algorithms do? • They lock the entire queue • Example: 10

What do single-lock algorithms do? • They lock the entire queue • Example: 10 processes want to operate on the queue at the same time {P 1, …, P 10 } P 1 Head (1) Node (2) Node (3) Tail (4) P 2 P 3 P 4 P 5 P 6 P 7 P 8 P 9 P 10 High Contention

What do two locks do? (1) • Only lock the Head node or the

What do two locks do? (1) • Only lock the Head node or the Tail node • Enqueue: only needs to read/write the Tail node • Dequeue: only needs to read/write the Head node

What do two locks do? (2) • Example: 10 processes. Enqueuing processes {E 1,

What do two locks do? (2) • Example: 10 processes. Enqueuing processes {E 1, …, E 5} Dequeuing processes {D 1, …, D 5} D 1 D 3 D 4 D 5 D 2 Head (1) E 4 Node (2) Node (3) Tail (4) E 1 E 2 E 3 E 5 Increases Concurrency And Decreases Contention

Two Critical Mechanisms There are two kinds of processes: 1. Processes that have acquired

Two Critical Mechanisms There are two kinds of processes: 1. Processes that have acquired a lock 2. Processes that are trying to acquire a lock Issues: - Dealing with preemption of processes with locks (Preemption-safe locking) - Dealing with processes that keep trying to acquire a lock (Bounded exponential backoff)

Preemption-Safe Locking or Temporary Non-Preemption (processes holding locks) Note: There is a bound on

Preemption-Safe Locking or Temporary Non-Preemption (processes holding locks) Note: There is a bound on how much extra time the process can take after which the scheduler automatically forces preemption.

Bounded Exponential Backoff (processes trying to acquire a lock) • Bounded Exponential Backoff is

Bounded Exponential Backoff (processes trying to acquire a lock) • Bounded Exponential Backoff is an algorithm that uses feedback to multiplicatively decrease the rate of some process. Repeated attempts are exponentially delayed (1, 2, 4, 8…) up to a predefined bound. • The feedback here is that the process fails to acquire the lock

Performance of Backoff From: T. E. Anderson. The Performance of Spin Lock Alternatives for

Performance of Backoff From: T. E. Anderson. The Performance of Spin Lock Alternatives for Shared-Memory Multiprocessors. IEEE Transactions on Parallel and Distributed Systems.

Single-Lock v. Two-Lock (1) • The two techniques: preemption-safe locking and bounded exponential backoff

Single-Lock v. Two-Lock (1) • The two techniques: preemption-safe locking and bounded exponential backoff can also be used with a single-lock algorithm • If both algorithms (single-lock and twolock) use the two techniques, who wins? • Performance depends on: – Number of processors – Number of programs per processor (level of multiprogramming)

Single Lock v. Two Lock (2) Dedicated Multiprocessor: One process per processor Crossover points

Single Lock v. Two Lock (2) Dedicated Multiprocessor: One process per processor Crossover points 2 processes/processor: 5 3 processes / processor: 7

Verdict • It depends • • • Single-lock better at MP=1, #Processors=2 due to

Verdict • It depends • • • Single-lock better at MP=1, #Processors=2 due to cache misses Higher degree of multiprogramming means higher chance of preemption while holding a lock, therefore, two-lock suffers Two-lock good candidate for dedicated multiprocessor machines

End of Slide Show Questions/Comments?

End of Slide Show Questions/Comments?