Chapter 81 Deadlock Avoidance Technique  Resource Allocation Denial: Grant incremental resource requests if we can prove that this leaves the system in.

Slides:



Advertisements
Similar presentations
Chapter 7: Deadlocks.
Advertisements

Chapter 7: Deadlocks.
Chapter 81 Deadlock is:  A set of blocked processes each holding a resource and waiting to acquire a resource held by another process in the set.  Example.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 7: Deadlocks.
Chapter 7: Deadlocks (Continuation). 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 14, 2005 Chapter 7: Deadlocks.
7.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 7: Deadlocks.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Lecture 12: Deadlocks (Chapter 7)
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 7: Deadlocks.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 30 Handling Deadlock.
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.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 8: Deadlocks System Model Deadlock Characterization Methods for Handling Deadlocks.
Chapter 7. Deadlocks.
Lecture 14 Chapter 7: Deadlocks (cont)
1 M. Bozyigit ICS Operating Systems Deadlock. 2 Deadlock n Permanent blocking of a set of processes that either compete for system resources or communicate.
Chapter 8: Deadlocks System Model Deadlock Characterization
03/07/2007CSCI 315 Operating Systems Design1 Deadlock Notice: The slides for this lecture have been largely based on those accompanying the textbook Operating.
1 School of Computing Science Simon Fraser University CMPT 300: Operating Systems I Ch 7: Deadlock Dr. Mohamed Hefeeda.
02/19/2008CSCI 315 Operating Systems Design1 Deadlock Notice: The slides for this lecture have been largely based on those accompanying the textbook Operating.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 14, 2005 Chapter 7: Deadlocks The Deadlock.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 7: Deadlocks.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 7: Deadlocks.
03/03/2004CSCI 315 Operating Systems Design1 Deadlock Notice: The slides for this lecture have been largely based on those accompanying the textbook Operating.
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.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 14, 2005 Objectives Understand the Deadlock.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Deadlocks.
System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention, Avoidance, and Detection Recovering from Deadlock Combined Approach.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 7: Deadlocks.
Chapter 7 Deadlocks. 7.2 Modified By Dr. Khaled Wassif Operating System Concepts – 7 th Edition Silberschatz, Galvin and Gagne ©2005 Chapter 7: Deadlocks.
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.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 AE4B33OSS Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock Characterization.
CHAPTER 8: DEADLOCKS System Model Deadlock Characterization
 The Deadlock Problem  System Model  Deadlock Characterization  Methods for Handling Deadlocks  Deadlock Prevention  Deadlock Avoidance  Deadlock.
Dr. Kalpakis CMSC 421, Operating Systems Deadlocks.
1 Advanced Operating Systems - Spring 2009 Lecture 10 – February 11, 2009 Dan C. Marinescu Office: HEC 439 B. Office.
Chapter 6 Concurrency: Deadlock and Starvation
Deadlocks System Model RAG Deadlock Characterization
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 7: Deadlocks System Model Deadlock Characterization Methods.
Lecture 12 Handling Deadlock – Prevention, avoidance and detection.
Mi-Jung Choi Dept. of Computer and Science Silberschatz, Galvin and Gagne ©2006 Operating System Principles Chapter 7: Deadlocks.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 7: Deadlocks.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Lecture 7 Operating Systems.
Chapter 8 Deadlocks. Objective System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance Deadlock Detection.
Chapter 7: Deadlocks. 7.2CSCI 380 – Operating Systems Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock Characterization Methods for Handling.
7.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock Characterization.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock.
CS307 Operating Systems Deadlocks Fan Wu Department of Computer Science and Engineering Shanghai Jiao Tong University Spring 2012.
Chap 7 Deadlocks. Chapter Objectives To develop a description of deadlocks, which prevent sets of concurrent processes from completing their tasks To.
1 CS.217 Operating System By Ajarn..Sutapart Sappajak,METC,MSIT Chapter 6 Deadlocks Slide 1 Chapter 6 Deadlocks.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 8: Deadlocks System Model Deadlock Characterization Methods for Handling Deadlocks.
Deadlocks Introduction to Operating Systems: Module 7.
7.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 7: Deadlocks.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock.
7.1 CSE Department MAITSandeep Tayal 7: Deadlocks System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 14, 2005 Chapter 7: Deadlocks The Deadlock.
CSE Operating System Principles Deadlocks. CSE – Operating System Principles2 Overview System Model Deadlock Characterization Methods for.
Chapter 7: Deadlocks. The Deadlock Problem System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 7: Deadlocks.
Chapter 7: Deadlocks.
OPERATING SYSTEM CONCEPTS AND PRACTISE
Chapter 7: Deadlocks.
Outline Deadlocks, dead lock prevention, avoidance.
Deadlock Prevention Restrain the ways request can be made.
Deadlocks Session - 14.
Chapter 7: Deadlocks.
Presentation transcript:

Chapter 81 Deadlock Avoidance Technique  Resource Allocation Denial: Grant incremental resource requests if we can prove that this leaves the system in a state in which deadlock cannot occur. Based on the concept of a “safe state”  Banker’s Algorithm: Tentatively grant each resource request Analyze resulting system state to see if it is “safe”. If safe, grant the request if unsafe refuse the request (undo the tentative grant) block the requesting process until it is safe to grant it.

