Resource Sharing & Management

Similar documents
Module 6: Resource Sharing and Management

CISC 7310X. C10: Deadlocks. Hui Chen Department of Computer & Information Science CUNY Brooklyn College. 4/12/2018 CUNY Brooklyn College

Operating Systems. Lecture3.2 - Deadlock Management. Golestan University. Hossein Momeni

MODERN OPERATING SYSTEMS. Third Edition ANDREW S. TANENBAUM. Chapter 6 Deadlocks

Chapters 5 and 6 Concurrency

Resources. Lecture 4. Deadlocks. Resources (2) Resources (1) Four Conditions for Deadlock. Introduction to Deadlocks

Chapter 3. Deadlocks

Deadlocks. Today. Next Time. ! Resources & deadlocks! Dealing with deadlocks! Other issues. ! Memory management

General Objectives: To understand the process management in operating system. Specific Objectives: At the end of the unit you should be able to:

Deadlocks. Today. Next Time. Resources & deadlocks Dealing with deadlocks Other issues. I/O and file systems

Operating Systems. Deadlock. User OS. Kernel & Device Drivers. Interface Programs. Brian Mitchell - Operating Systems

OPERATING SYSTEMS. Deadlocks

Introduction to OS. Deadlock. MOS Ch. 6. Mahmoud El-Gayyar. Mahmoud El-Gayyar / Introduction to OS 1

Deadlocks. Prepared By: Kaushik Vaghani

UNIT:2. Process Management

Deadlocks. Dr. Yingwu Zhu

! What is a deadlock? ! What causes a deadlock? ! How do you deal with (potential) deadlocks? Maria Hybinette, UGA

Deadlock. Chapter Objectives

Introduction to Deadlocks

Concurrency: Deadlock and Starvation

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

Deadlocks. Deadlock in Resource Sharing Environment. CIT 595 Spring Recap Example. Representing Deadlock

MODERN OPERATING SYSTEMS. Third Edition ANDREW S. TANENBAUM. Chapter 6 Deadlocks

CSE 306/506 Operating Systems Deadlock. YoungMin Kwon

Chapter 6. Deadlocks

Chapter 3: Deadlocks

Chapter 3. Deadlocks

The Deadlock Problem

DEADLOCKS M O D E R N O P E R A T I N G S Y S T E M S C H A P T E R 6 S P R I N G

SYNCHRONIZATION M O D E R N O P E R A T I N G S Y S T E M S R E A D 2. 3 E X C E P T A N D S P R I N G 2018

CSE 380 Computer Operating Systems

University of Babylon / College of Information Technology / Network Department. Operating System / Dr. Mahdi S. Almhanna & Dr. Rafah M.

!! What is a deadlock? !! What causes a deadlock? !! How do you deal with (potential) deadlocks? Maria Hybinette, UGA

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.

Deadlocks Prof. James L. Frankel Harvard University. Version of 7:05 PM 7-Mar-2017 Copyright 2017, 2015 James L. Frankel. All rights reserved.

More on Synchronization and Deadlock

PESIT Bangalore South Campus

IT 540 Operating Systems ECE519 Advanced Operating Systems

Deadlocks. Thomas Plagemann. With slides from C. Griwodz, K. Li, A. Tanenbaum and M. van Steen

Deadlock. A Bit More on Synchronization. The Deadlock Problem. Deadlock Characterization. Operating Systems 2/7/2005. CSC 256/456 - Spring

Process-1 requests the tape unit, waits. In this chapter, we shall analyze deadlocks with the following assumptions:

ECE519 Advanced Operating Systems

Last Class: Deadlocks. Today

OPERATING SYSTEMS. Prescribed Text Book. Operating System Principles, Seventh Edition. Abraham Silberschatz, Peter Baer Galvin and Greg Gagne

Operating Systems ECE344. Ding Yuan

Learning Outcomes. Chapter 3. Deadlocks. Resources. Resources. Resources

Deadlock and Starvation

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

Learning Outcomes. Chapter 6. Deadlocks. Resources. Resources & Deadlocks. Resource Access. Two example resource usage patterns

VI. Deadlocks. What is a Deadlock? Intended Schedule. Deadlock Problem (1) ???

VI. Deadlocks Operating Systems Prof. Dr. Marc H. Scholl DBIS U KN Summer Term

Basic concepts and Terminologies

Deadlocks. Tore Larsen. With slides from T. Plagemann, C. Griwodz, K. Li, A. Tanenbaum and M. van Steen

Deadlock. Concurrency: Deadlock and Starvation. Reusable Resources

Concurrency problems. To do. q Non-deadlock bugs q Resources & deadlocks q Dealing with deadlocks q Other issues q Next Time: I/O and file systems

