1 Deadlock Solutions: Avoidance, Detection, and Recovery CS 241 March 30, 2012 University of Illinois.

Slides:



Advertisements
Similar presentations
Chapter 7: Deadlocks.
Advertisements

ICS Principles of Operating Systems Lectures 8 and 9 - Deadlocks Prof. Dmitri V. Kalashnikov dvk ics.uci.edu Slides © Prof. Nalini Venkatasubramanian.
Deadlock and Starvation
Concurrency: Deadlock and Starvation Chapter 6. Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate.
Deadlocks Today Resources & deadlocks Dealing with deadlocks Other issues Next Time Memory management.
6. Deadlocks 6.1 Deadlocks with Reusable and Consumable Resources
Chapter 7: Deadlocks.
7.5 Deadlock Avoidance The algorithm is simply to ensure that the system will always remain in safe state. Therefore, if a process requests a resource.
Ceng Operating Systems Chapter 2.4 : Deadlocks Process concept  Process scheduling  Interprocess communication  Deadlocks Threads.
1 Deadlocks Chapter Resource 3.2. Introduction to deadlocks 3.3. The ostrich algorithm 3.4. Deadlock detection and recovery 3.5. Deadlock avoidance.
5/25/2015Page 1 Deadlock Management B. Ramamurthy.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 30 Handling Deadlock.
Avishai Wool lecture Introduction to Systems Programming Lecture 5 Deadlocks.
Deadlock Chapter 3 R1 R2 P2P1 Allocated Requested.
Deadlocks CS 3100 Deadlocks1. The Deadlock Problem A set of blocked processes each holding a resource and waiting to acquire a resource held by another.
Chapter 7: Deadlocks. 7.2 Chapter Objectives To develop a description of deadlocks, which prevent sets of concurrent processes from completing their tasks.
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
1 School of Computing Science Simon Fraser University CMPT 300: Operating Systems I Ch 7: Deadlock Dr. Mohamed Hefeeda.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 7: Deadlocks.
Silberschatz, Galvin and Gagne  Operating System Concepts Deadlock and Starvation Deadlock – two or more processes are waiting indefinitely for.
Deadlocks Gordon College Stephen Brinton. Deadlock Overview The Deadlock Problem System Model Deadlock Characterization Methods for Handling Deadlocks.
1 School of Computing Science Simon Fraser University CMPT 300: Operating Systems I Ch 7: Deadlock Dr. Mohamed Hefeeda.
What we will cover…  The Deadlock Problem  System Model  Deadlock Characterization  Methods for Handling Deadlocks  Deadlock Prevention  Deadlock.
1 Deadlock Solutions CS 241 March 28, 2012 University of Illinois.
Deadlock Chapter 3 Thursday, February 22, Today’s Schedule Assignment #4 from Chapter 3 posted Deadlock - Chapter 3  Skip multiple resources (3.4.2.
CH 3 Deadlock When 2 (or more) processes remain blocked forever!
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 7: Deadlocks.
1 Deadlocks Chapter Resource 3.2. Introduction to deadlocks 3.3. The ostrich algorithm 3.4. Deadlock detection and recovery 3.5. Deadlock avoidance.
1 Deadlocks Chapter Resource 3.2. Introduction to deadlocks 3.3. The ostrich algorithm 3.4. Deadlock detection and recovery 3.5. Deadlock avoidance.
Cosc 4740 Chapter 6, Part 4 Deadlocks. The Deadlock Problem A set of blocked processes each holding a resource and waiting to acquire a resource held.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-6 Deadlocks Department of Computer Science and Software Engineering.
Operating Systems (OS)
Deadlocks Silberschatz Ch. 7 and Priority Inversion Problems.
CHAPTER 8: DEADLOCKS System Model Deadlock Characterization
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 7: Deadlocks.
MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 6 Deadlocks Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All.
CS6502 Operating Systems - Dr. J. Garrido Deadlock – Part 2 (Lecture 7a) CS5002 Operating Systems Dr. Jose M. Garrido.
This Time - Deadlock Definition Conditions for deadlocks
CS 346 – Chapter 7 Deadlock –Properties –Analysis: directed graph Handle –Prevent –Avoid Safe states and the Banker’s algorithm –Detect –Recover.
Chapter 7 Deadlocks Page 2 Chapter 7: Deadlocks System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance.
Chapter 7 Deadlocks. 7.1 Introduction Deadlock Common approaches to deal with deadlock – Prevention – Avoidance – Detection and recovery.
Deadlocks System Model RAG Deadlock Characterization
CS333 Intro to Operating Systems Jonathan Walpole.
Styresystemer og Multiprogrammering Block 3, 2005 Deadlocks Robert Glück.
Lecture 12 Handling Deadlock – Prevention, avoidance and detection.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Lecture 7 Operating Systems.
CS307 Operating Systems Deadlocks Fan Wu Department of Computer Science and Engineering Shanghai Jiao Tong University Spring 2012.
1 CS.217 Operating System By Ajarn..Sutapart Sappajak,METC,MSIT Chapter 6 Deadlocks Slide 1 Chapter 6 Deadlocks.
Deadlocks Copyright ©: University of Illinois CS 241 Staff1.
Silberschatz, Galvin and Gagne ©2009 Edited by Khoury, 2015 Operating System Concepts – 9 th Edition, Chapter 7: Deadlocks.
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 Deadlock.
Lecture 6 Deadlock 1. Deadlock and Starvation Let S and Q be two semaphores initialized to 1 P 0 P 1 wait (S); wait (Q); wait (Q); wait (S);. signal (S);
Deadlocks Lots of resources can only be used by one process at a time. Exclusive access is needed. Suppose process A needs R1 + R2 and B needs R1 + R2.
Chapter 7: Deadlocks.
Process Management Deadlocks.
Chapter 7: Deadlocks.
Deadlock Management.
Chapter 6 : Deadlocks What is a Deadlock?
Chapter 7: Deadlocks.
Introduction to Operating Systems
ICS 143 Principles of Operating Systems
Process Deadlocks.
Outline Deadlocks, dead lock prevention, avoidance.
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
Introduction to Deadlocks
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
Chapter 7: Deadlocks.
Deadlock CSE 2431: Introduction to Operating Systems
Presentation transcript:

