Lecture Notes for 20.04.2005

advertisement
DEADLOCKS
Necessary conditions for deadlocks arising:
 Processes share common critical resources;
 Processes require additional resources
 If they are absent, processes wait for them,
 When waiting, they don’t release already captured resources.
Methods for coping with deadlocks:
 Detection and resolution (system monitors processes states);
 Exclusion of deadlocks (before starting process gets all
necessary resources and doesn’t require additional any more);
 Avoidance of deadlocks (compromise, resources are granted to
process only if there is a possibility for system further
development).
DEADLOCKS DETECTION
Resource graphs are used for deadlock detection. They have nodes of
two types: processes –
and resources –
. If we have several units of
some resource type they are shown by dots (or by number) inside resource
node.
Nodes are connected by edges. Edge is directed from the process to
resource if process requires resource. Edge is directed from resource to the
process if it is granted to the process.
DEADLOCKS DETECTION (CONT 1)
P1
R1
P2
P3
Deadlock is represented by the loop on the resource graph.
Resource graph reduction procedure is used for deadlock detection. If
after this reduction all edges in the graph will disappear, then deadlocks are
absent. Otherwise left edges form loops representing deadlocks.
Resource graph reduction follows:
If resources are granted to the process or may be granted (they are
present), or no resources are granted, then respective edges may be shrunk.
Reduction is made sequentially on processes and shrinks edges associated
with processes which potentially can terminate (its requests are satisfied or
can be satisfied).
Let’s consider the following situation:
R1
P1
P2
R2
Р1 requires R1 and already has R2, P2 requires R2 and captures R1. Graph
can’t be reduced, i.e. we have deadlock.
DEADLOCKS DETECTION (CONT 2)
Methods of deadlocks detection are classified as centralized (1) and
decentralized (2).
CENTRALIZED DEADLOCKS DETECTION
Resource graph is stored in one place and processed by respective processor.
Benefit is simplicity, drawback is lack of reliability and performance
decreasing (it becomes a bottleneck);
DECENTRALIZED DEADLOCKS DETECTION
Goldman’s algorithm:
Processes exchange by information in the form of ordered blocked processes
lists (OBPLs) in which each process excepting last is blocked by its
successor. It is assumed that process is blocked by the other process if the
latter captured resources required for the former process.
P1
P2
P3
P4
P5
In the figure is shown tasks waiting graph (TWG): Р1 waits for P2,
which waits for P3 and so on, last process P5 runs; when it will release
resource required to P4, the latter will be resumed. There is no loop on this
graph, hence there is no deadlock. If P1 will initiate deadlock detection
procedure, it will send to P2 list of (P1, P2), P2 will add P3 to it and send it
to P3, and so on. Each process after getting OBPL analyses it trying to find
itself twice. Process found itself twice in this list detects deadlock. In the
case of P5 being blocked by P1, P1 will detect deadlock after getting OBPL
(P1,P2,P3,P4,P5,P1) from P5.
DECENTRALIZED DEADLOCKS DETECTION (CONT 1)
Chandy, Misra, Haas’s algorithm
P1
P2
P3
1
P4
P9
P5
3
P8
P10
2
P6
P7
Processes exchange by special packets (triplets (i, j, k)), where:
i – is a number of the process-sender;
j – is a number of computer node in which process-sender resides;
k – is a number of the node where blocking process resides.
Process-initiator detects deadlock in the case of receiving triplet back,
as it is illustrated for the figure above with 3 computer nodes and 10
processes, process P1 initiates deadlock detection by sending (1,1,1) to
blocking it process P2:
12(1,1,1), 23(2,1,1), 34(3,1,2), 45(4,2,2), 56(5,2,2), 57(5,2,2),
56(5,2,2), 68(6,2,3), 89(8,3,3), 91(9,3,1), 710(7,2,3)
Process P1 will get back triplet and will detect deadlock.
DECENTRALIZED DEADLOCKS DETECTION (CONT 2)
Michell-Merritt’s algorithm
Each node in the graph gets two labels: local and global. Local labels
are unique. Initially both labels have the same values. Algorithm detects
deadlock by backward (contrary to graph edges direction) spreading of the
global labels. Node, on receiving global label, changes its global label on the
value, maximal from the old and new global labels.
(8, 8)
will be
(8, 9)
(9, 9)
l g
max [9, 1]
is not
changed
(1, 1)
l g
Deadlock is detected when node gets its own global label, this label is
the greatest in the deadlock loop. Node, detected deadlock, resolves it by
termination its own work.
Bracha-Toueg’s algorithm
Algorithm has 2 phases: messages with resources requests stream
down to TWG (along edges direction) ; messages on granting resources are
returned back from active processes, making getting them processes also
active. At the end of the 2nd phase not became active processes are assumed
to be in deadlock.
DECENTRALIZED DEADLOCKS DETECTION (CONT 3)
Hierarchical approach - Ho-Ramamoorthy’s algorithm
Computers are grouped in disjoint clusters. Periodically one computer
is assigned to be a main, and it assigns main computers for each cluster.
Main computer asks for inter-cluster transactions and inter-cluster blocks,
and the latter considers blockings on the system level, while main computers
in clusters try to find in-cluster deadlocks.
PROBLEMS RELATED WITH DEADLOCKS DETECTION
1. Proof of the algorithms correctness is hard because of very large possible
combinations of interactions and sensitivity of deadlocks to timings.
2. Problem of performance evaluation. What to take as the performance
measure: number of messages, their total volume, time of deadlocks
existence, time for deadlock resolution?
3. Deadlocks resolution. Deadlock may be resolved by termination of any
process involved in deadlock. Process detected deadlock may not know
that other process also has detected the same deadlock. This may lead to
double termination which is not efficient. Hence, after deadlock detection
there must be additional information exchange. For deadlock resolution it
is necessary to:
3.1.Select victim (what process to terminate);
3.2.Terminate chosen process, release all captured by it resources,
restoring their original values.
3.3.Delete information about victim from all system structures (for
example, from TWG).
4. False deadlocks.
PROBLEMS RELATED WITH DEADLOCKS DETECTION
(CONT 1)
Т2
Т1
S1
Т3
Т6
S2
S4
Т4
Т5
Т9
Т8
Т7
S3
Let’s assume that upper deadlock (loop) is detected by P3, which resolves
it deletion of edge T4T5. Simultaneously, process T8 could detect lower
loop (if edge T4T5 would be deleted after transmitting through it message
from T8).
DEADLOCKS EXCLUSION
1. Process is not launched unless all necessary resources will be granted
to it.
2. Process which has not got required resources releases all previously
captured resources and is interrupted.
Download