OPERATING SYSTEMS DEADLOCKS



Similar documents
System model. Section 7.1. Operating Systems: Deadlock p. 1/15

Chapter 7: Deadlocks!

The Deadlock Problem. Deadlocks. Deadlocks. Bridge Crossing Example

Resource Allocation and Deadlock Resource Allocation and Handling

Section 1. Inequalities

OPERATING SYSTEMS SCHEDULING

Problem set on Cross Product

Outlook Web App (OWA) To create a new message:

Dynamic Programming. Lecture Overview Introduction

/ Operating Systems I. Process Scheduling. Warren R. Carithers Rob Duncan

CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team

Scheduling. Getting Started. Scheduling 79

Unit 7 The Number System: Multiplying and Dividing Integers

Real-Time Scheduling (Part 1) (Working Draft) Real-Time System Example

Linux Process Scheduling Policy

My Favorite Futures Setups. By John F. Carter

Efficiency of algorithms. Algorithms. Efficiency of algorithms. Binary search and linear search. Best, worst and average case.

Priority Inversion Problem and Deadlock Situations


FirstClass FAQ's An item is missing from my FirstClass desktop

Search help. More on Office.com: images templates

W4118 Operating Systems. Instructor: Junfeng Yang

Process / Operation Symbols

Create a Poster Using Publisher

2 SYSTEM DESCRIPTION TECHNIQUES

Chapter 12 File Management. Roadmap

Chapter 12 File Management

Solutions to Homework 6

Common Data Structures

Advanced Programming with LEGO NXT MindStorms

1 Description of The Simpletron

Introduction to Data Structures

Method To Solve Linear, Polynomial, or Absolute Value Inequalities:

Decision Making under Uncertainty

Announcements. Basic Concepts. Histogram of Typical CPU- Burst Times. Dispatcher. CPU Scheduler. Burst Cycle. Reading

INTRODUCTION TO MATHEMATICAL MODELLING

Notes on Determinant

Understanding Backup and Recovery Methods

Protocol for Microscope Calibration

Introduction to Parallel Programming and MapReduce

Homework 1 (Time, Synchronization and Global State) Points

PostgreSQL Concurrency Issues

Transmission Lines. Smith Chart

Graph Theory Problems and Solutions

BPMN Business Process Modeling Notation

Sales people who are trying to switch your phone service or put you on VoIP. Sales people who work for companies who fix billing errors.

CSE 326, Data Structures. Sample Final Exam. Problem Max Points Score 1 14 (2x7) 2 18 (3x6) Total 92.

A linear combination is a sum of scalars times quantities. Such expressions arise quite frequently and have the form

Fixed Point Theorems

Adobe Acrobat 6.0 Professional

OPERATING SYSTEMS STRUCTURES

Question #1: What are the main issues considered during physical database design?

Agent vs. Agent-less auditing

Event Log. Chapter 7 Event Log Event Log Management Excel Editing Create a New Event Log... 10

Issue 1. Nokia and Nokia Connecting People are registered trademarks of Nokia Corporation

Lecture 7: Concurrency control. Rasmus Pagh

The PageRank Citation Ranking: Bring Order to the Web

Operating Systems, 6 th ed. Test Bank Chapter 7

Anomaly detection. Problem motivation. Machine Learning

MATLAB Workshop 3 - Vectors in MATLAB

Fair Scheduler. Table of contents

CS 245 Final Exam Winter 2013

Statgraphics Getting started

Mathematics Content: Pie Charts; Area as Probability; Probabilities as Percents, Decimals & Fractions

Unified Lecture # 4 Vectors

SYSM 6304: Risk and Decision Analysis Lecture 5: Methods of Risk Analysis

Weather Direct Displays show Lost Forecast (blank boxes in the picture icons)

6.02 Practice Problems: Routing

Operating Systems OBJECTIVES 7.1 DEFINITION. Chapter 7. Note:

Solution to Homework 2

Compute Cluster Server Lab 3: Debugging the parallel MPI programs in Microsoft Visual Studio 2005