1 Deadlock Solutions: Avoidance, Detection, and Recovery CS 241 March 30, 2012 University of Illinois

2 Deadlock: definition There exists a cycle of processes such that each process cannot proceed until the next process takes some specific action. Result: all processes in the cycle are stuck!

3 Deadlock solutions Prevention Design system so that deadlock is impossible Avoidance Steer around deadlock with smart scheduling Detection & recovery Check for deadlock periodically Recover by killing a deadlocked processes and releasing its resources Do nothing Prevention, avoidance and detection/recovery are expensive If deadlock is rare, is it worth the overhead? Manual intervention (kill processes, reboot) if needed

4 Last time: Deadlock Prevention #1: No mutual exclusion Thank you, Captain Obvious #2: Allow preemption OS can revoke resources from current owner #3: No hold and wait When waiting for a resource, must not currently hold any resource #4: Request resources in order When waiting for resource i, must not currently hold any resource j > i As you can see: If your program satisfies #3 then it satisfies #4

5 “Request In Order” is more permissive Will not deadlock Might deadlock (depending on scheduler, inputs, etc.) Definitely deadlock Request in order No hold and wait All programs

6 Are we always in trouble without ordering resources? No, not always: Ordered resource requests are sufficient to avoid deadlock, but not necessary Convenient, but may be conservative

7 Q: What’s the rule of the road? What’s the law? Does it resemble one of the rules we saw? I can almost get across Drat!

8 Deadlock Detection & Recovery

9 Deadlock Detection Check to see if a deadlock has occurred! Special case: Single resource per type E.g., mutex locks (value is zero or one) Check for cycles in the resource allocation graph General case E.g., semaphores, memory pages,... See book, p. 355 – 358

10 Dependencies between processes Resource allocation graph Corresponding process dependency graph

11 Deadlock Recovery Recovery idea: get rid of the cycles in the process dependency graph Options: Kill all deadlocked processes Kill one deadlocked process at a time and release its resources Steal one resource at a time Roll back all or one of the processes to a checkpoint that occurred before they requested any resources, then continue  Difficult to prevent indefinite postponement

12 Deadlock Recovery Have to kill one more Resource allocation graph Corresponding process dependency graph

13 Deadlock Recovery Only have to kill one Resource allocation graph Corresponding process dependency graph

14 Deadlock Recovery How should we pick a process to kill? We might consider... process priority current computation time and time to completion amount of resources used by the process amount of resources needed by the process to complete the minimal set of processes we need to eliminate to break deadlock is process interactive or batch?

15 Rollback instead of killing processes Selecting a victim Minimize cost of rollback (e.g., size of process’s memory) Rollback Return to some safe state Restart process for that state Note: Large, long computations are sometimes checkpointed for other reasons (reliability) anyway Challenge: Starvation Same process may always be picked as victim Fix: Include number of rollbacks in cost factor

16 Deadlock Avoidance

