Lecture Operating systems: A concept-based approach (2/e): Chapter 11 - Dhananjay M. Dhamdhere

44 23 0
Lecture Operating systems: A concept-based approach (2/e): Chapter 11 - Dhananjay M. Dhamdhere

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Chapter 11 - Deadlocks. This chapter discusses how deadlocks can arise and how an OS performs deadlock handling to ensure an absence of deadlocks, either through detection and resolution of deadlocks, or through resource allocation policies that perform deadlock prevention or deadlock avoidance.

   PROPRIETARY MATERIAL. ©  2007 The McGraw­Hill Companies, Inc. All rights reserved. No part of this PowerPoint slide  may be displayed, reproduced or distributed  in any form or by any means, without the prior written permission of the publisher, or used beyond the limited distribution to teachers and educators permitted by McGraw­Hill  for their individual course preparation. If you are a student using this PowerPoint slide, you are using it without permission.  Chapter  11: Deadlocks Dhamdhere: Operating Systems— A Concept­Based Approach, 2 ed  Slide No: 1 Copyright © 2008 Deadlocks • A deadlock is a situation in which a set of processes face indefinite waits – A deadlock results in reduction of concurrency and parallelism – Both response times to applications and system performance suffer • Definition – A deadlock involving a set of processes D is a situation in which * Every process Pi in D is blocked on some event ei    * Event ei can be caused only by actions of some process(es) in D Chapter  11: Deadlocks Dhamdhere: Operating Systems— AConceptưBasedApproach,2ed SlideNo:2 Copyrightâ2008 Deadlocks Various kinds of deadlocks can arise in an OS, e.g., – Synchronization deadlocks * Processes wait for one another to perform expected actions – Message communication deadlocks * Processes wait for messages from one another – Resource deadlocks * Processes wait for requested resources to be allocated to them • An OS handles only resource deadlocks, if at all    Chapter  11: Deadlocks Dhamdhere: Operating Systems— A Concept­Based Approach, 2 ed  Slide No: 3 Copyright © 2008 Resource deadlocks • Events related to resource allocation – Resource request * A process requests a resource through a system call * The process is blocked if the resource cannot be allocated to it – Resource allocation to a process * If the process was blocked, its state is changed to ready * The process becomes a holder of the resource * The resource state is changed to ‘allocated’ – Resource release    * A process releases a resource through a system call * The OS allocates the resource to a process blocked for it, if any * Otherwise, it changes the state of the resource to ‘free’ Chapter  11: Deadlocks Dhamdhere: Operating Systems— AConceptưBasedApproach,2ed SlideNo:4 Copyrightâ2008 Conditions for resource deadlock A resource deadlock can arise only if the following conditions hold simultaneously – Non-shareable resources * Processes need exclusive access to resources – Hold-and-wait * A process continues to hold resources allocated to it while it waits for other resources – No preemption    * OS cannot preempt a resource from one process and allocate it to another process – Circular waits * A circular chain of hold-and-wait conditions exists Chapter  11: Deadlocks Dhamdhere: Operating Systems— A Concept­Based Approach, 2 ed  Slide No: 5 Copyright © 2008 The resource allocation state of a system • We use the term resource allocation state of the system, or simply resource state, to indicate – State of each resource in the system – Resource allocations and pending resource requests • A resource class contains resources of the same kind – Each resource in a class is called a resource unit or resource instance – Each resource instance has a state    Chapter  11: Deadlocks Dhamdhere: Operating Systems— A Concept­Based Approach, 2 ed  Slide No: 6 Copyright © 2008 Modeling the resource state • We use two kinds of models of resource state – Graph models * Can be used only if a process requests only one resource of a resource class  Processes and resources are denoted as nodes in the graph  Allocations and pending requests are denoted as edges  – The matrix model    * Does not impose any constraints on resource requests  Resources, allocations and pending requests are represented     in separate matrices Chapter  11: Deadlocks Dhamdhere: Operating Systems— A Concept­Based Approach, 2 ed  Slide No: 7 Copyright © 2008 Wait-for graph (WFG) • A WFG can be used to depict the resource state of a system in which every resource class contains only one resource unit – A Node in the graph is a process – An edge is a wait-for relationship between processes * A wait-for edge (Pi, Pj) indicates that  Process Pj holds the resource unit of a resource class     Process Pi has requested the resource and it has become blocked on it  In essence Pi waits for Pj to release the resource Chapter  11: Deadlocks Dhamdhere: Operating Systems— AConceptưBasedApproach,2ed SlideNo:8 Copyrightâ2008 Resource request and allocation graph (RRAG) Nodes and edges in an RRAG – Two kinds of nodes exist in an RRAG * A circle is a process * A rectangle is a resource class  Each bullet in a rectangle is one resource unit – Edges can also be of two kinds * An edge from a resource class to a process is a resource allocation * An edge from a process to a resource class is a pending resource request    Chapter  11: Deadlocks Dhamdhere: Operating Systems— A Concept­Based Approach, 2 ed  Slide No: 9 Copyrightâ2008 Examples of RRAG and WFG Part(a) R1 contains one resource unit,   which is allocated to P • R2 contains two units, allocated to P2 and P3 • P2, P3 wait for R1, P4 for R2 Chapter  11: Deadlocks Part (b) RRAG (left half of Part (b)) • R1 contains one resource unit, which is allocated to P1 • P2 and P3 have requested R1 • WFG is shown in the right half Dhamdhere: Operating Systems— A Concept­Based Approach, 2 ed  Slide No: 10 Copyright © 2008 Deadlock avoidance by Multi-resource Banker’s algorithm    Chapter  11: Deadlocks Dhamdhere: Operating Systems— A Concept­Based Approach, 2 ed  Slide No: 30 Copyright © 2008 Banker’s algorithm Q: Can P1 or P2 be allocated resources (1, 0) in this resource state?    Chapter  11: Deadlocks Dhamdhere: Operating Systems— A Concept­Based Approach, 2 ed  Slide No: 31 Copyright © 2008 Banker’s algorithm    Qs: Is this state safe? Should P1’s request for (1, 1, 0) resources be granted? Chapter  11: Deadlocks Dhamdhere: Operating Systems— A Concept­Based Approach, 2 ed  SlideNo:32 Copyrightâ2008 Characterization of deadlocks We determine the necessary and sufficient conditions for deadlocks to exist in a system – For this, we classify systems on the basis of the nature of resource classes and resource requests made by processes * Resource classes  Single instance (SI): Resource class has a single resource unit  Multiple instance (MI): Resource class has several resource units    * Resource requests  Single request (SR): Request for unit of class only  Multiple request (MR): Request for unit each of several resource classes Chapter  11: Deadlocks Dhamdhere: Operating Systems— A Concept­Based Approach, 2 ed  Slide No: 33 Copyright © 2008 Classification of systems    • Classification is based on nature of resource classes and resource requests • Four classes of systems exist—SISR, SIMR, MISR and MIMR Chapter  11: Deadlocks Dhamdhere: Operating Systems— A Concept­Based Approach, 2 ed  Slide No: 34 Copyright © 2008 SISR systems • What are the necessary and sufficient conditions for a deadlock in SISR systems? – A cycle in a WFG is both a necessary and a sufficient condition Q: Is a cycle in an RRAG necessary and sufficient? Chapter11:Deadlocks Dhamdhere:OperatingSystems AConceptưBasedApproach,2ed SlideNo:35 Copyrightâ2008 MISR system A cycle in an RRAG is a necessary but not a sufficient condition for a deadlock in an MISR system – See the example involving three processes and a printer and a tape (slides 13 and 14) Q: So, what is a sufficient condition?    Chapter  11: Deadlocks Dhamdhere: Operating Systems— A Concept­Based Approach, 2 ed  Slide No: 36 Copyright © 2008 MISR system • A knot in the RRAG is a necessary and sufficient condition A subgraph G’ = ( N’, E’ ) of graph G = ( N, E ) is a knot if – For every node ni in N’: All out-edges of ni in G are included in G’ – For every path ni nj in G’, a path nj ni also exists in G’    Chapter  11: Deadlocks Dhamdhere: Operating Systems— A Concept­Based Approach, 2 ed  Slide No: 37 Copyright © 2008 A knot in RRAG of an MISR system • The tape class has two instances, hence the tape node has two    out-edges • The notion of knot requires that both out-edges of a tape node are involved in cycles Chapter11:Deadlocks Dhamdhere:OperatingSystems AConceptưBasedApproach,2ed SlideNo:38 Copyrightâ2008 SIMR system Acycleisbothanecessaryandsufficientconditionfora deadlock     Q:  Why?    Chapter  11: Deadlocks Dhamdhere: Operating Systems— A Concept­Based Approach, 2 ed  Slide No: 39 Copyright © 2008 MIMR system • The RRAG must contain a resource knot A subgraph G’ = ( N’, E’ ) of graph G = ( N, E ) is a resource knot if – For every resource node in N’: All out-edges of ni in G are included in G’ – For every path ni nj in G’, a path nj ni also exists in G’    Chapter  11: Deadlocks Dhamdhere: Operating Systems— A Concept­Based Approach, 2 ed  Slide No: 40 Copyright © 2008 RRAG for an MIMR system    Qs: Does a deadlock exist ? (You could complete the out-edge of R3 as you like) Chapter11:Deadlocks Dhamdhere:OperatingSystems AConceptưBasedApproach,2ed SlideNo:41 Copyrightâ2008 Processes in a deadlock How to identify all processes that are in a deadlock? – RRi : Set of resource classes requested by Pi – HSk: Set of processes holding resources of resource class Rk – KS : Set of processes in resource knots – AS : Auxiliary set of process nodes AS = { Pi | RRi contains Rk such that HSk is included    in (KS Ụ AS) } D = KS Ụ AS Chapter  11: Deadlocks Dhamdhere: Operating Systems— A Concept­Based Approach, 2 ed  Slide No: 42 Copyright © 2008 Processes in deadlock    Chapter  11: Deadlocks Q: Form the sets KS, AS and D Dhamdhere:OperatingSystems AConceptưBasedApproach,2ed SlideNo:43 Copyrightâ2008 Deadlock handling in practice To limit overhead, the kernel uses different deadlock handling policies for different resources – Memory: Swapping is used, hence no deadlocks – I/O devices: All deadlock handling policies have weaknesses Hence the kernel creates virtual I/O devices for allocation – Files and messages: Deadlock handling is not implemented – Control blocks in the kernel: Resource ranking can be used    Chapter  11: Deadlocks Dhamdhere: Operating Systems— A Concept­Based Approach, 2 ed  Slide No: 44 Copyright © 2008 ... OS cannot preempt a resource from one process and allocate it to another process – Circular waits * A circular chain of hold-and-wait conditions exists Chapter 11:  Deadlocks Dhamdhere: Operating Systems—... granted? Chapter 11:  Deadlocks Dhamdhere: Operating Systems— A Concept­Based Approach,  2 ed  Slide No: 29 Copyright © 2008 Deadlock avoidance by Multi-resource Banker’s algorithm    Chapter 11:  Deadlocks... – A deadlock may arise in future if it is not the case •    Q: Why? The Banker’s algorithm for deadlock avoidance follows this approach Chapter 11:  Deadlocks Dhamdhere: Operating Systems— A Concept­Based Approach,  2 ed 

Ngày đăng: 30/01/2020, 03:16

Từ khóa liên quan

Mục lục

  • Slide 1

  • Deadlocks

  • Slide 3

  • Resource deadlocks

  • Conditions for resource deadlock

  • The resource allocation state of a system

  • Modeling the resource state

  • Wait-for graph (WFG)

  • Resource request and allocation graph (RRAG)

  • Examples of RRAG and WFG

  • Paths in WFG and RRAG

  • An example of a deadlock

  • Another example

  • RRAG after all requests of the example are made

  • Deadlock handling approaches

  • Deadlock detection

  • Slide 17

  • Algorithm for deadlock detection

  • Deadlock resolution

  • Slide 20

Tài liệu cùng người dùng

Tài liệu liên quan