INTRODUCTION
TO
OPERATING SYSTEMS
Lecture 7: RESOURCE ALLOCATION (2)
CHRIS STAFF
Dept. of Computer Science and Artificial Intelligence
University of Malta
Lecture Outline
Aims and Objectives
Preventing Deadlock (by denying one of the conditions)
Deadlock Detection
Recovering from Deadlock
Deadlock Avoidance
Aims and Objectives
- Handling Deadlock
- Prevention
- Detection
- Recovery
- Avoidance
Preventing Deadlock (by denying one of the conditions)
- Denying Mutual Exclusion
Not desirable to deny - we want dedicated resources
- Denying Hold-And-Wait
Force processes to request and gain all their resources in one go.
Disadvantages are other processes are made to wait.
A resource which will not be used until the end of a process still has to be
requested at the beginning - poor resource utilisation
- Denying No Pre-emption
Some non-shareable resources can be pre-empted if the hardware/software saves
the context of the interrupted process - but what about printers?
Only partial denial of no pre-emption is possible.
- Denying Circular Waiting
Resources are grouped into `Frequency of Use' classes, C1, C2, C3, etc.
All required resources belonging to the same class are requested at the same
time in class order
No circular wait because either all required resources one class are held, or
process waits until all required resources within a class are available.
Disadvantages are that resources must be requested in an artifical order -
not necessarily the order in which they will be used.
Deadlock Detection
- Do not prevent deadlock from occurring. Periodically look for deadlock. If
found then recover.
- Only one of the conditions implies deadlock.
Representing Circular Wait.
- `State Graph' used to show which processes hold resources and which processes
have requested resources.
- Try to reduce the state graph by removing links for allocations and requests
in turn for each process.
- If at least one link cannot be removed, then deadlock
When to update state graph
- Every time there is an allocation or release? Time consuming.
- Update state graph periodically by examining state
Recovering from Deadlock
- Problem determining which processes are deadlocked.
- Four Main Methods of Deadlock Recovery
Abort all deadlocked processes
Restart all deadlocked processes from a checkpoint
Abort processes one at a time
Pre-empt resources from processes
- Deadlock Recovery usually performed by operator
Deadlock Avoidance
- Tries to anticipate deadlock
- Will deny resource requests if algorithm decides that granting the request
could lead to deadlock.
- Because of nondeterminacy of OS, algorithm is not always correct, and denies
requests that would not have led to deadlock.
- Deadlock does not occur immediately after allocating a resource, so cannot
simply make projection on state graph and then run deadlock detection
algorithm
Dijkstra's Banker's Algorithm
- Keep a track of all processes' current usage, future needs, and current
availability of resources.
- Deadlock will be avoided if request plus current usage is less than or equal
to process's claim, and if after the request is granted there is a sequence in
which all processes can run to completion even if they request their full claim
- safe state
Example, using 12 tape decks
Current Maximum
Loan Need
Process(1) 1 4
Process(2) 4 6
Process(3) 5 8
Available 2
Case A
Process(2) requests and obtains 2 remaining decks. Process(2) can run to
completion, releasing all 6 decks providing sufficient resources for the other
processes to complete - safe state
Case B
Process(1) requests one deck. State unsafe because there are not enough
resources to guarantee completion of all processes - request denied.
Advantages of the Banker's Algorithm
- Allows mutual-exclusion, hold-and-wait, and no pre-emption conditions
- System guarantees that processes will be allocated resources within finite
time.
Disadvantages
As an assignment, hand in an essay which discusses the disadvantages of the Banker's Algorithm
Summary
- Different ways of handling deadlock
Next Lecture...
Process Scheduling (1)