Chapter 6 Concurrency: Deadlock and Starvation

Operating Systems. Deadlock. Lecturer: William Fornaciari Politecnico di Milano Homel.deib.polimi.

Resource Management and Deadlocks 1

Resources. Chapter 3. Deadlocks. Resources. Resources

CS153: Midterm (Fall 16)

Chapter 6 - Deadlocks

Administrivia. Assignments 0 & 1 Class contact for the next two weeks Next week. Following week

Interprocess Communication By: Kaushik Vaghani

Module 1. Introduction:

Resource management. Real-Time Systems. Resource management. Resource management

Fig Bridge crossing - deadlock

Operating Systems: Quiz2 December 15, Class: No. Name:

Dr. D. M. Akbar Hussain DE5 Department of Electronic Systems

CSE Opera+ng System Principles

The Deadlock Problem. A set of blocked processes each holding a resource and waiting to acquire a resource held by another process in the set.

Resource Management and Deadlocks 43

Input Output (IO) Management

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

COMPUTER SCIENCE 4500 OPERATING SYSTEMS

Concurrency Issues. Past lectures: What about coordinated access across multiple objects? Today s lecture:

Concurrent Processes Rab Nawaz Jadoon

CS 571 Operating Systems. Midterm Review. Angelos Stavrou, George Mason University

(b) External fragmentation can happen in a virtual memory paging system.

Deadlock. Disclaimer: some slides are adopted from Dr. Kulkarni s and book authors slides with permission 1

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

CSL373: Lecture 5 Deadlocks (no process runnable) + Scheduling (> 1 process runnable)

Operating Systems. Deadlocks. Stephan Sigg. November 30, Distributed and Ubiquitous Systems Technische Universität Braunschweig

CS450/550 Operating Systems

Deadlocks. Operating Systems. Resources. Deadlocks

Outlook. Deadlock Characterization Deadlock Prevention Deadlock Avoidance

DUH! Deadlocks. Concurrency Issues. The TENEX Case. If a process requests all systems buffers, operator console tries to print an error message

PROCESS SYNCHRONIZATION

Chapter 7: Deadlocks

Process Synchronisation (contd.) Deadlock. Operating Systems. Spring CS5212

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

Deadlocks. System Model

Shared and Preemptable Resources. A few resources may be sharable. Anyone can write the system log.

Operating Systems: William Stallings. Starvation. Patricia Roy Manatee Community College, Venice, FL 2008, Prentice Hall

Operating Systems Structure

2. The system of... generally ran one job at a time. These were called single stream batch processing.

Principles of Operating Systems

System Model. Types of resources Reusable Resources Consumable Resources

UNIT-3 DEADLOCKS DEADLOCKS

Chapter 5 Concurrency: Mutual Exclusion and Synchronization

Concurrency: Deadlock and Starvation. Chapter 6

Transcription:

Resource Sharing & Management P.C.P Bhatt P.C.P Bhatt OS/M6/V1/2004 1

Introduction Some of the resources connected to a computer system (image processing resource) may be expensive. These resources may be shared among users or processes. P.C.P Bhatt OS/M6/V1/2004 2

Dead-Lock Prevention We have multiple resources and processes that can request multiple copies of each resource. It is difficult modeling this as a graph. We use the matrix method to model this scenario. P.C.P Bhatt OS/M6/V1/2004 3

Assume n processes and m kinds of resources. We denote the i th resource with r i. We define 2 vectors each of size m, Vector R = (r 1, r 2,., r m ) Vector A = (a 1, a 2,, a m ) where a i is the resource of type i available for allocation. We define 2 matrices for allocations made (AM) and the requests pending for resources (RM). P.C.P Bhatt OS/M6/V1/2004 4

Matrix model of Requests and Allocation P.C.P Bhatt OS/M6/V1/2004 5

Clearly, we must have n [Σ c i,j + a j ] <= r j i=1 n [Σ q i,j ] >= r j i=1 P.C.P Bhatt OS/M6/V1/2004 6

Bankers Algorithm This is a deadlock prevention algorithm based on resource denial if there is a suspected risk of a deadlock. A request of a process is assessed if the process resources can be met from the available resources RMi,j <= ai for all j. Once the process is run, it shall return all the resources it held. P.C.P Bhatt OS/M6/V1/2004 7

Note that Banker s Algorithm makes sure that only processes that will run to completion are scheduled to run. However, if there are deadlocked processes, the will remain deadlocked. Banker s Algorithm does not eliminate a deadlock. P.C.P Bhatt OS/M6/V1/2004 8

Banker s Algorithm makes some unrealistic assumptions resource requirements for processes is known in advance. The algorithm requires that there is no specific order in which the processes should be run. It assumes that there is a fixed number of resources available on the system. P.C.P Bhatt OS/M6/V1/2004 9

