Frequently asked questions from the previous class survey

Similar documents
CS370: Operating Systems [Spring 2016] Dept. Of Computer Science, Colorado State University

CS370: Operating Systems [Spring 2016] Dept. Of Computer Science, Colorado State University

CS370: Operating Systems [Spring 2017] Dept. Of Computer Science, Colorado State University

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

CS370 Operating Systems

CS370 Operating Systems

More on Synchronization and Deadlock

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

Frequently asked questions from the previous class survey

Frequently asked questions from the previous class survey

Chapter 7: Deadlocks CS370 Operating Systems

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

Fig Bridge crossing - deadlock

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

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

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

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

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

CS370 Operating Systems

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

UNIT-3 DEADLOCKS DEADLOCKS

Chapter 6 - Deadlocks

CSE Opera+ng System Principles

Lecture 7 Deadlocks (chapter 7)

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

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

CS370: Operating Systems [Spring 2017] Dept. Of Computer Science, Colorado State University

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

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

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

Chapter 3. Deadlocks

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

CS370: System Architecture & Software [Fall 2014] Dept. Of Computer Science, Colorado State University

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

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

Frequently asked questions from the previous class survey

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

Last Class: Monitors. Real-world Examples

CS370: Operating Systems [Spring 2017] Dept. Of Computer Science, Colorado State University

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

CS370: System Architecture & Software [Fall 2014] Dept. Of Computer Science, Colorado State University

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

Frequently asked questions from the previous class survey

CS370: System Architecture & Software [Fall 2014] Dept. Of Computer Science, Colorado State University

Chapter 3. Deadlocks

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

CSCC 69H3 2/1/13. Today: Deadlock. Remember example from last week? Example of Deadlock. Example: dining philosophers: Not just an OS Problem!

CS450/550 Operating Systems

Course Description: This course includes the basic concepts of operating system

Deadlocks. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Chapter 3: Deadlocks

CS370: Operating Systems [Spring 2017] Dept. Of Computer Science, Colorado State University

Bridge Crossing Example

Scheduling. The Basics

Chapter 8: Deadlocks. The Deadlock Problem

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.

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

CSE120 Principles of Operating Systems. Prof Yuanyuan (YY) Zhou Deadlock

Comp 204: Computer Systems and Their Implementation. Lecture 9: Deadlock

Chapter 7: Deadlocks

Deadlock. Operating Systems. Autumn CS4023

CS370 Operating Systems

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

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

Chapter 8: Deadlocks. The Deadlock Problem

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

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

Frequently asked questions from the previous class survey

ECS 150 (Operating Systems) Goal To examine what causes deadlock, and what to do about it. Spring Quarter

Chapter 8: Deadlocks. Operating System Concepts with Java

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.

CS370: Operating Systems [Fall 2018] Dept. Of Computer Science, Colorado State University

Operating Systems. Operating Systems Sina Meraji U of T

CS420: Operating Systems. Deadlocks & Deadlock Prevention

Frequently asked questions from the previous class survey

CS370: Operating Systems [Fall 2018] Dept. Of Computer Science, Colorado State University

COMP 3713 Operating Systems Slides Part 3. Jim Diamond CAR 409 Jodrey School of Computer Science Acadia University

The Deadlock Problem

Deadlocks. Operating System Concepts - 7 th Edition, Feb 14, 2005

Frequently asked questions from the previous class survey

The Deadlock Problem (1)

Module 7: Deadlocks. The Deadlock Problem

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

Chapter 7: Deadlocks

CS370 OperaBng Systems

COS 318: Operating Systems. Deadlocks. Jaswinder Pal Singh Computer Science Department Princeton University

Deadlock and Starvation

Deadlock and Starvation

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

Frequently asked questions from the previous class survey

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

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

Principles of Operating Systems

OPERATING SYSTEMS. Deadlocks

Chapter 7: Deadlocks

Module 6: Deadlocks. Reading: Chapter 7

CS555: Distributed Systems [Fall 2017] Dept. Of Computer Science, Colorado State University