17 Deadlock Avoidance Idea: Steer around deadlock with smart scheduling Assume OS knows: Number of available instances of each resource  Each individual mutex lock is a resource with one instance available  Each individual semaphore is a resource with possibly multiple “instances” available For each process, current amount of each resource it owns For each process, maximum amount of each resource it might ever need  For a mutex this means: Will the process ever lock the mutex? Assume processes are independent If one blocks, others can finish if they have enough resources

18 How to guide the system down a safe path of execution Helper function: is a given state safe? Safe = there’s definitely a way to finish the processes without deadlock When a resource allocation request arrives Pretend that we approve the request Call function: Would we then be safe? If safe,  Approve request Otherwise,  Block process until its request can be safely approved  Some other process is scheduled in the meantime This is called the Banker’s Algorithm Dijkstra, 1965

19 What is a state? For each resource, Current amount available Current amount allocated to each process Future amount needed by each process (maximum) Free P1 alloc P2 alloc P1 need P2 need Buffer spaceA mutex

20 When is a state safe? There is an execution order that can finish In general, that’s hard to predict So, we’re conservative: find sufficient conditions for safety i.e., make some pessimistic assumptions Pessimistic assumptions: A process might request its maximum resources at any time A process will never release its resources until it’s done All states Safe Unsafe Deadlocked

21 Computing safety “There is an execution order that can finish” Search for an order P1, P2, P3,... such that: P1 can finish using what it has plus what’s free P2 can finish using what it has + what’s free + what P1 releases when it finishes P3 can finish using what it has + what’s free + what P1 and P2 will release when they finish...

22 Computing safety “There is an execution order that can finish” More specifically... Search for an order P1, P2, P3,... such that: P1’s max resource needs ≤ what it has + what’s free P2’s max resource needs ≤ what it has + what’s free + what P1 will release when it finishes P3’s max resource needs ≤ what it has + what’s free + what P1 and P2 will release when they finish... But how do we find that order?

23 Inspiration

24 Playing Pickup Sticks with Processes Pick up a stick on top = Find a process that can finish with what it has plus what’s free Remove stick = Process finshes & releases its resources Repeat until......all processes have finished  Answer: safe...or we get stuck  Answer: unsafe

25 Try it: is this state safe? P2 alloc Buffer spaceA mutex Free P2 need P1 alloc P1 need Which process can go first?

26 Try it: is this state safe? P2 alloc Free P2 need P1 alloc P1 need Start with P2 Buffer spaceA mutex

27 Try it: is this state safe? P2 alloc Free P2 need P1 alloc P1 need Release P2’s resources Buffer spaceA mutex

28 Try it: is this state safe? P2 alloc Free P2 need P1 alloc P1 need Release P2’s resources Buffer spaceA mutex

29 Try it: is this state safe? P2 alloc Free P2 need P1 alloc P1 need Continue with P1 Buffer spaceA mutex

30 Try it: is this state safe? P2 alloc Free P2 need P1 alloc P1 need Continue with P1 Buffer spaceA mutex

31 Try it: is this state safe? P2 alloc Free P2 need P1 alloc P1 need Yes, it’s safe: Order is P2, P1 Buffer spaceA mutex

32 Example 2: Is this state safe? P2 alloc Free P2 need P1 alloc P1 need P3 alloc P3 need Can P1 go first? Can P2 go first? Can P3 go first? Buffer space

33 Example 2: Is this state safe? P2 alloc Free P2 need P1 alloc P1 need P3 alloc P3 need Buffer space

34 Example 2: Is this state safe? P2 alloc Free P2 need P1 alloc P1 need P3 alloc P3 need Buffer space

35 Example 2: Is this state safe? P2 alloc Free P2 need P1 alloc P1 need P3 alloc P3 need Unsafe! Can P1 go next? Can P2 go next? Buffer space

36 Deadlock Summary Deadlock: cycle of processes/threads each waiting for the next Nasty timing-dependent bugs! Detection & Recovery Typically very expensive to kill / checkpoint processes Avoidance: steer around deadlock Requires knowledge of everything an application will request Expensive to perform on each scheduling event Prevention (ordered resources) Imposes conservative rules on application that preclude deadlock Application can do it; no special OS support

37 Deadlock Summary Typical solution: OS (Unix/Windows) do nothing (Ostrich Algorithm) Application uses general-purpose deadlock prevention Transaction systems (e.g., credit card processing) may use detection/recovery/avoidance

38 Concluding notes In general, deadlock detection or avoidance is expensive Must evaluate cost and frequency of deadlock against costs of detection or avoidance Deadlock avoidance and recovery may cause indefinite postponement Unix, Windows use Ostrich Algorithm (do nothing) Typical apps use deadlock prevention (order locks) Transaction systems (e.g., credit card systems) need to use deadlock detection/recovery/avoidance/prevention (why?) 38Copyright ©: University of Illinois CS 241 Staff