A Graph Based Detection Algorithm In the digraph model with one resource of one kind, we are required to detect a directed cycle in a processor resource digraph. For each process, use the process node as root and traverse the digraph in depth first mode marking the nodes. If a marked node is revisited, deadlock exists. P.C.P Bhatt OS/M6/V1/2004 10

Consider a process P i and its corresponding row in matrix RM. If vector RM <= A then every resource request of process P i can be met from the available set of resources. On completion, this process can return its current allocation in row AM i for another process. P.C.P Bhatt OS/M6/V1/2004 11

Deadlock detection algorithm is in the following steps : Step 0 : Assume that all processes are unmarked initially. Step 1: While there are unmarked processes, choose an unmarked process with RMi <= A. process Step 2 else go to Step 3. P.C.P Bhatt OS/M6/V1/2004 12

Step 2 : Add row AM i to A and mark the process. Step 3 : If there is no such process the algorithm terminates. If all processes are marked, no deadlock. If there is a set of processes that remain unmarked, then this set of processes have a deadlock. P.C.P Bhatt OS/M6/V1/2004 13

Note that notwithstanding the non-deterministic nature of the algorithm it always detects a deadlock. The method detects a deadlock if present; it does not eliminate a deadlock. Deadlock elimination may require preemption or release of resources. P.C.P Bhatt OS/M6/V1/2004 14

Mutual Exclusion Revisited : Critical Sections Mutual exclusion is required for memory. Mutual exclusion must be ensured whenever there is a shared area of memory and processes writing to it. The main motivation is to avoid race condition among processes. P.C.P Bhatt OS/M6/V1/2004 15

Critical Section is the section of code that is executed exclusively and without any interruptions none of its operations can be annulled. Unix provides a facility called semaphore to allow processes to use critical sections mutually exclusive of each other. P.C.P Bhatt OS/M6/V1/2004 16

A semaphore is essentially a variable which is treated in a special way. Access and operations on a semaphore is permitted only when it is in a free state. If a process locks a semaphore, others cannot get access to it. P.C.P Bhatt OS/M6/V1/2004 17

When a process enters a critical section, other processes are prevented from accessing this shared variable. A process frees the semaphore on exiting the critical section. To ensure this working, a notion of atomicity or indivisibility is invoked. P.C.P Bhatt OS/M6/V1/2004 18

Basic Properties of Semaphores A semaphore takes only integer values. There are only two operations possible on a semaphore: A wait operation on a semaphore decreases its value by 1. wait(s) : while s < 0 do noop; s := s-1; P.C.P Bhatt OS/M6/V1/2004 19

A signal operation increments its value signal(s) : s := s + 1; A semaphore operation is atomic. A process is blocked if its wait operation evaluates a negative semaphore value. A blocked process can be unblocked when some other process executes a signal operation. P.C.P Bhatt OS/M6/V1/2004 20

Usage of Semaphore Suppose two processes P1 and P2 use a semaphore variable use with initial value 0. We assume both processes have a program structure as: P.C.P Bhatt OS/M6/V1/2004 21

repeat some process code here wait(use); enter the critical section the process manipulates a shared area); signal(use); rest of the process code; until false; P.C.P Bhatt OS/M6/V1/2004 22

We have here an infinite loop for both processes. Either P1 or P2 can be in its critical section. P.C.P Bhatt OS/M6/V1/2004 23

The following is a representative operational sequence. Initially neither process is in critical section and use = 0. P1 arrives at critical section first and calls wait(use). It succeeds and enters the critical section setting use = -1. P2 wants to enter its critical section. Calls wait procedure. P.C.P Bhatt OS/M6/V1/2004 24

As use < 0, P2 busy waits. P1 executes signal and exits its critical section, use = 0 now. P2 exits busy wait loop. It enters critical section use = -1. The above sequence continues. Semaphore is also used to synchronize amongst processes. A process may have a synchronizing event. P.C.P Bhatt OS/M6/V1/2004 25

Suppose we have 2 processes P i and P j, P j can execute some statement s j only after statement s i in P i has been executed. This can be achieved with semaphore s e initialized to - 1 as follows: In P i, execute sequence s j ; signal(s e ); In P j execute wait(s e ); s j ; Now, P j must wait completion of s j before it can execute s j. P.C.P Bhatt OS/M6/V1/2004 26

These resources are not all used all the time. In case of a printer - output resource is used once in a while. This printer must be used amongst multiple users - because the printer is expensive and because it is sparingly used. P.C.P Bhatt OS/M6/V1/2004 27

