CSE 451
Operating Systems
L12 - Deadlocks
Slides by: Tom Anderson
Baris Kasikci
Dining Lawyers
Each lawyer needs two chopsticks to eat. Each grabs chopstick on the right first.
Necessary Conditions for Deadlock
Question
Preventing Deadlock
Exploit or Limit Behavior
Question
Example
Thread 1
1. Acquire A
2.
3. Acquire C
4.
5. If (maybe) Wait for B
Thread 2
1.
2. Acquire B
3.
4. Wait for A
How can we make sure to avoid deadlock?
Deadlock Dynamics
eventually grant all requests
Possible System States
Question
Communal Dining Lawyers
Communal Mutant Dining Lawyers
Communal Mutant
Absent-Minded Dining Lawyers
Predict the Future
request would lead to deadlock
Banker’s Algorithm
CPU Scheduling
Main Points
Example
Definitions
More Definitions
First In First Out (FIFO)
Shortest Job First (SJF)
FIFO vs. SJF
Question
Question
Tail Latency
Round Robin
Round Robin
Round Robin vs. FIFO
always better than FIFO?
Round Robin vs. FIFO
Round Robin == Fairness?
Max-Min Fairness
Fair Ǫueueing: Implementing max-min
Example: Workload with I/O and Compute Tasks (Round Robin)
Tasks
I/O Bound
CPU Bound
CPU Bound
Time
Issues
I/O Request
I/O
Completes
Issues
I/O Request
I/O
Completes
Example: Workload with I/O and Compute Tasks (Weighted Fair Ǫueueing)
Round Robin vs. FIFO
Round Robin vs. FIFO
Round Robin with I/O and Compute Tasks
Multi-level Feedback Queue (MFQ)
MFQ
MFQ
Example: Workload with I/O and Compute Tasks (Multilevel Feedback Queues)
Example: Multilevel Feedback Queues and Starvation
Fair Queuing: Max-Min Fairness
Example: Workload with I/O and Compute Tasks (Fair Queueing)
Weighted Fair Queueing
Uniprocessor Summary (1)
Uniprocessor Summary (2)
Virtual Machines and Two Level Scheduling
Multiprocessor Scheduling
Per-Processor Affinity Scheduling
Per-Processor Multi-level Feedback with Affinity Scheduling
Bulk Synchronous Model of Parallelism
Bulk Synchronous in Action
Scheduling Parallel Programs
Scheduling Parallel Programs
Oblivious: each CPU time-slices its ready list independently
Gang Scheduling
Parallel Program Speedup
Virtual Machines and Two Level Scheduling
Space Sharing
Scheduler activations: kernel tells each app its assignment, and every time it changes
Queueing Theory
Assumption: average performance in a stable system, where the arrival rate (ƛ) matches the departure rate (μ)
Queueing Model
Definitions
Little’s Law
N = X * R
N: number of tasks in the system
Applies to any stable system – where arrivals match departures
Question
Suppose a system has throughput (X) = 100 tasks/s, average response time (R) = 50 ms/task
Question
Suppose a system has throughput (X) = 100 tasks/s, average response time (R) = 50 ms/task
Question
Suppose a system has throughput (X) = 100 tasks/s, average response time (R) = 50 ms/task
Question
X = 100 task/sec
R = 50 ms/task
S = 5 ms/task
W = 45 ms/task
Q = 4.5 tasks
Queueing
Queueing: Best Case
Response Time: Best vs. Worst Case
Queueing: Average Case?
Exponential Distribution
Exponential Distribution
Permits closed form solution to state probabilities, as function of arrival rate and service rate
Response Time vs. Utilization (Exponential)
Question
Variance in Response Time
What if Multiple Resources?
Sum over all i: Service time for resource i /
(1 – Utilization of resource i)
Overload Management
Highway Congestion (measured)
Why Do Metro Buses Cluster?
Suppose two Metro buses start 10 minutes apart. Why might they arrive at the same time?