


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



12 ÿ resource allocation state matrix
Deadlock avoidance Examine each resource request and determine whether or not granting the request can lead to deadlock
Define a set of vectors and matrices that characterize the current state of all resources and processes ÿ maximum claim matrix Maxij = the maximum number of units of resource j that the process i will ever require simultaneously ÿ available vector Allocij = the number of units of resource j held by process i Availj = the number of units of resource j that are unallocated 13
State matrices example ALLOCATION MAX_CLAIM AVAILABLE R 1 R 2 R 3 R 4 0 0 1 2 1 7 5 0 2 3 5 6 0 6 5 2 0 6 5 6
Concept The OS will examine each resource request and determine whether or not granting the request can lead to deadlock ÿ If, after we grant this request, all processes simultaneously make their maximum claim, will the system deadlock? ÿ Can we satisfy the maximum claims of processes in some order? ALLOCATION MAX_CLAIM AVAILABLE R 1 R 2 R 3 R 4 0 0 1 2 1 7 5 0 2 3 5 6 0 6 5 2 0 6 5 6
State definitions A resource allocation state is safe if the system can allocate resources to each process up to its maximum claim such that the system can not deadlock
Term. j The largest request for resources that process Pi can make The resources available to process Pi after processes P 1 through Pi– 1 terminate This ordering of processes is called a safe sequence If a safe sequence exists then there exists a process ( P 1 ) that can execute to completion in the current state, and Pj can execute to completion at worst after processes P 1 - Pj– 1 complete There must be an ordering of the processes P 1 , P 2 , ..., Pn, such that for all processes Pi,
16
Example ALLOCATION MAX_CLAIM AVAILABLE R 1 R 2 R 3 R 4 0 0 1 2 1 7 5 0 2 3 5 6 0 6 5 2 0 6 5 6
MAX_CLAIMPi – ALLOCATIONPi ≤ AVAIL + (^) S j =1 ALLOCATIONPj i –
Does there exist a safe sequence? 17
Safe sequence computation
Safe sequence computation ÿ Does there exist a process Pi such that MAX_REQUESTPi ≤ AVAILABLE? ÿ If no, then there is no safe sequence, the state is unsafe ÿ If yes, add Pi to the sequence ÿ Set AVAILABLE = AVAILABLE + ALLOCATIONPi
Safe sequence computation What if P 2 wants to change its allocation to < 0 , 4 , 2 , 0 >? ÿ Is the resulting allocation state safe?
Recovering from deadlock Abort all deadlocked processes & reclaim their resources Abort one process at a time until all cycles in the RAG are eliminated Where to start? ÿ Select low priority process ÿ Processes with most allocation of resources Caveat: ensure that system is in consistent state (e.g., transactions) Optimization: ÿ Checkpoint processes periodically; rollback processes to checkpointed state