Resources may be categorized depending upon the nature of their use. OS needs a policy to schedule its use - dependant on nature of use, frequency and context of use. For a printer, OS can spool the data to the printer the printer requests. P.C.P Bhatt OS/M6/V1/2004 28

Each printer job must have exclusive use of it till it finishes. Print-outs would be garbled otherwise. Some times processes may require more than one resource. A process may not be able to proceed till it gets all the resource. P.C.P Bhatt OS/M6/V1/2004 29

Consider a process P1 requiring resources r1 and r2. Consider process P2 requiring resources r2 and r3. P1 will proceed only when it has both r1 and r2. P2 needs both r2 and r3. If P2 has r2, then P1 has to wait until P2 releases r2 or terminates. P.C.P Bhatt OS/M6/V1/2004 30

Mutual Exclusion Mutual Exclusion is required in many situations in the OS design. Consider the context of management of a print request queue. Processes that need to print a file, deposit the file address into this queue. Printer spooler process picks the file address from this queue to print files. P.C.P Bhatt OS/M6/V1/2004 31

P.C.P Bhatt OS/M6/V1/2004 32

Both processes P i and P j think their print jobs are spooled. Q can be considered as a shared memory area between processes P i, P j and P s. Inter Process Communication can be established between processes that need printing and that which does printing. P.C.P Bhatt OS/M6/V1/2004 33

Deadlocks Consider an example in which process P1 needs 3 resources r1, r2 and r3 to make any progress. Similarly, P2 needs resources r2 and r3. Suppose P1 gets r1 and r3; P2 gets r3. P2 is waiting for r2 to be released; P1 is waiting for r3 to be released deadlock. P.C.P Bhatt OS/M6/V1/2004 34

A dead-lock is a condition that may involve two or more processes in a state such that each is waiting for release of a resource currently held by some other process. P.C.P Bhatt OS/M6/V1/2004 35

P.C.P Bhatt OS/M6/V1/2004 36

Formally, a deadlock occurs when the following conditions are present simultaneously Mutual Exclusion Hold and Wait No preemption Circular Wait P.C.P Bhatt OS/M6/V1/2004 37

Dead-lock Avoidance Conditions for dead-lock to occur are mutual exclusion, hold and wait, no preemption and circular wait. The first 3 conditions for dead-lock are necessary conditions. Circular Wait implies Hold and Wait. How does one avoid having a dead-lock?? P.C.P Bhatt OS/M6/V1/2004 38

Infinite Resource Argument One possibility is to have multiple resources of the same kind. Sometimes, we may be able to break a dead-lock by having a few additional copies of a resource. When one copy is taken, there is always another copy of that resource. P.C.P Bhatt OS/M6/V1/2004 39

P.C.P Bhatt OS/M6/V1/2004 40

The pertinent question is, how many copies of each resource do we need?? Unfortunately, theoretically, we need infinite number of resources!!! In the example, if P3 is deadlocked, the deadlock between P1 and P3 cannot be broken. P.C.P Bhatt OS/M6/V1/2004 41

Never let the conditions occur It takes 4 conditions for dead-lock to occur. This dead-lock avoidance simply states do not let conditions occur: Mutual exclusion - unfortunately many resources require many exclusion!! P.C.P Bhatt OS/M6/V1/2004 42

Hold and Wait - since this is implied by Circular Wait, we may possibly avoid Circular Wait. Preemption - may not be the best policy to avoid deadlock but works and is clearly enforceable in many situations. P.C.P Bhatt OS/M6/V1/2004 43

Dead-Lock Prevention We have multiple resources and processes that can request multiple copies of each resource. It is difficult modeling this as a graph. We use the matrix method to model this scenario. P.C.P Bhatt OS/M6/V1/2004 44

Assume n processes and m kinds of resources. We denote the i th resource with r i. We define 2 vectors each of size m, Vector R = (r 1, r 2,., r m ) Vector A = (a 1, a 2,, a m ) where a i is the resource of type i available for allocation. P.C.P Bhatt OS/M6/V1/2004 45

We define 2 matrices for allocations made (AM) and the the requests pending for resources (RM). P.C.P Bhatt OS/M6/V1/2004 46

Bankers Algorithm This is a deadlock prevention algorithm based on resource denial if there is a suspected risk of a deadlock. A request of a process is assessed if the process resources can be met from the available resources RMi,j <= ai for all j. Once the process is run, it shall return all the resources it held. P.C.P Bhatt OS/M6/V1/2004 47

Note that Banker s Algorithm makes sure that only processes that will run to completion are scheduled to run. However, if there are deadlocked processes, the will remain deadlocked. Banker s Algorithm does not eliminate a deadlock. P.C.P Bhatt OS/M6/V1/2004 48