The Deadlock Problem

Readings and References. Deadlock. Deadlock. Simple Traffic Gridlock Example. Reading. CSE Computer Systems November 30, 2001.

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

Transcription:

CS 370: OPERATING SYSTEMS [DEADLOCKS] Shrideep Pallickara Computer Science Colorado State University L16.1 Frequently asked questions from the previous class survey Exponential Moving Average Is the α adjusted? How is the first estimate (i.e. τ 0 ) chosen? MFQ Any user-level control over setting the quanta? No Must there be a quanta for every priority level? YES Is the quanta in milliseconds or nanoseconds? MIlliseconds At a given priority level what is the order of processes being scheduled? When does a process get off the MFQ? HLT on x86 halts the CPU until the next external interrupt How does a thread first get assigned to a core? L16.2 SLIDES CREATED BY: SHRIDEEP PALLICKARA L16.1

Topics covered in today s lecture Deadlocks Deadlock characterization Deadlock vs Starvation Resource allocation graph L16.3 A waiting process is never again able to change state It is waiting for resources held by other processes DEADLOCKS L16.4 SLIDES CREATED BY: SHRIDEEP PALLICKARA L16.2

What we will look at Prevention Why? System Model Deadlocks Characterization Avoidance Detection & Recovery Requirements L16.5 For many applications, processes need exclusive accesses to multiple resources Process A: Asks for scanner and is granted it Process B: Asks CD recorder first and is granted it. Process A: Now asks for CD recorder Process B: Now asks for Scanner Both processes are blocked and will remain so forever! Deadlock L16.6 SLIDES CREATED BY: SHRIDEEP PALLICKARA L16.3

Other deadlock situations Distributed systems involving multiple machines Database systems Process 1 locks record R1 Process 2 locks record R2 Then, processes 1 and 2 try to lock each other s record n Deadlock Deadlocks can occur in hardware or software resources L16.7 Resource Deadlocks Major class of deadlocks involves resources Can occur when processes have been granted access to devices, data records, files, etc. Other classes of deadlocks: communication deadlocks, two-phase locking Related concepts Livelocks and starvation L16.8 SLIDES CREATED BY: SHRIDEEP PALLICKARA L16.4

Preemptable resources Can be taken away from process owning it with no ill effects Example: Memory Process B s memory can be taken away and given to process A n Swap B from memory, write contents to backing store, swap A in and let it use the memory L16.9 Non-preemptable resources Cannot be taken away from a process without causing the process to fail If a process has started to burn a CD Taking the CD-recorder away from it and giving it to another process? n Garbled CD n CD recorders are not preemptable at an arbitrary moment In general, deadlocks involve non-preemptable resources L16.10 SLIDES CREATED BY: SHRIDEEP PALLICKARA L16.5

Some notes on deadlocks The OS typically does not provide deadlock prevention facilities Programmers are responsible for designing deadlock free programs L16.11 System model Finite number of resources Distributed among competing processes Resources are partitioned into different types Each type has a number of identical instances Resource type examples: n Memory space, files, I/O devices L16.12 SLIDES CREATED BY: SHRIDEEP PALLICKARA L16.6

A process must utilize resources in a sequence Request Requesting resource must wait until it can acquire resource request(), open(), allocate() Use Operate on the resource Release release(), close(), free() L16.13 For kernel managed resources, the OS maintains a system resource table Is the resource free? Record process that the resource is allocated to Is the resource allocated? Add to queue of processes waiting for resource For resources not managed by the OS Use wait() and signal() on semaphores L16.14 SLIDES CREATED BY: SHRIDEEP PALLICKARA L16.7

Deadlock: Formal Definition A set of processes is deadlocked if each process in the set is waiting for an event that only another process in the set can cause. Because all processes are waiting, none of them can cause events to wake any other member of the set Processes continue to wait forever L16.15 DEADLOCK CHARACTERIZATION L16.16 SLIDES CREATED BY: SHRIDEEP PALLICKARA L16.8

