1 / 18

Resource Management: Chap 9

Learn about resource management and deadlock prevention techniques, including prevention, avoidance, detection, recovery, and the Banker's algorithm.

cthorpe
Download Presentation

Resource Management: Chap 9

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Resource Management: Chap 9 Reusable Disk blocks File descriptors Semaphores Consumable Messages Packets

  2. Reusable Data Structures const int M = 10;/* # of resources*/ typedef unsigned int ResourceVec[M]; ResourceVec available, /* # unallocated */ total; /*maximum possible units*/

  3. Reusable Data Structures const int N = 5; /* # of processes*/ typedef struct { ResourceVec allocation, /*owned*/ request, /*unsatisfied requests*/ maxClaim; /*only for batch */ } PerProcess; /*process*/

  4. Resource State Diagram Process 1 2 3 Resource avail total • 2+(1)+[1] 1 [2] 0 3 • 2 1+[1] 1+(1)+[1] 0 2 • 3 1+(1)[1] 1 0 2 3 RESOURCES 3 PROCESSES Process 1 owns 2 units of R1, has requested 1 more with a remaining claim of 1 unit. There are no R1 units avail.

  5. Deadlock • No Effective Deadlock A request must be granted in finite time even if new requests are accepted. • No Deadlock A request must be granted in finite time assuming that no further requests are accepted.

  6. Effective Deadlock Example Process 1 2 3 Resource avail total 1 1+[1] (2)+[2] 1+[1] 0 2 Processes 1 and 3 overlap requests for 1 unit at a time. Process 2’s request for 2 units is never satisfied.

  7. Necessary Conditions • (1) Processes claim exclusive control. • (2) Processes hold resources while requesting additional resources. • (3) Resources cannot be forcibly removed (preempted) from processes. • (4) A circular chain of processes exist such that each process holds one or more of the resources requested by itspredecessor in the chain. If not, one of the processes would eventually receive a resource that it needed to complete.

  8. Solution Classes • Prevention • Static, works before programs execute • Avoidance • Dynamic, check every request for safety • Detection/Recovery • Check for “stuck” processes at intervals

  9. Prevention • No exclusive control -- share everything • No incremental requests • Collective requests • Release all before requesting more • Allow preemption • Havender’s Ordered Requests • request a resource in class C(i) only if it holds noresources in any class C(j), j>=i. • Dijkstra’s Minimal Progress

  10. Havender Ordered Request Example Class Resource Type 6 Printer 5 Disk 1 4 Tape Drives 1 and 2 3 Disk 2 2 Tape Drives 3 and 4 1 Memory

  11. Avoidance • A request is granted only if it results in a SAFE resource state. • Requires Max Claim information. • A safe execution sequence is an executionschedule of processes (P1, P2, ... , Pn) such that for each P(i), when it begins execution, its maximal claims can besatisfied by the available resources.

  12. A Safe State Process 1 2 3 Resource avail total • 1+[4] 3+(1)+[4] 3+[3] 3 10 Safe Execution Sequences =(P3, P1, P2) (P3, P2, P1)

  13. An Unsafe State Process 1 2 3 Resource avail total • 1+(1)+[4] 4+[3] 3+[3] 2 10 NO Safe Execution Sequence exists!

  14. Banker’s Algorithm • On every request, search for a SES such that • Every process can have its MAXIMUM CLAIM satisfied in at least one execution order • Most Liberal because it gives away all resources if possible at the cost of execution order flexibility

  15. Banker’s Algorithm avail = available; /*copy the current state*/ for (i=0; i<N; i++) canFinish[i]=false; for ( ;; ) { i = 0; allInSES = true; for ( ;; ) { if ( !canFinish[i] ) { /*am I already in SES*/ if (vGeq(avail, i)) { /*no, can I get resources?*/ vAdd(avail, i); /*yes, then I can finish and*/ canFinish[i] = true; /*add resources to "avail"*/ break; /*I am now in the SES*/ } else allInSES = FALSE; /*>=1 is still delayed*/ } /*if*/ if (++i >= N) return allInSES; /*exit with answer*/ } } /*for for*/

  16. Detection and Recovery • For single-unit resources (semaphores/files), a cycle is a necessary and sufficient condition for deadlock.

  17. Detection and Recovery Process 1 2 3 4 Resource available total 1 1+(1) 1 (1) 1 0 3 2 1+(1) 1 0 0 2 A cycle (P1 <-> P2) exists but no deadlock because P4 can terminate and give a resource back.

  18. Recovery Options • Terminate operating system • Terminate all processes in a cycle • Terminate one process in a cycle • Preempt resources

More Related