WRITING PROOFS. Christopher Heil Georgia Institute of Technology

Textbook and References

8.1 Min Degree Spanning Tree

Graph Theory Origin and Seven Bridges of Königsberg -Rhishikesh

oxigen system Slot.it oxigen timing RMS installation Dongle driver installation 1/ 11 Race Management Software

Inv 1 5. Draw 2 different shapes, each with an area of 15 square units and perimeter of 16 units.

1 Solving LPs: The Simplex Algorithm of George Dantzig

Free Inductive/Logical Test Questions

Chapter 2 Data Storage

Class Registration 101

Introduction to Distributed Systems

13 Managing Devices. Your computer is an assembly of many components from different manufacturers. LESSON OBJECTIVES

Course Content. Transactions and Concurrency Control. Objectives of Lecture 4 Transactions and Concurrency Control

COSC 6374 Parallel Computation. Parallel I/O (I) I/O basics. Concept of a clusters

2) Write in detail the issues in the design of code generator.

TRAVEL MANAGEMENT SYSTEM MILEAGE CLAIMS Procedure

PROG0101 Fundamentals of Programming PROG0101 FUNDAMENTALS OF PROGRAMMING. Chapter 3 Algorithms

Process Scheduling. Process Scheduler. Chapter 7. Context Switch. Scheduler. Selection Strategies

Navigating Your SIS Home Page

Event Log. Chapter 7 Event Log Event Log Management Excel Editing Create a New Event Log... 9

Grade 6 Math Circles March 10/11, 2015 Prime Time Solutions

Concepts of Database Management Seventh Edition. Chapter 7 DBMS Functions

Flowcharting, pseudocoding, and process design

Binary Search Trees. A Generic Tree. Binary Trees. Nodes in a binary search tree ( B-S-T) are of the form. P parent. Key. Satellite data L R

9.4. The Scalar Product. Introduction. Prerequisites. Learning Style. Learning Outcomes

Computational Mathematics with Python

Math 21a Curl and Divergence Spring, Define the operator (pronounced del ) by. = i

Transcription:

OPERATING SYSTEMS DEADLOCKS Jerry Breecher 7: Deadlocks

OPERATING SYSTEM Deadlocks What is a deadlock? What Is In This Chapter? Staying Safe: Preventing and Avoiding Deadlocks Living Dangerously: Let the deadlock happen, then detect it and recover from it. 7: Deadlocks

EXAMPLES: "It takes money to make money". You can't get a job without experience; you can't get experience without a job. BACKGROUND: The cause of deadlocks: Each process needing what another process has. This results from sharing resources such as memory, devices, links. Under normal operation, a resource allocations proceed like this::. Request a resource (suspend until available if necessary ).. Use the resource. 3. Release the resource. 7: Deadlocks 3

Bridge Crossing Example Traffic only in one direction. Each section of a bridge can be viewed as a resource. If a deadlock occurs, it can be resolved if one car backs up (preempt resources and rollback). Several cars may have to be backed up if a deadlock occurs. Starvation is possible. 7: Deadlocks 4

DEADLOCK CHARACTERISATION NECESSARY CONDITIONS ALL of these four must happen simultaneously for a deadlock to occur: Mutual exclusion One or more than one resource must be held by a process in a non-sharable (exclusive) mode. Hold and Wait A process holds a resource while waiting for another resource. No Preemption There is only voluntary release of a resource - nobody else can make a process give up a resource. Circular Wait Process A waits for Process B waits for Process C... waits for Process A. 7: Deadlocks 5

RESOURCE ALLOCATION GRAPH A visual ( mathematical ) way to determine if a deadlock has, or may occur. G = ( V, E ) The graph contains nodes and edges. V Nodes consist of processes = { P, P, P3,...} and resource types { R, R,...} E Edges are ( Pi, Rj ) or ( Ri, Pj ) An arrow from the process to resource indicates the process is requesting the resource. An arrow from resource to process shows an instance of the resource has been allocated to the process. Process is a circle, resource type is square; dots represent number of instances of resource in type. Request points to square, assignment comes from dot. P i P i P i 7: Deadlocks R j R j 6

