Deadlock Detection. Several Instances of a Resource Type. Single Instance of Each Resource Type

Similar documents
CS370 Operating Systems

Deadlock. Deadlock. Deadlock. Deadlock 10/7/2014. CS341: Operating System. Deadlock Conditions Mutex, Hold & Wait, No Preemption and Circular wait

When Deadlock Happens

Deadlock Prevention. Restrain the ways request can be made. Mutual Exclusion not required for sharable resources; must hold for nonsharable resources.

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

Chapter 7: Deadlocks

Chapter 7: Deadlocks

The Deadlock Problem

Chapter 7: Deadlocks. Operating System Concepts 8 th Edition,

Chapter 7: Deadlocks

Roadmap. Safe State. Deadlock Avoidance. Basic Facts. Safe, Unsafe, Deadlock State. Tevfik Koşar. CSC Operating Systems Spring 2007

CS307 Operating Systems Deadlocks

Deadlocks. Bridge Crossing Example. The Problem of Deadlock. Deadlock Characterization. Resource-Allocation Graph. System Model

Chapter 7 : 7: Deadlocks Silberschatz, Galvin and Gagne 2009 Operating System Concepts 8th Edition, Chapter 7: Deadlocks

Chapter 8: Deadlocks

Chapter 8: Deadlocks. The Deadlock Problem. System Model. Bridge Crossing Example. Resource-Allocation Graph. Deadlock Characterization

CSE Opera+ng System Principles

Chapter 7: Deadlocks. Chapter 7: Deadlocks. The Deadlock Problem. Chapter Objectives. System Model. Bridge Crossing Example

Chapter 7: Deadlocks. Operating System Concepts with Java 8 th Edition

Module 7: Deadlocks. The Deadlock Problem. Bridge Crossing Example. System Model

CS307: Operating Systems

The Slide does not contain all the information and cannot be treated as a study material for Operating System. Please refer the text book for exams.

CMSC 412. Announcements

Module 7: Deadlocks. The Deadlock Problem

CS370 Operating Systems

Module 7: Deadlocks. System Model. Deadlock Characterization. Methods for Handling Deadlocks. Deadlock Prevention. Deadlock Avoidance

Chapter 8: Deadlocks. The Deadlock Problem

Chapter 7: Deadlocks

Deadlock. Concepts to discuss. A System Model. Deadlock Characterization. Deadlock: Dining-Philosophers Example. Deadlock: Bridge Crossing Example

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

Lecture 7 Deadlocks (chapter 7)

Unit-03 Deadlock and Memory Management Unit-03/Lecture-01

CSC Operating Systems Fall Lecture - XII Deadlocks - III. Tevfik Ko!ar. Louisiana State University. October 6 th, 2009

The Deadlock Problem (1)

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

COS 318: Operating Systems

Chapter 7: Deadlocks. Operating System Concepts 9th Edition DM510-14

Chapter 8: Deadlocks. Operating System Concepts with Java

Deadlocks. Deadlock Overview

Deadlocks. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Chapter 7: Deadlocks. Chapter 7: Deadlocks. System Model. Chapter Objectives

Bridge Crossing Example

Deadlock Risk Management

Operating Systems 2015 Spring by Euiseong Seo DEAD LOCK

Principles of Operating Systems

Silberschatz, Galvin and Gagne 2013! CPU cycles, memory space, I/O devices! " Silberschatz, Galvin and Gagne 2013!

CHAPTER 7: DEADLOCKS. By I-Chen Lin Textbook: Operating System Concepts 9th Ed.

COS 318: Operating Systems. Overview. Andy Bavier Computer Science Department Princeton University

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition! Silberschatz, Galvin and Gagne 2013!

UNIT-5 Q1. What is deadlock problem? Explain the system model of deadlock.

Roadmap. Deadlock Prevention. Deadlock Prevention (Cont.) Deadlock Detection. Exercise. Tevfik Koşar. CSE 421/521 - Operating Systems Fall 2012

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

Chapter 8: Memory Management. Operating System Concepts with Java 8 th Edition

Module 6: Deadlocks. Reading: Chapter 7

Chapter 8: Deadlocks. Bridge Crossing Example. The Deadlock Problem

CS370 Operating Systems

CSE 4/521 Introduction to Operating Systems. Lecture 12 Main Memory I (Background, Swapping) Summer 2018

Contents. Chapter 8 Deadlocks

ICS Principles of Operating Systems. Lectures Set 5- Deadlocks Prof. Nalini Venkatasubramanian

Chapter 8: Memory- Management Strategies. Operating System Concepts 9 th Edition

Chapter 8: Memory- Management Strategies

Principles of Operating Systems

