CSC 322 Operating Systems Concepts Lecture - 29: by

Slides:



Advertisements
Similar presentations
Chapter 7: Deadlocks.
Advertisements

Chapter 5 Deadlocks. Contents What is deadlock? What is deadlock? Characterization Characterization Resource allocation graph Resource allocation graph.
Concurrency: Deadlock and Starvation Chapter 6. Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate.
Operating Systems Lecture Notes Deadlocks Matthew Dailey Some material © Silberschatz, Galvin, and Gagne, 2002.
Concurrency: Deadlock and Starvation Chapter 6. Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate.
Lecture 7: Deadlock     Necessary Conditions for Deadlock     Deadlock Prevention - Havender's Linear Ordering Deadlock Avoidance Deadlock Detection &
Deadlocks Today Resources & deadlocks Dealing with deadlocks Other issues Next Time Memory management.
6. Deadlocks 6.1 Deadlocks with Reusable and Consumable Resources
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Ceng Operating Systems Chapter 2.4 : Deadlocks Process concept  Process scheduling  Interprocess communication  Deadlocks Threads.
EEE 435 Principles of Operating Systems Deadlock Avoidance, Prevention, and Wrap-Up (Modern Operating Systems 3.5, 3.6, and 3.7)
Operating Systems COMP 4850/CISG 5550 Deadlock Avoidance Dr. James Money.
Chapter 3 Deadlocks TOPICS Resource Deadlocks The ostrich algorithm
MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 6 Deadlocks Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All.
1 Deadlocks Chapter Resource 3.2. Introduction to deadlocks 3.3. The ostrich algorithm 3.4. Deadlock detection and recovery 3.5. Deadlock avoidance.
Tanenbaum Ch 6 Silberschatz Ch 7
Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Silberschatz, Galvin and Gagne ©2007 Deadlocks  (How to Detect Them and Avoid Them) A:
Chapter 7 Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 14, 2005 Chapter 7: Deadlocks 7.1 System Model.
Chapter 3 Deadlocks - Αδιέξοδα 3.1. Resource
With slides from C. Griwodz, K. Li, A. Tanenbaum and M. van Steen
Avishai Wool lecture Introduction to Systems Programming Lecture 5 Deadlocks.
DPNM Lab. Dept. of CSE, POSTECH
Deadlock Chapter 3 R1 R2 P2P1 Allocated Requested.
Deadlocks. 2 System Model There are non-shared computer resources –Maybe more than one instance –Printers, Semaphores, Tape drives, CPU Processes need.
The Banker’s Algorithm for A Single Resource
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
Deadlock Detection with One Resource of Each Type (1)
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 7: Deadlocks.
Chapter 6 Concurrency: Deadlock and Starvation
Deadlock Characterization
CH 3 Deadlock When 2 (or more) processes remain blocked forever!
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.4. Deadlock detection and recovery 3.5. Deadlock avoidance 3.6. Deadlock prevention.
1 Deadlocks 2 Resources Examples of computer resources –printers –tape drives –tables Processes need access to resources in reasonable order Suppose.
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 3. 2 Resources Examples of computer resources –printers –tape drives –tables Processes need access to resources in reasonable order.
Operating Systems 软件学院 高海昌 Operating Systems Gao Haichang, Software School, Xidian University 22 Contents  1. Introduction** 
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 MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 6 Deadlocks Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc.
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.
Resource Management Reusable  Disk blocks  File descriptors  Semaphores Consumable  Messages  Packets.
Operating Systems (CS 340 D) Dr. Abeer Mahmoud Princess Nora University Faculty of Computer & Information Systems Computer science Department.
Deadlocks. What is a Deadlock “A set of processes is deadlocked if each process in the set is waiting for an event that only another process in the set.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 14, 2005 Chapter 7: Deadlocks The Deadlock.
CSC 322 Operating Systems Concepts Lecture - 28: by Ahmed Mumtaz Mustehsan Special Thanks To: Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
CS333 Intro to Operating Systems Jonathan Walpole.
7.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock Characterization.
Silberschatz, Galvin and Gagne ©2009 Edited by Khoury, 2015 Operating System Concepts – 9 th Edition, Chapter 7: Deadlocks.
CH 3 Deadlock When 2 (or more) processes remain blocked forever!
Deadlocks Chapter 6 Tanenbaum & Bo, Modern Operating Systems:4th ed., (c) 2013 Prentice-Hall, Inc. All rights reserved.
Sistem Operasi IKH311 Deadlock. 2 Resources Examples of computer resources printers tape drives tables Processes need access to resources in reasonable.
Process Management Deadlocks.
Operating Systems, Summer Semester 2011
Operating Systems, Winter Semester 2011
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Concurrency: Deadlock and Starvation
Chapter 7 – Deadlock and Indefinite Postponement
Chapter 6 : Deadlocks What is a Deadlock?
Lecture 19: Deadlock: Conditions, Detection and Avoidance
CS 333 Introduction to Operating Systems Class 7 - Deadlock
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
Lecture 19: Deadlock: Conditions, Detection and Avoidance
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
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Presentation transcript:

CSC 322 Operating Systems Concepts Lecture - 29: by Ahmed Mumtaz Mustehsan Special Thanks To: Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. (Chapter-6) Silberschatz, Galvin and Gagne 2002, Operating System Concepts, www.sju.edu/~ggrevera/cscSystems/cscSystems-3-deadlock.ppt‎ Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad 1

Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad Chapter 6 Deadlock Lecture-29 Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad

Ways of Handling Deadlock Deadlock Detection (studied) Deadlock Recovery (studied) Deadlock Avoidance (Today) Deadlock Prevention (Today) Lecture-29 Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad

Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad Deadlock Avoidance Allow the chance of deadlock to occur, but avoid it happening when it is going to happen!!! Check whether the next state (change in system) may end up in a deadlock situation; avoid it. Plotting of Graph (Next Slide) Explains the idea!!! Lecture-29 Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad

Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad Deadlock Avoidance Two process resource trajectories. Lecture-29 Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad

Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad Deadlock avoidance Safe state = NO deadlock! there exists some scheduling order in which every process can run to completion even if all of them suddenly request their max number of resources immediately Unsafe != deadlocked Lecture-29 Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad

Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad Safe states Lecture-29 Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad

Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad Unsafe states With only 4 free, neither A nor C can be completely satisfied. Lecture-29 Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad

Banker’s algorithm for single resource (SR) type Lecture-29 Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad

Dijkstra's Banker's Algorithm Definitions Each process has a LOAN, MAXIMUM NEED, CLAIM LOAN: current number of resources held MAXIMUM NEED: total number resources needed to complete CLAIM: = (MAXIMUM - LOAN) Lecture-29 Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad

Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad Assumptions Establish a LOAN ceiling (MAXIMUM NEED) for each process MAXIMUM NEED < total number of resources available (ie., capital) Total loans for a process must be less than or equal to MAXIMUM NEED Loaned resources must be returned back in finite time; Assume immediately after completion. Total resources available are much less than the total committed accumulative resources . Lecture-29 Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad

Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad Algorithm 1. Search for a process with a claim that can be satisfied using the current number of remaining resources (ie., tentatively grant the claim) 2. If such a process is found then assume that it will return all the loaned resources. 3. Update the number of remaining resources 4. Repeat steps 1-3 for all processes and mark them completed. Lecture-29 Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad

Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad DO NOT GRANT THE CLAIM if at least one process can not be marked to completion. Implementation A resource request is only allowed if it results in a SAFE state The system is always maintained in a SAFE state so eventually all requests will be filled Lecture-29 Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad

Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad Advantages It works Allows jobs to proceed where a prevention algorithm wouldn't Problems Requires that there are a fixed number of resources What happens if a resource goes down? Does not allow the process to change its Maximum need while processing Lecture-29 Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad

Banker’s algorithm (SR) Grant only those requests that lead to safe states. Requires future information. Lecture-29 Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad

Banker’s algorithm (SR) Issue2 get back 4 Free =4 (b) is safe because from (b) we can give C 2 more (free=0) then C completes (free=4) then give either B or D . . . Lecture-29 Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad

Banker’s algorithm (SR) Issue 1 to B Free =1 No max could be served now (c) is unsafe because no max can be satisfied Lecture-29 Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad

Banker’s algorithm for multiple resource (MR) types Lecture-29 Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad

Banker’s algorithm (MR) (need) E=existing (total); constant P=possessed (allocated/held) A=available (free) ∑ Lecture-29 Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad

Banker’s algorithm (MR) To check for a safe state: Look for a row, R, in N <= A. Assume the chosen process of the row requests all resources, runs to completion, and terminates (giving back all of its resources to A). Repeat steps 1 and 2 until either all processes run to completion or terminate (indicating that the initial state is safe) or deadlock occurs. Lecture-29 Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad

Banker’s algorithm (MR) To check for a safe state: Look for a row, R, in N <= A. A (available) can completely satisfy D’s needs. Lecture-29 Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad

Banker’s algorithm (MR) Previous: E=(6342) P=(5322) A=(1020) To check for a safe state: Look for a row, R, in N <= A. Assume the process of the chosen row requests all resources, runs to completion, and terminates (giving back all of its resources to A). After D terminates: E=(6342) P=(4221) A=(2121) Lecture-29 Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad

Banker’s algorithm (MR) Previous: E=(6342) P=(5322) A=(1020) To check for a safe state: Look for a row, R, in N <= A. E=(6342) P=(4221) A=(2121) Lecture-29 Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad

Banker’s algorithm (MR) Previous: E=(6342) P=(4221) A=(2121) To check for a safe state: Look for a row, R, in N <= A. Assume the process of the chosen row requests all resources, runs to completion, and terminates (giving back all of its resources After A terminates: E=(6342) P=(1210) A=(5132) Lecture-29 Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad

Banker’s algorithm (MR) Previous: E=(6342) P=(4221) A=(2121) To check for a safe state: Look for a row, R, in N <= A. E=(6342) P=(1210) A=(5132) Lecture-29 Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad

Banker’s algorithm (MR) Previous: E=(6342) P=(1210) A=(5132) To check for a safe state: Look for a row, R, in N <= A. E=(6342) P=(1110) A=(5232) Lecture-29 Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad

Banker’s algorithm (MR) Previous: E=(6342) P=(1210) A=(5132) To check for a safe state: Look for a row, R, in N <= A. E=(6342) P=(1110) A=(5232) Lecture-29 Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad

Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad Deadlock prevention Lecture-29 Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad

Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad Deadlock Prevention Remove the possibility of deadlock occurring by denying one of the four necessary conditions: Mutual Exclusion (Can we share everything?) Hold & Wait No preemption Circular Wait Lecture-29 Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad

Deadlock prevention: Attack mutex Example: Use spooling instead of mutex on printer Not all problems lend themselves to spooling Still have contention for disk space with spooling Lecture-29 Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad

Deadlock prevention: attack hold & wait Request (and wait for) all resources prior to process execution Problems: We may not know in advance the requirements of resources. We tie up resources for entire time. Before requesting a resource, we must first temporarily release all allocated resources and then try to acquire all of them again. Lecture-29 Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad

Denying the “Hold & Wait” Implementation A process is given its resources on a "ALL or NONE" basis Either a process gets ALL its required resources and proceeds or it gets NONE of them and waits until it can Lecture-29 Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad

Denying the “Hold & Wait” Advantages It works Reasonably easy to code Problems Resource wastage Possibility of starvation Lecture-29 Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad

Denying “No pre-emption” Tricky at best. Impossible at worst. Implementation Resources may be removed from a process before it is finished with them. Forcefully preempt the resource. Lecture-29 Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad

Denying “No pre-emption” Advantages It works Possibly better resource utilisation Problems The cost of removing a process's resources The process is likely to lose work it has done. (How often does this occur?) Possibility of starvation Lecture-29 Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad

Attacking the Circular Wait Condition (a) Numerically ordered resources. (b) A resource graph. Processes can request resources whenever they want to, but all requests must be made in numerical order. Example: A process may request first a printer and then a tape drive, but it may not request first a plotter and then a printer. Lecture-29 Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad

Deadlock prevention: attack circular wait Only allow one resource at a time. Request all resources in (some globally assigned) numerical order. But no numerical ordering may exist! Implementation Resources are uniquely numbered Processes can only request resources in linear ascending order Thus preventing the circular wait from occurring Lecture-29 Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad

Deadlock prevention: attack circular wait Advantages It works Has been implemented in some OS Problems Resources must be requested in ascending order of resource number rather than as needed Resource numbering must be maintained by someone and must reflect every addition to the OS Difficult to sit down and write just write code Lecture-29 Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad

Approaches to Deadlock Prevention Summary of approaches to deadlock prevention. Lecture-29 Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad

Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad Other Issues Two-phase locking Commonly used in databases. First phase: lock all the needed resources. If locking succeeds, go to second phase, else release all the locks. Second phase: do the read or write operation. Communication deadlocks Livelock Starvation Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad

Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad Two-phase locking Two-phase locking Commonly used in databases. First phase: lock all the needed resources. If locking succeeds, go to second phase, else release all the locks; go to First Phase. Second phase: do the read or write operation. And release the records Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad

Communication Deadlocks Example: Suppose process A sends a request message to process B, and then blocks until B sends back a reply message. Suppose that the request message gets lost. A is blocked waiting for the reply. B is blocked waiting for a request asking it to do something. We have a deadlock! Not the classical resource deadlock. This situation is called a communication deadlock. Lecture-29 Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad

Communication Deadlocks In a communication system a node is either computer or Router having finite buffers ( 8 in example) If no buffer available we have a resource deadlock in a network. Lecture-29 Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad

Communication Deadlocks Example: Suppose that all the packets at router A need to go to B and all the packets at B need to go to C and all the packets at C need to go to D and all the packets at D need to go to A. No packet can move because there is no buffer at the other end and we have a classical resource deadlock, in the middle of a communications system. Lecture-29 Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad

Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad Livelock Busy waiting that can lead to livelock. Lecture-29 Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad

Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad Livelock Example: In some situations, polling (busy waiting) is used to enter a critical region or access a resource. This strategy is often used when the mutual exclusion will be used for a very short time and the overhead of suspension is large compared to doing the work. Consider an atomic primitive in which the calling process tests a mutex and either grabs it or returns fail. We do not have a deadlock (because no process is blocked) but we have functionally equivalent to deadlock but livelock. Lecture-29 Ahmed Mumtaz Mustehsan, GM-IT, CIIT, Islamabad