RESOURCE ALLOCATION GRAPH If the graph contains no cycles, then no process is deadlocked. If there is a cycle, then: a) If resource types have multiple instances, then deadlock MAY exist. b) If each resource type has instance, then deadlock has occurred. R3 Assigned to P3 Resource allocation graph P Requests P3 7: Deadlocks 7

RESOURCE ALLOCATION GRAPH Resource allocation graph with a deadlock. Resource allocation graph with a cycle but no deadlock. 7: Deadlocks 8

Strategy HOW TO HANDLE DEADLOCKS GENERAL STRATEGIES There are three methods: Ignore Deadlocks: Most Operating systems do this!! Ensure deadlock never occurs using either Prevention Avoidance Prevent any one of the 4 conditions from happening. Allow all deadlock conditions, but calculate cycles about to happen and stop dangerous operations.. Allow deadlock to happen. This requires using both: Detection Recovery Know a deadlock has occurred. Regain the resources. 7: Deadlocks 9

Deadlock Prevention Do not allow one of the four conditions to occur. Mutual exclusion: a) Automatically holds for printers and other non-sharables. b) Shared entities (read only files) don't need mutual exclusion (and aren t susceptible to deadlock.) c) Prevention not possible, since some devices are intrinsically non-sharable. Hold and wait: a) Collect all resources before execution. b) A particular resource can only be requested when no others are being held. A sequence of resources is always collected beginning with the same one. c) Utilization is low, starvation possible. 7: Deadlocks

Deadlock Prevention Do not allow one of the four conditions to occur. No preemption: a) Release any resource already being held if the process can't get an additional resource. b) Allow preemption - if a needed resource is held by another process, which is also waiting on some resource, steal it. Otherwise wait. Circular wait: a) Number resources and only request in ascending order. b) EACH of these prevention techniques may cause a decrease in utilization and/or resources. For this reason, prevention isn't necessarily the best technique. c) Prevention is generally the easiest to implement. 7: Deadlocks

If we have prior knowledge of how resources will be requested, it's possible to determine if we are entering an "unsafe" state. Possible states are: Deadlock Avoidance Deadlock No forward progress can be made. Unsafe state A state that may allow deadlock. Safe state A state is safe if a sequence of processes exist such that there are enough resources for the first to finish, and as each finishes and releases its resources there are enough for the next to finish. The rule is simple: If a request allocation would cause an unsafe state, do not honor that request. NOTE: All deadlocks are unsafe, but all unsafes are NOT deadlocks. 7: Deadlocks

Deadlock Avoidance NOTE: All deadlocks are unsafe, but all unsafes are NOT deadlocks. UNSAFE DEADLOCK SAFE Only with luck will processes avoid deadlock. O.S. can avoid deadlock. 7: Deadlocks 3

Deadlock Avoidance Let's assume a very simple model: each process declares its maximum needs. In this case, algorithms exist that will ensure that no unsafe state is reached. EXAMPLE: There exists a total of tape drives. The current state looks like this: Process There are multiple instances of the resource in these examples. Max Needs Allocated Current Needs In this example, < p, p, p > is a workable sequence. P P 4 5 5 Suppose p requests and is given one more tape drive. What happens then? P 9 7 7: Deadlocks 4

Deadlock Avoidance A method used to determine if a particular state is safe. It's safe if there exists a sequence of processes such that for all the processes, there s a way to avoid deadlock: The algorithm uses these variables: Safety Algorithm Need[I] the remaining resource needs of each process. Work - Temporary variable how many of the resource are currently available. Finish[I] flag for each process showing we ve analyzed that process or not. need <= available + allocated[] +.. + allocated[i-] <- Sign of success Let work and finish be vectors of length m and n respectively. 7: Deadlocks 5

Safety Algorithm Deadlock Avoidance. Initialize work = available Initialize finish[i] = false, for i =,,3,..n. Find an i such that: finish[i] == false and need[i] <= work If no such i exists, go to step 4. 3. work = work + allocation[i] finish[i] = true goto step 4. if finish[i] == true for all i, then the system is in a safe state. 7: Deadlocks 6