Chapter 8: Deadlocks. The Deadlock Problem

The Deadlock Problem. Chapter 8: Deadlocks. Bridge Crossing Example. System Model. Deadlock Characterization. Resource-Allocation Graph

Operating systems. Lecture 5. Deadlock: System Model. Deadlock: System Model. Process synchronization Deadlocks. Deadlock: System Model

Part II Process M anagement Management Chapter 7: Deadlocks Fall 2010

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

Chapter 7: Deadlocks CS370 Operating Systems

Background. Contiguous Memory Allocation

UNIT-3 DEADLOCKS DEADLOCKS

The Deadlock Problem

CS370 Operating Systems

COP 4610: Introduction to Operating Systems (Spring 2016) Chapter 7 Deadlocks. Zhi Wang Florida State University

(Extract from the slides by Terrance E. Boult

CSC 539: Operating Systems Structure and Design. Spring 2005

Lesson 5: Deadlocks Memory management (Part 1)

Chapter 7: Deadlocks. Operating System Concepts 8 th Edition,

Deadlocks. Minsoo Ryu. Real-Time Computing and Communications Lab. Hanyang University.

Deadlocks. Prepared By: Kaushik Vaghani

Module 3. DEADLOCK AND STARVATION

UNIT:2. Process Management

CSE 2421: Systems I Low-Level Programming and Computer Organization. Linking. Presentation N. Introduction to Linkers

TDDB68 + TDDD82. Lecture: Deadlocks

Chapter 7: Deadlocks. Chapter 7: Deadlocks. Deadlock Example. Chapter Objectives

A software view. Computer Systems. The Compilation system. How it works. 1. Preprocesser. 1. Preprocessor (cpp)

Operating Systems. Designed and Presented by Dr. Ayman Elshenawy Elsefy

Chapter 7: Deadlocks

System Model. Types of resources Reusable Resources Consumable Resources

The Deadlock Problem

CS420: Operating Systems. Deadlocks & Deadlock Prevention

CIT 595 Spring System Software: Programming Tools. Assembly Process Example: First Pass. Assembly Process Example: Second Pass.

Chapter 8: Memory- Management Strategies. Operating System Concepts 9 th Edition

Chapter 8: Deadlocks. The Deadlock Problem

Generating Programs and Linking. Professor Rick Han Department of Computer Science University of Colorado at Boulder

Final Exam Review. CPSC 457, Spring 2016 June 29-30, M. Reza Zakerinasab Department of Computer Science, University of Calgary

System Model. Deadlocks. Deadlocks. For example: Semaphores. Four Conditions for Deadlock. Resource Allocation Graph

What is the Race Condition? And what is its solution? What is a critical section? And what is the critical section problem?

Deadlock Risk Management

Fall 2015 COMP Operating Systems. Lab 06

Outline. G Honors Operating Systems. Deadlock Avoidance. Review: Deadlock Prevention. Lecture 11: Deadlocks Avoidance, Detection, and Recovery

Transcription:

CS341: Operating System Lect26: 08 th Oct 2014 Dr. A. Sahu Dept of Comp. Sc. & Engg. Indian Institute of Technology Guwahati Deadlock Conditions Mutex, Hold & Wait, No Preemption and Circular wait Deadlock Prevention and Avoidance RAG, Cycle Deadlock Detection and Recovery WFG and RAG Main Memory and Memory Management Deadlock Detection Allow system to enter deadlock state Detection algorithm Recovery scheme Single Instance of Each Resource Type Maintain wait for graph Nodes are processes P i P j if P i is waiting forp j PeriodicallysearchesforacycleinWFG a cycle in If there is a cycle, there exists a deadlock Detect a cycle in a graph O(n 2 ) operations, where n=number of vertices Resource Allocation Graph and Wait for Graph R1 R3 R4 P1 R2 P5 P2 P4 P5 P3 P1 P2 R5 P4 P3 Several Instances of a Resource Type Similar to Safety Algorithm of Deadlock Avoidance Available[1:M] : Currently Available Allocation[N:M]: currently allocated Request[N:M]: current request Resource-Allocation Graph Corresponding wait-for graph 1

Deadlock Detection Graphical Approach Resource Allocation Graph Reduction (Erase) If a resource has only arrow away from it No request pending to resource If a process has only arrow pointing towards it All the request granted If a process has arrows pointing away from it but each such request arrow there is an available dot in resource : Erase all the process arrow If a process has only arrow pointing towards it All the request granted If a process has arrows pointing away from it but each such request arrow there is an available dot in resource : Erase all the process arrow If a process has arrows pointing away from it but each such request arrow there is an available dot in resource : Erase all the process arrow If a process has arrows pointing away from it but each such request arrow there is an available dot in resource : Erase all the process arrow 2

Another If a process has arrows pointing away from it but each such request arrow there is an available dot in resource : Erase all the process arrow No Deadlock Another Another Another Another If a resource has only arrow away from it No request pending to resource No further reduction: There must be cycle 3

Several Instances of a Resource Type Similar to Safety Algorithm of Deadlock Avoidance Available[1:M] : Currently Available Allocation[N:M]: currently allocated Request[N:M]: current request Detection Algorithm Let Work[1:M] and Finish[1:M] Work[1:M] = Available[1:M]; Found=true; for(i= 0 ; i< n; i++ ) { if (Allocation i [1:M] 0) Finish[i] = false; else Finish[i] = true; while(found==true){ Find an index isuch that both: Finish[i] == false && Request i [1:M] Work[1:M] If(Found==false) break; Work = Work + Allocation i Finish[i] = true if (Finish[i] == false, for some i, 1 i n) { the system is in deadlock state. //Moreover, if Finish[i] == false, then P i is deadlocked of Detection Algorithm P 0 010 000 0 00 of Detection Algorithm P 0 010 000 010 of Detection Algorithm P 0 010 000 313 of Detection Algorithm P 0 010 000 524 4

of Detection Algorithm P 0 010 000 724 of Detection Algorithm P 0 010 000 726 (Cont.) P 2 requests an additional instance of typec Request A B C P 0 000 P 1 202 P 2 001 P 3 100 P 4 002 State of system? Can reclaim resources held by process P 0, but insufficient resources to fulfill other processes; requests Deadlock exists, consisting of processes P 1, P 2, P 3, and P 4 Detection Algorithm Usage When, and how often, to invoke depends on: How often a deadlock is likely to occur? How many processes will need to be rolled back? one for each disjoint cycle Ifdetectionalgorithmisinvokedarbitrarily is invoked arbitrarily, There may be many cycles in the resource graph And so we would not be able to tell which of the many deadlocked processes caused the deadlock. Recovery from Deadlock: Process Termination Abort all deadlocked processes Abort one process at a time until the deadlock cycle is eliminated Recovery from Deadlock: Process Termination In which order should we choose to abort? 1.Priority of the process 2.How long process has computed, and how much longer to completion 3.Resources the process has used 4.Resources process needs to complete 5.How many processes will need to be terminated 6.Is process interactive or batch? 5

Recovery from Deadlock: Resource Preemption Selecting a victim minimize cost Rollback return to some safe state, restart process for that state Starvation same process may always be picked as victim, include number of rollback in cost factor Process a program in execution; process execution must progress in sequential fashion Multiple parts The program code, also called text section Current activity includingpc, processor registers Stackcontaining temporary data Function parameters, return addresses, local variables Data sectioncontaining global variables Heapcontaining memory dynamically allocated during run time Process to be run.. Program must be brought (from disk) into memory and placed within a process for it to be run CPU can access directly : Main memory and registers Memory unit only sees A stream of addresses + read requests, or address + data and write requests Process to be run.. Register access in one CPU clock (or less) Main memory can take many cycles, causing a stall Cachesits between main memory and CPU registers Protection of memory required to ensure correct operation New Q/Pool I/O or event completion admitted Ready Q/Pool interrupt Scheduler Dispatch Short term Waiting Running Terminated Exit I/O or event wait 6

Protection Issue Long term scheduler may put many process in to Ready at a time Where to put? Howtoaccessthem? them? Is there any efficient way to put and access? How ensure safety and protection? Base and Limit Registers A pair of registersdefine the logical address space baseandlimit CPU must check every memory access generated in user mode to be sure it is between base and limit for that user Base and Limit Registers 0 256000 300040 420940 880000 1024000 Operating System Process Process Process base 300040 120900 limit CPU Hardware Address Protection address Base no yes Trap to OS monitor Addressing Error Base + Limit < no yes M E M O R Y Address Binding Programs on disk, ready to be brought into memory to execute form an input queue Without support, must be loaded into address 0000 Inconvenient to have user process physical address always start at 0000 How can it not be? Address Binding Further, addresses represented in different ways at different stages of a program s life Source code addresses usually symbolic Compiled code addresses bind to relocatable addresses i.e. 14 bytes from beginning of this module Linker or loader will bind relocatableaddresses to absolute addresses i.e. 74014 Each binding maps one address space to another 7

Binding of Instructions and Data to Memory Address binding can happen at three different stages Compile time: If memory location known a priori, absolute codecan be generated; must recompile code if starting location changes Load time: Must generate relocatablecodeif memory location is not known at compile time Execution time: Binding delayed until run time if the process can be moved during its execution from one memory segment to another Need hardware support for address maps (e.g., base and limitregisters) Compile time Load time Multistep Processing of a User Program Source Program (C/C++/ALP) Compiler Or Assembler Object Code Linkage Editor Load Module Loader In Memory Binary Memory Image Other Object Codes System Library Dynamically loaded System library Execution time Program with Absolute Address Red marked are address Dataareavailable are available at absolute address LD R1 10, Call & JMP gototo Absolute Address Call 15and JNZ 3 0 LD R1 10 1 LD R2 11 2 LD R3 12 3 CALL 15 4 CMP R1 R3 5 JNZ 3 6 HLT 7 8 9 10 0 11 5 12 100 13 14 15 ADD R1 R1R2 16 RET Program with Relative Address With reloadable register All address need to be add with RR Let program go relocated to 5000 RelReg1=5000 5000 LD R1 RR+10 5001 LD R2 RR+11 5002 LD R3 RR+12 5003 CALL RR+15 5004 CMP R1 R3 5005 JNZ RR+3 5006 HLT 5007 5008 5009 5010 0 5011 5 5012 100 5013 5014 5015 ADD R1 R1R2 5016 RET Program with Relative Address With reloadable register All address need to be add with RR Call to Shared Lib Shared Lib Register (Assumption) Add at 2000 SR=2000 Let program go relocated to 5000 RelReg1=5000 2000 ADD R1 R1R2 2001 RET.. 5000 LD R1 RR+10 5001 LD R2 RR+11 5002 LD R3 RR+12 5003 CALL SR+15 5004 CMP R1 R3 5005 JNZ RR+3 5006 HLT 5007 5008 5009 5010 0 5011 5 5012100 5013 48 8

//foo.c int foo3x(int x){ return 3*x; //bar.c intmain(){ intx; x=foo3x(10); printf( %d,x); return 0; $ gcc c foo.c $ gcc c bar.c $gccfoo.obar.o obaro $./a.out 49 Compiler in Action $gcc foo.c bar.c o a.out foo.c run compiler preprocessor foo.s run assembler (as) foo.o bar.o linker a.out bar.s bar.c a.out= fully linked executable Combines multiple relocatable object files Produces fully linked executable directly loadable in memory How? Symbol resolution associating one symbol definition with each symbol reference Relocation relocating different sections of input relocatablefiles Types Relocatable: Requires linking to create executable Executable : Loaded directly into memory for execution Shared Objects : Linked dynamically, at run time or load time Collection of concatenated object files stored on disk in a particular format archive An input to Linker Referenced object files copied to executable foo.o bar.o Linker (ld) a.out libm.a libc.a printf.o& fopen.o fully linked executable object file //foo.c int foo3x(int x){ return 3*x; intmain(){//bar.c intx; x=foo3x(10); printf( %d,x); return 0; $ gcc c foo.c $ ar rcs libfoo.a foo.o //it create libfoo.a $ gcc bar.c L. lfoo $./a.out 54 9

Addresses disadvantages of static libraries Ensures one copy of text & data in memory Change in shared library does not require executabletobebuiltagainto be built again Loaded at run time by dynamic linker, at arbitrary memory address, linked with programs in memory On loading, dynamic linker relocates text & data of shared object Linker creates libfoo.so (PIC) from a.oand b.o a.out partially executable depend on libfoo.so Dynamic linker maps shared library into program s address space a.o b.o Partially linked executable dependency on libfoo.so bar.o Linker a.out Loader Linker fpic libfoo.so (position independentshared object) Dynamic linker fully linked executable in memory Creating Dynamic Library //foo.c int foo3x(int x){ return 3*x; intmain(){//bar.c intx; x=foo3x(10); printf( %d,x); return 0; $gcc c fpicfoo.c $gcc shared Wl, soname,libfoo.so.1 o libfoo.so.1 foo.o $ gccbar.c L. lfoo $ export LD_LIBRARY_PATH=. $./a.out CS 346 : Compiler Next Semester 57 Stack automatic(default), local Initialized/uninitialized Data Global, static, extern BSS: Block Started by Symbol BBS: Uninitialized Data Seg. Code: program instructions Heap : malloc, calloc Stack Heap BSS Data Code int A; int B=10; main(){ int Alocal; int *p; p=(int*)malloc(10); Block Started with Symbols: Un initialized Stack Heap BSS Data Code Memory for Process Same amount to all processes Allow only N processes to be in Memory Size of process is limited by MemSize/N Variable amount of memory Allow Allowsomeprocesstobefitinthememoryata in the memory a time Paging& Segmentation: Improve share and reduce fragmentation Virtually : Allow a process to take infinite amount of memory 10