Deadlocks: Necessary Conditions (I) Mutual Exclusion At least one resource held in nonsharable mode When a resource is being used n Another requesting process must wait for its release Hold-and-wait A process must hold one resource Wait to acquire additional resources n Which are currently held by other processes L16.17 Deadlocks: Necessary Conditions (II) No preemption Resources cannot be preempted Only voluntary release by process holding it Circular wait A set of {P 0, P 1,, P n } waiting processes must exist n P 0 à P 1 ; P 1 à P 2,, P n à P 0 Implies hold-and-wait L16.18 SLIDES CREATED BY: SHRIDEEP PALLICKARA L16.9

DEADLOCKS VS. STARVATION L16.19 Deadlocks vs. Starvation Deadlocks and starvation are both liveness concerns Starvation Task fails to make progress for an indefinite period of time Deadlock is a form of starvation, BUT with a stronger condition A group of tasks forms a cycle where none of the tasks makes progress because each task is waiting for some other task in the cycle to take action L16.20 SLIDES CREATED BY: SHRIDEEP PALLICKARA L16.10

Deadlocks vs. Starvation Deadlock implies starvation (literally for the dining philosophers problem) Starvation DOES NOT imply deadlock L16.21 Also Just because a system can suffer deadlock or starvation does not mean that it always will A system is subject to starvation if a task could starve in some circumstances A system is subject to deadlock if a group of tasks could deadlock in some circumstances Circumstances impact whether a deadlock or starvation may occur Choices made by scheduler, number of tasks, workload or sequence of requests, which tasks win races to acquire locks, order of task activations, etc. L16.22 SLIDES CREATED BY: SHRIDEEP PALLICKARA L16.11

RESOURCE ALLOCATION GRAPH L16.23 Resource allocation graph Used to describe deadlocks precisely Consists of a set of vertices and edges Two different sets of nodes P: the set of all active processes in system R: the set of all resource types in the system L16.24 SLIDES CREATED BY: SHRIDEEP PALLICKARA L16.12

Directed edges Request edge P i has requested an instance of resource type R j Directed edge from process P i to resource R j Denoted P i à R j Currently waiting for that resource Assignment edge Instance of resource R j assigned to process P i Directed edge from resource R j to process P i Denoted R j à P i L16.25 Representation of Processes and Resources Processes Resources A resource type may have multiple instances L16.26 SLIDES CREATED BY: SHRIDEEP PALLICKARA L16.13

Resource Allocation Graph example R 1 R 3 P 1 P 2 P 3 R 2 R 4 Request Edge Assignment Edge L16.27 Determining deadlocks If the graph contains no cycles? No process in the system is deadlocked If there is a cycle in the graph? If each resource type has exactly one instance n Deadlock has occurred If each resource type has multiple instances n A deadlock may have occurred L16.28 SLIDES CREATED BY: SHRIDEEP PALLICKARA L16.14

Resource Allocation Graph: Deadlock example R 1 R 3 Two cycles P 1 àr 1 àp 2 àr 3 àp 3 àr 2 àp 1 P 2 àr 3 àp 3 àr 2 àp 2 P 1 P 2 P 3 R 2 R 4 L16.29 Resource Allocation Graph: Cycle but not a deadlock R 1 P 2 P 1 àr 1 àp 3 àr 2 àp 1 P 1 P 3 R 2 P 4 P 4 may release instance of R 2 allocate to P 3 and break cycle L16.30 SLIDES CREATED BY: SHRIDEEP PALLICKARA L16.15

Resource Allocation Graphs and Deadlocks If the graph does not have a cycle No deadlock If the graph does have a cycle System may or may not be deadlocked L16.31 Methods for handling deadlocks Use protocol to prevent or avoid deadlocks Ensure system never enters a deadlocked state Allow system to enter deadlocked state; BUT Detect it and recover Ignore problem, pretend that deadlocks never occur L16.32 SLIDES CREATED BY: SHRIDEEP PALLICKARA L16.16