Safety Algorithm Deadlock Avoidance Do these examples: Consider a system with: five processes, P P4, three resource types, A, B, C. Type A has instances, B has 5 instances, C has 7 instances. At time T the following snapshot of the system is taken. Max Needs = allocated + can-be-requested Alloc Req Avail Is the system in a safe state? P A B C A 7 B 4 C 3 A 3 B 3 C P P 3 6 P3 P4 4 3 7: Deadlocks 7

Safety Algorithm Deadlock Avoidance Do these examples: Now try it again with only a slight change in the request by P. P requests one additional resource of type A, and two more of type C. Request = (,,). Is Request < available? Produce the state chart as if the request is Granted and see if it s safe. (We ve drawn the chart as if it s granted. P P P A 3# 3 Alloc B C # A 7 6 Req B 4 C 3 A # Avail B 3 C # P3 Can the request be granted? P4 4 3 7: Deadlocks 8

Need an algorithm that determines if deadlock occurred. Also need a means of recovering from that deadlock. Deadlock Detection SINGLE INSTANCE OF A RESOURCE TYPE Wait-for graph == remove the resources from the usual graph and collapse edges. An edge from p(j) to p(i) implies that p(j) is waiting for p(i) to release. 7: Deadlocks 9

Deadlock Detection SEVERAL INSTANCES OF A RESOURCE TYPE Complexity is of order m * n * n. We need to keep track of: available - records how many resources of each type are available. allocation - number of resources of type m allocated to process n. request - number of resources of type m requested by process n. Let work and finish be vectors of length m and n respectively. 7: Deadlocks

Deadlock Detection. Initialize work[] = available[] For i =,,...n, if allocation[i]!= then finish[i] = false; otherwise, finish[i] = true;. Find an i such that: finish[i] == false and request[i] <= work If no such i exists, go to step 4. 3. work = work + allocation[i] finish[i] = true goto step 4. if finish[i] == false for some i, then the system is in deadlock state. IF finish[i] == false, then process p[i] is deadlocked. 7: Deadlocks

Deadlock Detection EXAMPLE We have three resources, A, B, and C. A has 7 instances, B has instances, and C has 6 instances. At this time, the allocation, etc. looks like this: Is there a sequence that will allow deadlock to be avoided? P A Alloc B C A Req B C A Avail B C Is there more than one sequence that will work? P P P3 3 3 P4 7: Deadlocks

Deadlock Detection EXAMPLE Suppose the Request matrix is changed like this. In other words, the maximum amounts to be allocated are initially declared so that this request matrix results. Is there now a sequence that will allow deadlock to be avoided? P A Alloc B C A Req B C A Avail B C USAGE OF THIS DETECTION ALGORITHM P P 3 3 # Frequency of check depends on how often a deadlock occurs and how many processes will be affected. P3 P4 7: Deadlocks 3

Deadlock Recovery So, the deadlock has occurred. Now, how do we get the resources back and gain forward progress? PROCESS TERMINATION: Could delete all the processes in the deadlock -- this is expensive. Delete one at a time until deadlock is broken ( time consuming ). Select who to terminate based on priority, time executed, time to completion, needs for completion, or depth of rollback In general, it's easier to preempt the resource, than to terminate the process. RESOURCE PREEMPTION: Select a victim - which process and which resource to preempt. Rollback to previously defined "safe" state. Prevent one process from always being the one preempted ( starvation ). 7: Deadlocks 4

Deadlock Recovery COMBINED APPROACH TO DEADLOCK HANDLING: Type of resource may dictate best deadlock handling. Look at ease of implementation, and effect on performance. In other words, there is no one best technique. Cases include: Preemption for memory, Preallocation for swap space, Avoidance for devices ( can extract Needs from process. ) 7: Deadlocks 5

WRAPUP In this section we have: Looked at necessary conditions for a deadlock to occur. Determined how to prevent, avoid, detect and recover from deadlocks. 7: Deadlocks 6