Data Structures for the Banker’s Algorithm Let n = number of processes, m = number of resource types  Available: Vector of length m. If Available [j] = k, there are k instances of resource type R j currently available  Max: n x m matrix. If Max [i,j] = k, then process P i will request at most k instances of resource type R j.  Alloc: n x m matrix. If Alloc[i,j] = k then P i is currently allocated (i.e. holding) k instances of R j.  Need: n x m matrix. If Need[i,j] = k, then P i may need k more instances of R j to complete its task. Need [i,j] = Max[i,j] – Alloc [i,j].

Chapter 83 Safety Algorithm 1. 1.Let Work and Finish be vectors of length m and n, respectively. Initialize: Work := Available Finish [i] == false for i = 1,2, …, n. 2.Find an i such that both: Finish [i] == false Need i  Work If no such i exists, go to step Work := Work + Allocation i (Resources freed when process completes!) Finish[ i ] := true go to step 2. 4.If Finish [ i ] = true for all i, then the system is in a safe state.

Chapter 84 Resource-Request Algorithm for Process P i Request i = request vector for P i. Request i [j] = k means process P i wants k instances of resource type R j. 1.If Request i  Need i go to step 2. Otherwise, error ( process exceeded its maximum claim). 2.If Request i  Available, go to step 3. Otherwise P i must wait, (resources not available). 3.“Allocate” requested resources to P i as follows: Available := Available - Request i Alloc i := Alloc i + Request i Need i := Need i – Request i If safe  the resources are allocated to P i. If unsafe  restore the old resource-allocation state and block P i

Chapter 85 Example of Banker’s Algorithm 5 processes P 0 through P 4 3 resource types A (10 units), B (5 units), and C (7 units). Snapshot at time T 0 : AllocationMaxAvailable A B CA B C A B C P P P P P

Chapter 86 Example (cont) Need = Max – Allocation Need A B C P P P P P The system is in a safe state since the sequence satisfies safety criteria.

Chapter 87 Now P 1 requests (1,0,2) Check that Request  Available (that is, (1,0,2)  (3,3,2))  true. AllocationNeedAvailable A B CA B CA B C P P P P P Executing safety algorithm shows that sequence satisfies safety requirement. Can request for (3,3,0) by P 4 be granted? (no!) Can request for (0,2,0) by P 0 be granted? (no, unsafe)

Chapter 88 Banker’s algorithm: Comments  A safe state cannot be deadlocked. But an unsafe state is not necessarily deadlocked.  So if we withhold resources because the system would be “unsafe”: some processes may need to wait unnecessarily sub optimal use of resources

Chapter 89 Deadlock Detection  Resource accesses are granted to processes whenever possible (might lead to deadlock) (No need to declare Maximum Claim)  Detect the deadlock and recover.  The OS needs: an algorithm to check if deadlock is present an algorithm to recover from deadlock  The deadlock check can be performed at every resource request (high overhead) ...or less frequently

Chapter 810 Deadlock Detection  Similar to Safety Algorithm, but use Request matrix instead of Max matrix.  Note that processes not holding any resources cannot be involved in a deadlock!  Like Safety, find a sequence (if possible) in which resource allocations can be granted assume they can run to completion with these resources and then release all held resources might need more, leading to deadlock later, but we can detect that later!  Any processes not in this sequence are deadlocked

Deadlock Detection Algorithm  Marks each process not deadlocked. Initially all processes are unmarked. Then perform: Mark each process j for which: Alloc[ j,i] = 0 for all resource type i. (These are not deadlocked) Initialize work vector: Work[i] = Available[i] for all i REPEAT: Find a unmarked process j such that Request[ j,i ] <= Work[i] for all i. Stop if no such process exists. If such process j exists: mark process j and set Work[i] = Work [i] + Alloc[ j,i] for all i. Goto REPEAT. At the end: each unmarked process is deadlocked

Chapter 812 Deadlock Detection Example  Mark P4 since it has no allocated resources  Set Work = (0,0,0,0,1)  P3’s request <= Work. So mark P3 and set Work = Work + (0,0,0,1,0) = (0,0,0,1,1)  Algorithm terminates. P1 and P2 are deadlocked R1 R2 R3 R4 R5 P1 P2 P3 P4 Request Allocated Available R1 R2 R3 R4 R

Chapter 813 Deadlock Recovery  If you detect a deadlock, you need to do something!  The following approaches are possible: Abort all deadlocked processes (common to do this manually, inefficient) Rollback each deadlocked process to some previously defined checkpoint and restart them  Requires checkpoint/restart procedures in OS  The original deadlock may reoccur but good chance it won’t

Chapter 814 More recovery approaches  Successively abort deadlocked processes until deadlock no longer exists (Re-invoke the deadlock detection algorithm each time)  Successively preempt some resources from processes and give them to other processes until deadlock no longer exists a process that has a resource preempted must be rolled back to a point prior to its acquisition of the resource

Chapter 815 Deadlock Recovery (cont.)  Last approaches involve choosing a “victim” process :  Possible selection criteria: least amount of CPU time consumed so far least total resources allocated so far least amount of “work” produced so far Lowest priority Largest estimated remaining time Dean’s processes last...