1 / 20

EEE 435 Principles of Operating Systems

EEE 435 Principles of Operating Systems. Deadlock Detection and Recovery (Modern Operating Systems 3.4). Quick Review. What are our four conditions for deadlock? How are we going to try and solve it? (four ways…). Outline. Deadlock Detection One resource of each type

Download Presentation

EEE 435 Principles of Operating Systems

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. EEE 435Principles of Operating Systems Deadlock Detection and Recovery (Modern Operating Systems 3.4)

  2. Quick Review • What are our four conditions for deadlock? • How are we going to try and solve it? (four ways…) Dr Alain Beaulieu

  3. Outline • Deadlock Detection • One resource of each type • Multiple resources of each type • Recovery from a detected deadlock Dr Alain Beaulieu

  4. Deadlocks • For this solution to our deadlock problem, we accept that deadlocks will happen but we build a system for detection of deadlocks and the means to recover from them • Is this practical in the real world? Dr Alain Beaulieu

  5. Deadlock Detection • Consider systems with only single instances of each resource type • For example, one printer, one scanner, one magnetic storage • Multiple instances of each type will be considered later in this class • We have used directed graphs to easily see where a deadlock “loop” exists, can we implement an algorithm to do the same? Dr Alain Beaulieu

  6. Deadlock Detection • Draw this on your next slide: • Process A holds R and wants S • Process B holds nothing but wants T • Process C holds nothing but wants S • Process D holds U and wants S and T • Process E holds T and wants V • Process F holds W and wants S • Process G holds V and wants U Dr Alain Beaulieu

  7. Deadlock Detection Dr Alain Beaulieu

  8. Deadlock Detection • How can we implement an algorithm that detects a deadlock the same way our eyes do? • Create a list of nodes (called L) and follow out all connections from each node, adding nodes to the list when they are followed • If a node appears in the list twice, we know we have followed a loop! • Specific details, next slide, stay tuned! Dr Alain Beaulieu

  9. Deadlock Detection 1) For each node, N, in the graph, perform the following steps with N as the starting node: 2) Initialize L as an empty list and all arcs as unmarked 3) Add the current node to the end of L and check to see if it appears in L twice. If it does, the graph contains a cycle and the algorithm terminates 4) From the given node, see if there are any unmarked outgoing arcs. If so, go to step 5; if not, go to step 6 5) Pick an unmarked outgoing arc at random and mark it. Then follow it to the new current node and go to step 3 6) The algorithm is at a dead end. Remove the current node, go back to the node from which we came, and go to step 3. If this node is the initial node then the graph contains no cycles Dr Alain Beaulieu

  10. Deadlock Detection (empty for drawing demonstration of algorithm) Dr Alain Beaulieu

  11. Deadlock Detection • The solution for deadlock detection works for single instances of resources, but what about when we have multiple disks/printers/etc? • One solution is matrix-based and uses four data structures to identify deadlock conditions • m resource classes (ie: m=2, printer, scanner) • Ei instances of each resource class (1i  m) • E is the existing resource vector • A is the available resource vector • Two matrices: current allocation (C) and request(R) Dr Alain Beaulieu

  12. Deadlock Detection Resources in Existence (E1, E2, E3, ..., Em) Resources Available (A1, A2, A3, ..., Am) Doomsday Device Scanner Modem Printer Current Allocation Matrix Request Matrix Dr Alain Beaulieu Needed by process 1 Allocated to process 2

  13. Deadlock Detection • How do we use these four data structures to detect a deadlock? • Vector comparison. Define AB to mean that each element of A is less than or equal to the corresponding element of B • Mathematically, AB is true iff AiBi for 1im • Start by designating each process “unmarked” • Once a process is “marked” it indicates that it is able to complete and is therefore not deadlocked (that process in particular) Dr Alain Beaulieu

  14. Deadlock Detection • How do we use these four data structures to detect a deadlock? • Now apply the following algorithm: 1) Look for an unmarked process, Pi, for which the i-th row of R is less than or equal to A 2) If such a process is found, add the i-th row of C to A, mark the process, and go to step 1 3) If no such process exists, the algorithm terminates • If there are any unmarked processes at the termination of the algorithm, they are deadlocked Dr Alain Beaulieu

  15. Deadlock Detection • Example: Is there a deadlock here? Dr Alain Beaulieu

  16. Deadlock Recovery • Now that we can detect deadlock, how can we recover from it? • There are no good choices, just the lesser evil from a number of candidates • Recovery through preemption • Recovery through rollback • Recovery through killing processes Dr Alain Beaulieu

  17. Deadlock Recovery • Recovery through preemption • It may be possible to take a resource away from a process and give it to another • This may require manual intervention (ie: go to the printer and remove the sheets printed so far so as not to group them with the output from the other process) • This method is highly dependent on the nature of the resource – frequently difficult or impossible (writing to a database but only half done...can you really interrupt this?) Dr Alain Beaulieu

  18. Deadlock Recovery • Recovery through rollback • Processes are checkpointed periodically. Everything required to restart them in exactly the state they are in is written to file (including which resources are assigned to which resources) • If a deadlock occurs, a previous state can be restored and certain processes delayed so that the resources are not requested and deadlock does not occur • Disadvantage: time and resources taken to save the state Dr Alain Beaulieu

  19. Deadlock Recovery • Recovery through killing processes • Crude, effective, but potentially damaging • Best to kill a process in the cycle if it won’t disrupt all other processes in the cycle. Alternatively, another victim holding a required resource (that he is using but never plans on giving back so he is not technically part of the cycle) can be killed • Best choice: a process that can be rerun from the start with no ill effects • Worst choice: processes that modify static resources such as databases Dr Alain Beaulieu

  20. Quiz Time! Questions? Dr Alain Beaulieu

More Related