Distributed Deadlock Detection
Distributed Deadlock Detection
P1
R1 R4
P4 P2 Assignment
Edge
Request Edge
R2 P3 R3
DDD: Wait-For Graph
• Wait-For Graphs:
– In distributed systems, the system state can be
modeled or represented by a directed graph, called a
wait-for graph (WFG)
– In a WFG, nodes are processes and there is a
directed edge from node P1 to node P2 if P1 is
blocked and is waiting for P2 to release some
resource
– A system is deadlocked if and only if there is a
directed cycle or knot (depending upon the underlying
model) in the WFG
DDD: Wait-For Graph
P1 P2
P4 P3
DDD: Deadlock handling strategies in
DS
• There are three strategies to handle deadlock
– Deadlock Prevention
– Deadlock Avoidance
– Deadlock Detection and Recovery
• Deadlock handling is complicated to implement
in DS because no one site has accurate
knowledge of the current state of the system and
because every inter-site communication involves
a finite and unpredictable delay
DDD: Deadlock Prevention
• deadlock can be prevented in a DS through following approaches:
– Deadlock can be prevented in a DS through linear ordering of the
resources, simple to implement with less overhead
– Can be achieved either by having a process acquired all the needed
resources simultaneously before it begins execution or by preempting a
process that holds the needed resources
– Can use time-stamping and priority with resource preemption
– To control the preemption each process is assigned a unique priority
– These values are used to decide whether a process will wait for Pj if Pi
has a priority higher than Pj, otherwise Pi is rolled back
– It prevents deadlock because for nay edge Pi Pj, in the wait-for-graph,
Pi has a higher priority then Pj, then a cycle cant exist
– Low priority process will always be rolled back
– It can be avoided by the use of timestamps, two schemes can be used
as following:
Deadlock Prevention (contd.)
• The Wait-Die Scheme:
– A non-preemptive approach
– When process Pi requests a resource currently held
by Pj, Pi is allowed to wait only if it has a smaller
timestamp than does Pj (Pi is older than Pj)
– Otherwise Pi is rolled back
• The Wound-Wait scheme:
– A preemptive approach
– When process Pi requests a resource currently held
by Pj, Pi is allowed to wait only if it has a larger
timestamp than Pj ( pi is younger)
– Otherwise Pj is rolled back (pj is wounded)
DDD: Deadlock Avoidance
• A resource is granted to a process if the resulting global
state is safe ( a global state includes all the processes
and resources of the DS)
• Deadlock is practically impossible to implement because
– Every site ahs to maintain information on the global state of the
system, which translates into huge storage requirements an
dextensive communication costs
– The process of checking for a safe global state must be mutually
exclusive, because if several sites concurrently perform checks
for a safe state they may all find the state safe but the net global
state may not be safe
– Due to the large number of processes and resources it will be
computationally expensive to check for a safe state
DDD: Deadlock Detection and
Recovery
• Requires an examination of the staus of
process-resource interaction for the presence
of cyclical wait
• Two conditions exist in the DS:
– Once a cycle is formed in the WFG, it persists
until its is detected and broken, and
– Cycle detection can proceed concurrently with the
normal activities of a system
– We’ll study the techniques to detect deadlock in a
DS instead of trying to prevent or avoid it
Detection and Recovery
(contd.)
• Deadlock detection and resolution entails addressing two
basic issues:
– First, detection of existing deadlocks and
– second resolution of detected deadlocks.
• The detection of deadlocks involves two Issues:
– maintenance of the WFG and
– search of the WFG for the presence of cycles (or knots)
• In distributed systems, a cycle may involve several sites,
so the search for cycles greatly depends upon how the
WFG of the system is represented across the system
• Depending upon the manner in which WFG information
is maintained and the search for cycles is carried out,
there are centralized, distributed, and hierarchical
algorithms for deadlock detection in distributed systems.
Detection and Recovery
(contd.)
• Deadlock resolution involves breaking existing
wait-for dependencies in the system WFG to
resolve the deadlock
• It involves rolling back one or more processes
that are deadlocked and assigning their
resources to blocked processes in the deadlock
so that they can resume execution
DDD: Control Organizations
• Centralized Control
– Provided with a control site responsible of constructing WFG
– However, a single point of failure, congested links, continuous
message generation for deadlock detection, are the demerits.
• Distributed Control
– Detection of a global deadlock is shared equally
– Deadlock detection is initiated only when a waiting process is
suspected to be a part of deadlock cycle.
– However, such systems are difficult to design, several sites may
initiate detection for the same deadlock, proof of correctness is
difficult, deadlock resolution is cumbersome.
• Hierarchical Control
– Site detects deadlocks involving only its descendent sites
– Exploits access patterns local to a cluster of sites to efficiently detect
deadlocks.
– However, the control is defeated if most deadlocks span several
clusters.
Centralized Deadlock-
Detection
The Completely Centralized Algorithm
The Ho-Ramamoorthy Algorithms
The Completely Centralized
Algorithm
• A designated site called the Control Site is
provided which maintains the WFG of the entire
system
– It checks the WFG for the existence of deadlock cycles
whenever a request edge is added to the WFG.
• Sites request or release through Request and
Release message for all resources, whether local
or remote.
• However, it is highly inefficient due to
concentration of all messages.
– It imposes larger delays, large communication
overhead, and the congestion of communication links.
– Moreover, the reliability is poor due to single point of
failure.
The Ho-Ramamoorthy Algorithms
• Two proposals to resolve the problems in Centralized
algorithm
– The Two-Phase Algorithm
• Every site maintains a status table containing status of all the
processes initiated at that site.
• A designated site requests the status table from all sites, periodically.
• Two received reports are matched and a WFG is generated based on
the differences.
• The drawback is it may report a false deadlock.
– The One-Phase Algorithm
• It request one status report from each site, however, each site
maintains two status table, i.e. resource & process.
• Resource table keeps track of transactions, whereas the process table
keeps track of resources locked.
• Periodically, a designated site requests both the tables from every
site, constructs a WFG using the information provided by both tables.
• If no cycle is found, then the system is not deadlocked.
Distributed Deadlock
Detection Algorithms
A Path-Pushing Algorithm
An Edge-Chasing Algorithm
A Diffusion Computation Based Algorithm
Global State Detection Based Algorithm
An Overview
• All sites collectively cooperate to detect a cycle in
the state graph that is likely to be distributed over
several sites of the system.
• The algorithm can be initiated whenever a
process is forced to wait.
• The algorithm can be initiated either by the local
site of the process or by the site where the
process waits.
• These algorithm can be divided into four classes,
– Path-pushing algorithm
– Edge-chasing algorithm
– Diffusion computation algorithm
– Global state detection algorithm
An Edge-Chasing Algorithm
• If Pi is locally dependent on itself then declare deadlock
• Else for all Pj and Pk such that
– Pi is locally dependent upon Pj, and
– Pj is waiting on Pk, and
– Pj and Pk are on different sites,
• Send probe(I,j,k) to the home site of Pk
• On receipt of probe(I,j,k), the site takes the following actions:
• If
– Pk is blocked, and
– dependentk(i) is false, and
– Pk has not replied to all requests of Pj,
• then
begin
dependentk(i)=true;
if k=I then declare that Pi is deadlocked
else for all Pm and Pn such that
Pk is locally dependent upon Pm, and
Pm is waiting on Pn and
Pm and Pn are on different sites,
send probe(I,m,n) to the home sites of Pn
end
A Pictorial Example
P2
P1 P3
P9 Probe (1,6,8) P4
P6
P8 P5
P10 P7
Probe (1,7,10)
Site S3 Site S2
Hierarchical Deadlock
Detection Algorithm
The Menasce-Muntz Algorithm
The Ho-Ramamoorthy Algorithm
An Overview
• In hierarchical deadlock detection algorithms, sites are
arranged in a hierarchical fashion, and a site detects
deadlocks involving only its descendant sites
• Hierarchical algorithms exploit access patterns local to a
cluster of sites to efficiently detect deadlocks
• However, hierarchical deadlock detection algorithms
require special care while arranging the sites in a
hierarchy
• For efficiency, most deadlocks should be localized to as
few clusters as possible - the objective of hierarchical
control is defeated if most deadlocks span several clusters
• These algorithms can be divided into two classes,
– The Menasce-Muntz Algorithm
– The Ho-Ramamoorthy Algorithm
The Ho-Ramamoorth Algorithm
• Sites are grouped into several disjoint clusters.
• Periodically, a site is chosen as a central control site,
which dynamically chooses a control site for each cluster.
• The central control site requests from every control site
their intercluster transaction status information and wait-for
relation.
• A control site collects status tables from all the site in its
cluster and applies the one-phase deadlock detection
algorithm.
• It then sends status information and wait-for relation to the
central control site.
• Finally, the central site constructs a system WFG and
searches it for cycles.
A Pictorial Example
Control Site
Central Site