Problems with undetected deadlocks Resources held by processes that cannot run More and more processes enter deadlocked state When they request more resources Deterioration in system performance Requires restart L16.33 When is ignoring the problem viable? When they occur infrequently (once per year) Ignoring is the cheaper solution Prevention, avoidance, detection and recovery n Need to run constantly L16.34 SLIDES CREATED BY: SHRIDEEP PALLICKARA L16.17

SOME DEADLOCK EXAMPLES L16.35 Law passed by Kansas Legislature early 20 th Century When two trains approach each other at a crossing, both shall come to a full stop and neither shall start up again until the other has gone L16.36 SLIDES CREATED BY: SHRIDEEP PALLICKARA L16.18

Dining philosophers problem: Necessary conditions for deadlock (1) Mutual exclusion 2 philosophers cannot share the same chopstick Hold-and-wait A philosopher picks up one chopstick at a time Will not let go of the first while it waits for the second one L16.37 Dining philosophers problem: Necessary conditions for deadlock (2) No preemption A philosopher does not snatch chopsticks held by some other philosopher Circular wait Could happen if each philosopher picks chopstick with the same hand first L16.38 SLIDES CREATED BY: SHRIDEEP PALLICKARA L16.19

Is there a traffic deadlock here? T T C C T C C C C T C C C C L16.39 The traffic scenario: Necessary Conditions (1) Mutual Exclusion A vehicle needs its own space We can t stack automobiles on top of each other Hold-and-wait A vehicle does not move and stays in place if it cannot advance L16.40 SLIDES CREATED BY: SHRIDEEP PALLICKARA L16.20

The traffic scenario: Necessary Conditions (2) No preemption We cannot move an automobile to the side Circular-wait Each vehicle is waiting for the one in front of it to advance L16.41 DEALING WITH DEADLOCKS L16.42 SLIDES CREATED BY: SHRIDEEP PALLICKARA L16.21

Four strategies for dealing with deadlocks Ignore the problem May be if you ignore it, it will ignore you Detection and Recovery Let deadlocks occur, detect them, and take action Deadlock avoidance By careful resource allocation Deadlock prevention By structurally negating one of the four required conditions L16.43 THE OSTRICH ALGORITHM L16.44 SLIDES CREATED BY: SHRIDEEP PALLICKARA L16.22

Ostrich Algorithm Stick your head in the sand; pretend there is no problem at all Reactions Mathematician: Unacceptable; prevent at all costs Engineers: How often? Costs? Etc. L16.45 OS suffer from deadlocks that are not even detected [1/3] Number of processes in the system Total determined by slots in the process table n Slots are a finite resource Maximum number of open files Restricted by size of the inode table Swap space on the disk L16.46 SLIDES CREATED BY: SHRIDEEP PALLICKARA L16.23

OS suffer from deadlocks that are not even detected [2/3] Every OS table represents a finite resource Should we abolish all of these because collection of n processes 1 2 Might claim 1/n th of the total AND Then try to claim another one Most users prefer occasional deadlock to a restrictive policy E.g. All users: 1 process, 1 open file. one everything is far too restrictive L16.47 OS suffer from deadlocks that are not even detected [3/3] If deadlock elimination is free No discussions But the price is often high Inconvenient restrictions on processes Tradeoff Between convenience and correctness L16.48 SLIDES CREATED BY: SHRIDEEP PALLICKARA L16.24

The contents of this slide-set are based on the following references Avi Silberschatz, Peter Galvin, Greg Gagne. Operating Systems Concepts, 9 th edition. John Wiley & Sons, Inc. ISBN-13: 978-1118063330. [Chapter 5, 7] Andrew S Tanenbaum. Modern Operating Systems. 4 th Edition, 2014. Prentice Hall. ISBN: 013359162X/ 978-0133591620. [Chapter 7] Thomas Anderson and Michael Dahlin. Operating Systems Principles and Practice. 2 nd Edition. ISBN: 978-0985673529. [Chapter 6] L16.49 SLIDES CREATED BY: SHRIDEEP PALLICKARA L16.25