Unformatted text preview: Project #4 Friday, June 5 Homework #5 Credit Distribution Agreement (hardcopy) is due by end of class Review document is due by midnight Solutions are posted Do the Projects Survey Paulson: Responses are posted on the wiki Contribution credit No office hours today Extra hours Monday Today's topics Deadlock Avoidance Review for Final Exam Learning Objectives Evaluation Requires that the system has some a priori information. Deadlock Avoidance Simplest and most useful model requires that each process declare the maximum number of resources of each type that it may need. Resourceallocation state is determined by the number of available and allocated resources, and the maximum demands of the processes. The deadlockavoidance algorithm dynamically examines the resourceallocation state to ensure that there can never be a circularwait condition. Deadlock Avoidance: Safe State When a process requests an available resource, system must decide if immediate allocation leaves the system in a safe state or an unsafe state . System is in a safe state if and only if there exists a safe sequence of all processes. Deadlock Avoidance: Safe State A sequence <Pa1, Pa2, ..., Pan> is safe if for each i in [1 .. n] the resources that Pai needs can be satisfied by currently available resources plus the resources held by all the Paj with j<i. Example: <P4, P2, P3, P1> If P4 can get all its needed resources, and P2 can get all its needed resources after P4 is finished, ... then <P4, P2, P3, P1> is a safe sequence. and P3 can get all its needed resources after P4 and P2 are finished, and P1 can get all its needed resources after P4 and P2 and P3 are finished, Deadlock Avoidance: Safe State If resources needed by Pai are not immediately available, then Pai can wait until all Paj have finished. When a Paj is finished, Pai might obtain resources needed to continue. When all Paj are finished, Pai can obtain needed resources, execute, eventually return allocated resources, and eventually terminate. When Pa1 ... Pai return resources, Pai +1 can Basic Facts If a system is in a safe state, then no deadlocks. If a system is in an unsafe state, then possibility of deadlock. Avoidance means ensuring that a system will never enter an unsafe state. ResourceAllocation Graph Deadlock Avoidance: Claim edge Pi > Rj indicates that process Pi may request resource Rj Claim edge converts to request edge when a process requests a resource. Request edge converts to assignment edge when the request is granted. Assignment edge reverts to a claim edge (or no edge) when a resource is released by a process. Resources must be claimed a priori in the system. represented by a dashed line. ResourceAllocation Graph For Deadlock Avoidance Unsafe State In ResourceAllocation Graph Data Structures for the Banker's Algorithm Let n = number of processes, and m = number of resources types. available: Vector of length m. If available [j] = k, there are k instances of resource type Rj available. max: n x m matrix. If max [i,j] = k, then process Pi may request at most k instances of resource type Rj. allocation: n x m matrix. If allocation[i,j] = k then Pi is currently allocated k instances of Rj. need: n x m matrix. If need[i,j] = k, then Pi may need k more instances of Rj to complete its task. Notation Vector X Y means that every element of X is less than or equal to the corresponding element of Y I.E., for nelement vectors X and Y, X Y X[i] Y[i] for all i in 0, 1, ... n1 5 processes (P0 through P4), 3 resource types: A (10 instances), B (5 instances), C (7 instances). Snapshot at time T0:
P0 P1 P2 P3 P4 Allocation A B C 0 1 0 2 0 0 3 0 2 2 1 1 0 0 2 Max A B C 7 5 3 3 2 2 9 0 2 2 2 2 4 3 3 Available A B C 3 3 2 Need A B C 7 4 3 1 2 2 6 0 0 0 1 1 4 3 1 Example The system is in a safe state since the sequence < P1, P3, P4, P2, P0> satisfies safety criteria. Note there are other safe sequences, but we need only one to prove safety Example: P1 Requests (1,0,2) Can the request be granted immediately? Check that Request1 Available (i.e., (1,0,2) (3,3,2): true ) Sequence <P1, P3, P4, P0, P2> satisfies safety requirement. After P1 Request (1,0,2) is granted
Allocation A B C 0 1 0 3 0 2 3 0 2 2 1 1 0 0 2 Max Available A B C A B C 7 5 3 2 3 0 3 2 2 9 0 2 2 2 2 4 3 3 Need A B C 7 4 3 0 2 0 6 0 0 0 1 1 4 3 1 P0 P1 P2 P3 P4 Can a request for (3,3,0) by P4 now be granted? Can a request for (0,2,0) by P0 now be granted? No. Available < Request4 No, even though Request0 < Available Pretend to grant P0 Request (0,2,0)
P0 P1 P2 P3 P4 Allocation A B C 0 3 0 3 0 2 3 0 2 2 1 1 0 0 2 Max Available A B C A B C 7 5 3 2 1 0 3 2 2 9 0 2 2 2 2 4 3 3 Need A B C 7 2 3 0 2 0 6 0 0 0 1 1 4 3 1 Can the request for (0,2,0) by P0 be granted?
No, even though Request0 < Available Must return to previous state Available < Need[i] for all i Proving safe/unsafe systems To prove a system is safe : Produce one safe sequence To prove a system is unsafe : Must show that NO safe sequence exists Recovery from Deadlock: Process Termination Plan A: Abort all deadlocked processes. Plan B: Abort one process at a time until the deadlock cycle is eliminated. In which order should we choose to abort? Priority of the process. How long process has computed, and how much longer to completion. Resources the process has used. Resources process needs to complete. How many processes will need to be terminated. Is process interactive or batch? Recovery from Deadlock: Resource Preemption Select a victim minimize cost. Rollback return to some safe state, restart process for that state. Starvation is possible: same process may always be picked as victim include number of rollbacks in cost factor. Questions on deadlock? Homework #5 Answer key is posted Review for Final Exam Final Exam information Date: Monday, June 8, 2009 Time: 6:00 7:50 pm Place: KEC1003 Weight: 20% of course grade Bring: Format: several #2 pencils and a good eraser note page (standard size, 2sided) calculator 80% multiplechoice (40 questions) 20% freeresponse / coding Final Exam information Emphasis on topics that were not covered on the midterm: Chapters 8, 9, 12, 13 Lectures 16 30 (including guest lecture) Quiz #2 Homeworks #4, 5 Projects #3, 4 Few questions on Fundamentals Linux kernel coding I/O Devices Block / Character devices Device characteristics Topics covered since midterm Device drivers/controllers Magnetic disks
Logical blocks <cylinder, track, sector> Disk allocation methods Access method, transfer time, etc Freespace management contiguous, linked, indexed Bitmap (vector), linkedlist, etc. Topics covered since midterm I/O Scheduling Goals Scheduling structures Algorithms Calculations FCFS, LOOK, CLOOK, SSTF Reference strings Merging Aging / deadlines Seek/access time Blocking, nonblocking I/O Project #4 Topics covered since midterm File Systems Data, metadata File Control Block, File Information Table File structure File access Sequential, record, complex Attributes, operations, access methods Sequential, direct, indexed Simulation attributes, operations, access methods Directory structure Mounting/mount point Topics covered since midterm Virtual File Systems Goals OS/FS interface Data structures Linux VFS Structures Generic commands, etc. file, dentry, inode, superblock Object orientation Concurrency, Synchronization Topics covered since midterm
Critical section Atomic operations Software solutions Peterson's solution spinlocks, semaphores wait queue busywaiting monitor wait (P), signal (V) condition variable Hardware solutions Classical problems testandset, swap ProducerConsumer (bounded buffer) ReadersWriters, Dining Philosophers Topics covered since midterm
Starvation Deadlock four simultaneous conditions for potential deadlock resource allocation graph prevention/avoidance safe sequence, safe state detection/recovery Banker's Algorithm (structures / intuitive view) Questions? Do Homework #5 Solutions are posted Learning Objectives Evaluation In NAME area, write CS411 Paulson Don't put your name on the scan sheet
Strongly Disagree A B C D Strongly Agree E 1. 2. I have the ability to 1. design, implement, and test operating system related functions within a large and complex open source code base. 2. select appropriately among processes, user threads, or kernel threads to solve a concurrent problem. 3. explain why synchronization is necessary for a concurrent processes scenario, and design synchronization solutions. 4. apply appropriate algorithms to avoid deadlock for given concurrent processes. 3. 4. 5. 6. explain the strengths and weaknesses of several CPU scheduling algorithms with respect to wait time, turnaround time, throughput, and context switching implementation challenges. explain various mechanism for protection of memory, the operating system, and system/user files. map virtual addresses to physical addresses. analyze program data access patterns that may affect the performance of a virtual memory system. explain various disk block allocation / freespace management strategies, and compute access times for various disk scheduling algorithms. participate effectively in a team environment. ...
View Full Document
- Spring '08
- Operating Systems