Sie sind auf Seite 1von 36

Deadlock Detection in Distributed Systems

Ajay Kshemkalyani and Mukesh Singhal


Distributed Computing: Principles, Algorithms, and Systems
Chapter 10
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
Introduction
Deadlocks is a fundamental problemin distributed
systems.
A process may request resources in anyorder, which may
not be known a priori anda process can request resource
while holding others.
If the sequence of the allocations of resources to the
processes is not controlled, deadlocks can occur.
A deadlock is a state where a set of processes request
resources that are heldby other processes in the set.
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
SystemModel
A distributed programis composed of a set of n
asynchronous processes p
1
, p
2
, . . . , p
i
, . . . , p
n
that
communicates by message passing over the
communicationnetwork.
Without loss of generality we assume that each process is
running ona different processor.
The processors do not share a common global memory
and communicate solely by passing messages over the
communicationnetwork.
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
There is no physical global clock in the systemto which
processes have instantaneous access.
The communicationmediummay deliver messages out of
order, messages may be lost garbled or duplicateddue to
timeout andretransmission, processors may fail and
communicationlinks may go down.
We make the followingassumptions:
The systems have only reusable resources.
Processes are allowed to make onlyexclusive access to
resources.
There is only one copy of eachresource.
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
A process can be in two states: running or blocked.
In the running state (also called active state), a process
has all the neededresources andis either executing or is
readyfor execution.
In the blocked state, a process is waitingto acquire some
resource.
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
Wait-For-Graph (WFG)
The state of the systemcan be modeledby directedgraph,
called a wait for graph (WFG).
In a WFG , nodes are processes andthere is a directed
edge fromnode P
1
to mode P
2
if P
1
is blocked andis
waiting for P
2
to release some resource.
A systemis deadlockedif and only if there exists a directed
cycle or knot in the WFG.
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
Figure 1 shows a WFG, where process P
11
of site 1 has an
edge to process P
21
of site 1 andP
32
of site 2 is waitingfor
a resource whichis currently held by process P
21
.
At the same time process P
32
is waitingon process P
33
to
release a resource.
If P
21
is waitingon process P
11
, then processes P
11
, P
32
and P
21
forma cycle andall the four processes are
involvedin a deadlock dependinguponthe request model.
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
P
11
P
21
P
32
P
54
P
24 P
44
P
33
site 1 site2
site 4
site3
Figure 1: An Example of a WFG
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
Preliminaries
Deadlock HandlingStrategies
There are three strategies for handlingdeadlocks, viz.,
deadlock prevention, deadlock avoidance, and deadlock
detection.
Handlingof deadlock becomes highly complicatedin
distributed systems because no site has accurate
knowledgeof the current state of the systemand because
everyinter-site communicationinvolves a nite and
unpredictable delay.
Deadlock preventionis commonlyachieved either by
having a process acquire all the neededresources
simultaneously before it begins executing or by preempting
a process which holds the neededresource.
This approachis highly inefcient andimpractical in
distributed systems.
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
In deadlock avoidance approachto distributedsystems, a
resource is granted to a process if the resulting global
systemstate is safe (note that a global state includes all
the processes andresources of the distributedsystem).
However, due to several problems, deadlock avoidance is
impractical in distributed systems.
Deadlock detectionrequires examinationof the status of
process-resource interactions for presence of cyclic wait.
Deadlock detectionin distributed systems seems to be the
best approachto handle deadlocks in distributed systems.
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
Issues in Deadlock Detection
Deadlock handlingusing the approach of deadlock
detectionentails addressing two basic issues: First,
detectionof existing deadlocks and second resolution of
detecteddeadlocks.
Detection of deadlocks involves addressing two issues:
Maintenance of the WFG and searchingof the WFG for the
presence of cycles (or knots).
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
Correctness Criteria: A deadlock detectionalgorithmmust
satisfy the followingtwo conditions:
(i) Progress (No undetecteddeadlocks):
The algorithmmust detect all existing deadlocks in nite
time.
In other words, after all wait-for dependencies for a
deadlock have formed, the algorithmshould not wait for
anymore events to occur to detect the deadlock.
(ii) Safety (No false deadlocks):
The algorithmshouldnot report deadlocks which do not
exist (called phantom or false deadlocks).
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
Resolution of a Detected Deadlock
Deadlock resolution involves breakingexistingwait-for
dependencies betweenthe processes to resolve the
deadlock.
It involves rolling back one or more deadlockedprocesses
and assigningtheir resources to blocked processes so that
they canresume execution.
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
Models of Deadlocks
Distributed systems allowseveral kinds of resource requests.
The Single Resource Model
In the single resource model, a process can have at most
one outstandingrequest for onlyone unit of a resource.
Since the maximumout-degree of a node in a WFG for the
single resource model can be 1, the presence of a cycle in
the WFG shall indicate that there is a deadlock.
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
The ANDModel
In the ANDmodel, a process can request for more than
one resource simultaneously and the request is satised
onlyafter all the requestedresources are grantedto the
process.
The out degree of a node in the WFG for ANDmodel can
be more than 1.
The presence of a cycle in the WFG indicates a deadlock
in the ANDmodel.
Since in the single-resource model, a process can have at
most one outstandingrequest, the ANDmodel is more
general thanthe single-resource model.
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
Consider the example WFG described in theFigure 1.
P
11
has two outstandingresource requests. Incase of the
ANDmodel, P
11
shall become active fromidle state only
after both the resources are granted.
There is a cycle P
11
->P
21
->P
24
->P
54
->P
11
which
corresponds to a deadlock situation.
That is, a process may not be a part of a cycle, it canstill
be deadlocked. Consider process P
44
in Figure 1.
It is not a part of any cycle but is still deadlockedas it is
dependent on P
24
which is deadlocked.
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
The OR Model
In the OR model, a process can make a request for
numerous resources simultaneouslyandthe request is
satised if any one of the requestedresources is granted.
Presence of a cycle in the WFG of an OR model does not
implya deadlock in the OR model.
Consider examplein Figure 1: If all nodes are OR nodes,
thenprocess P
11
is not deadlockedbecause once process
P
33
releases its resources, P
32
shall become active as one
of its requests is satised.
After P
32
nishes execution andreleases its resources,
process P
11
can continue with its processing.
In the OR model, the presence of a knot indicates a
deadlock.
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
The AND-OR Model
A generalization of the previous two models (OR model
and ANDmodel) is the AND-OR model.
In the AND-OR model, a request may specify any
combinationof and andor in the resource request.
For example, in the AND-OR model, a request for multiple
resources can be of the formx and (y or z).
To detect the presence of deadlocks in such a model, there
is no familiar construct of graphtheory usingWFG.
Since a deadlock is a stable property, a deadlock in the
AND-OR model can be detectedby repeatedapplicationof
the test for OR-model deadlock.
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
The
p
q
Model
The
p
q
model (called the P-out-of-Q model) allows a
request to obtain anyk available resources froma pool of n
resources.
It has the same in expressive power as the AND-OR
model.
However,
p
q
model lends itself to a much more compact
formation of a request.
Every request in the
p
q
model can be expressed in the
AND-OR model andvice-versa.
Note that ANDrequests for p resources can be stated as
p
p
and OR requests for p resources can be stated as
p
1
.
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
Unrestricted Model
In the unrestrictedmodel, no assumptions are made
regardingthe underlyingstructure of resource requests.
Onlyone assumptionthat the deadlock is stable is made
and hence it is the most general model.
This model helps separate concerns: Concerns about
properties of the problem(stability anddeadlock) are
separated fromunderlying distributed systems
computations (e.g., message passing versus synchronous
communication).
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
Knapps Classication
Distributed deadlock detectionalgorithms can be dividedinto
four classes:
path-pushing
edge-chasing
diffusion computation
global state detection.
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
Path-PushingAlgorithms
In path-pushingalgorithms, distributed deadlocks are
detectedby maintaining an explicit global WFG.
The basic idea is to build a global WFG for eachsite of the
distributed system.
In this class of algorithms, at each site whenever deadlock
computationis performed, it sends its local WFG to all the
neighboringsites.
After the local data structure of each site is updated, this
updatedWFG is then passed alongto other sites, and the
procedure is repeated until some site has a sufciently
complete picture of the global state to announce deadlock
or to establish that no deadlocks are present.
This feature of sendingaround the paths of global WFG
has led to the termpath-pushingalgorithms.
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
Edge-ChasingAlgorithms
In an edge-chasingalgorithm, the presence of a cycle in a
distributed graphstructure is be veried bypropagating
special messages called probes, alongthe edges of the
graph.
These probe messages are different thanthe request and
reply messages.
The formationof cycle can be deletedbya site if it receives
the matchingprobe sent by it previously.
Whenever a process that is executing receives a probe
message, it discards this message and continues.
Onlyblocked processes propagateprobe messages along
their outgoingedges.
Mainadvantage of edge-chasingalgorithms is that probes
are xed size messages which is normally very short.
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
Diffusing Computations Based Algorithms
In diffusion computation based distributed deadlock
detectionalgorithms, deadlock detection computationis
diffused throughthe WFG of the system.
These algorithms make use of echo algorithms to detect
deadlocks.
This computationis superimposed on the underlying
distributed computation. If this computation terminates, the
initiator declares a deadlock.
To detect a deadlock, a process sends out query
messages alongall the outgoingedges in the WFG.
These queries are successively propagated (i.e., diffused)
through the edges of the WFG.
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
Whena blocked process receives rst querymessage for a
particular deadlock detection initiation, it does not send a
reply message until it has receiveda reply message for
everyqueryit sent.
For all subsequent queries for this deadlock detection
initiation, it immediately sends back a replymessage.
The initiator of a deadlock detection detects a deadlock
when it receives reply for every queryit had sent out.
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
Global State Detection Based Algorithms
Global state detection baseddeadlock detection
algorithms exploit the following facts:
1
A consistent snapshot of a distributed systemcan be
obtained without freezing the underlying computation and
2
If a stable property holds inthe systembefore the snapshot
collectionis initiated, this property will still holdinthe
snapshot.
Therefore, distributed deadlocks can be detectedby taking
a snapshot of the systemandexamining it for the condition
of a deadlock.
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
Mitchell and Merritts Algorithmfor the
Single-Resource Model
Belongs to the class of edge-chasingalgorithms where
probes are sent in opposite direction of the edges of WFG.
When a probe initiated by a process comes back to it, the
process declares deadlock.
Onlyone process in a cycle detects the deadlock. This
simplies the deadlock resolution this process can abort
itself to resolve the deadlock.
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
Eachnode of the WFG has two local variables, called
labels:
1
a private label, whichis unique to the node at all times,
thoughit is not constant, and
2
a public label, whichcanbe read byother processes and
which may not be unique.
Eachprocess is representedas u/v where u and uare the
public andprivate labels, respectively.
Initially, private andpublic labels are equal for each
process.
A global WFG is maintainedandit denes the entire state
of the system.
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
The algorithmis denedby the four state transitions shown
in Figure 2, where z =inc(u, v), andinc(u, v) yields a
unique label greater than both u and v labels that are not
shown do not change.
Block creates an edge in the WFG.
Two messages are needed, one resource request andone
message back to the blocked process to informit of the
public label of the process it is waitingfor.
Activate denotes that a process has acquired the resource
fromthe process it was waitingfor.
Transmit propagates larger labels in the opposite direction
of the edges by sendinga probe message.
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
Activate
Transmit
Block
u z
z
v v
v u
u
u v
u<v
z
z
Detect
u v v
Figure 2: The four possible state transitions
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
Whenever a process receives a probe which is less thenits
public label, then it simply ignores that probe.
Detect means that the probe with the private label of some
process has returnedto it, indicating a deadlock.
The above algorithmcanbe easilyextended to include
priorities where whenever a deadlock occurs, the lowest
priority process gets aborted.
Message Complexity:
If we assume that a deadlock persists long enoughto be
detected, the worst-case complexity of the algorithmis s(s -
1)/2 Transmit steps, wheres is the number of processes in the
cycle.
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
Chandy-Misra-Haas Algorithmfor the ANDModel
Chandy-Misra-Haass distributed deadlock detection
algorithmfor ANDmodel is basedonedge-chasing.
The algorithmuses a special message calledprobe, which
is a triplet (i, j, k), denotingthat it belongs to a deadlock
detectioninitiated for process P
i
and it is beingsent by the
home site of process P
j
to the home site of process P
k
.
A probe message travels alongthe edges of the global
WFG graph, anda deadlock is detected whena probe
message returns to the process that initiatedit.
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
A process P
j
is said to be dependent on another process
P
k
if there exists a sequence of processes P
j
, P
i 1
, P
i 2
, ...,
P
im
, P
k
such that eachprocess except P
k
in the sequence
is blocked and eachprocess, except the P
j
, holds a
resource for whichthe previous process in the sequence is
waiting.
Process P
j
is said to be locally dependent upon process
P
k
if P
j
is dependent uponP
k
andboththe processes are
onthe same site.
Data Structures
Eachprocess P
i
maintains a booleanarray, dependent
i
,
where dependent
i
(j) is true onlyif P
i
knows that P
j
is
dependent onit.
Initially, dependent
i
(j) is false for all i and j.
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
Algorithm
The following algorithmdetermines if a blocked process is
deadlocked:
if P
i
is locally dependent onitself then declare a deadlock
else for all P
j
andP
k
such that
1
P
i
is locally dependent upon P
j
, and
2
P
j
is waiting onP
k
, and
3
P
j
and P
k
are on different sites,send a probe (i, j, k) to the
home site of P
k
On the receipt of a probe (i, j, k), the site takes the
following actions: if
1
P
k
is blocked, and
2
dependent
k
(i) is false, and
3
P
k
has not replied to all requests P
j
,
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
then
begin
dependent
k
(i) =true;
if k=i
then declare that P
i
is deadlocked
else for all P
m
and P
n
such that
(a) P
k
is locally dependent uponP
m
,
and
(b) P
m
is waitingon P
n
, and
(c) P
m
andP
n
are on different sites,
send a probe (i, m, n) to the home site
of P
n
end.
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
A probe message is continuouslycirculated alongthe
edges of the global WFG graphand a deadlock is detected
when a probe message returns to its initiating process.
Performance Analysis
One probe message (per deadlock detectioninitiation) is
sent on every edge of the WFG which that two sites.
Thus, the algorithmexchanges at most m(n 1)/2
messages to detect a deadlock that involves m processes
and that spans over n sites.
The size of messages is xed andis very small (only 3
integer words).
Delayin detectinga deadlock is O(n).
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
Chandy-Misra-Haas Algorithmfor the OR Model
Chandy-Misra-Haas distributed deadlock detectionalgorithm
for OR model is basedonthe approachof
diffusion-computation.
A blocked process determines if it is deadlocked by
initiating a diffusioncomputation.
Two types of messages are usedin a diffusion
computation:
query(i, j, k) andreply(i, j, k), denotingthat they belongto a
diffusion computationinitiated by a process P
i
and are
being sent fromprocess P
j
to process P
k
.
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
A blocked process initiates deadlock detection by sending
query messages to all processes in its dependent set.
If anactive process receives a queryor reply message, it
discards it.
When a blocked process P
k
receives a query(i, j, k)
message, it takes the following actions:
1
If this is the rst query message received byP
k
for the
deadlock detection initiated byP
i
(called the engaging
query), thenit propagates the queryto all the processes in
its dependent set and sets a local variable num
k
(i) to the
number of query messages sent.
2
If this is not the engaging query, then P
k
returns a reply
message to it immediately provided P
k
has been
continuously blockedsince it received the corresponding
engaging query. Otherwise, it discards the query.
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
Process P
k
maintains a booleanvariable wait
k
(i) that
denotes the fact that it has beencontinuously blocked
since it received the last engagingquery fromprocess P
i
.
When a blocked process P
k
receives a reply(i, j, k)
message, it decrements num
k
(i) onlyif wait
k
(i) holds.
A process sends a reply message in response to an
engagingquery only after it has received a reply to every
query message it hadsent out for this engagingquery.
The initiator process detects a deadlock whenit receives
reply messages to all the querymessages it hadsent out.
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
Algorithm
The algorithmworks as follows:
Initiate a diffusion computation for a blocked process P
i
:
send query(i, i, j) to all processes P
j
in the dependent set
DS
i
of P
i
;
num
i
(i):=jDS
i
j; wait
i
(i):=true;
When a blocked process P
k
receives a query(i, j, k):
if this is the engagingquery for process P
i
then send query(i, k, m) to all Pm in its dependent
set DS
k
;
num
k
(i): =jDS
k
j; wait
k
(i):=true
else if wait
k
(i) thensend a reply(i, k, j) to P
j
.
When a process P
k
receives a reply(i, j, k):
if wait
k
(i)
then begin
num
k
(i):=num
k
(i) 1;
if num
k
(i)=0
thenif i=k then declare a deadlock
else send reply(i, k, m) to the process Pm
which sent the engagingquery.
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
In practice, several diffusioncomputations may be initiated
for a process (A diffusioncomputationis initiated every
time the process gets blocked), but, at any time only one
diffusion computationis current for anyprocess.
However, messages for outdateddiffusion computations
may still be in transit.
The current diffusioncomputationcan be distinguished
fromoutdatedones by using sequence numbers.
Performance Analysis
For everydeadlock detection, the algorithmexchanges e query
messages and e reply messages, where e=n(n-1) is the
number of edges.
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
Kshemkalyani-Singhal Algorithmfor P-out-of-Q Model
Kshemkalyani-Singhal algorithmdetects deadlocks in the
P-out-of-Q model is based on the global state detection
approach.
It is a single phase algorithm, which consists of a fan-out
sweep of messages outwards fromaninitiator process and
a fan-in sweepof messages inwards to the initiator
process.
A sweep is a traversal of the WFG in which all messages
are sent in the direction of the WFG edges (outward
sweep) or all messages are sent against the direction of
the WFG edges (inwardsweep).
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
In the outwardsweep, the algorithmrecords a snapshot of
a distributed WFG.
In the inwardsweep, the recorded distributed WFG is
reducedto determine if the initiator is deadlocked.
Boththe outwardand the inward sweeps are executed
concurrently in the algorithm.
Complications are introducedbecause the two sweeps can
overlap in time at a process, i.e., the reductionof the WFG
at a process can beginbefore the WFG at that process has
been completelyrecorded.
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
SystemModel
The systemhas n nodes, and everypair of nodes is
connected by a logical channel.
Events are assignedtimestamps usingLamports clocks.
The computationmessages can be either REQUEST,
REPLY or CANCEL messages.
To execute a p-out-of-q request, an active node i sends
REQUESTs to other nodes andremains blocked until it
receives sufcient number of REPLY messages.
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
When node i blocks onnode j , node j becomes a
successor of nodei andnode i becomes a predecessor of
node j in the WFG.
A REPLY message denotes the grantingof a request.
A node i unblocks when pout of its q requests have been
granted.
When a node unblocks, it sends CANCEL messages to
withdrawthe remainingq - p requests it had sent.
Sendingandreceivingof REQUEST, REPLY, andCANCEL
messages are computation events.
The sendingandreceiving of deadlock detectionalgorithm
messages are algorithmic or control events.
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
Data Structures
A node i has the followinglocal variables:
wait
i
: boolean (:=false); /*records the current status.*/
t
i
: integer (:=0); /*denotes the current time.*/
t_block
i
: real; /*denotes the local time wheni blocked last.*/
in(i ) : set of nodes whose requests are outstanding at node
i .
out (i ) : set of nodes on which node i is waiting.
p
i
: integer (:=0); /*the number of replies required for
unblocking.*/
w
i
: real (:=1.0); /*keeps weight to detect the termination
of the algorithm.*/
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
Computation Events
REQUEST_SEND(i)
/*Executedby node i whenit blocks on a p-out-of-q request.*/
For everynode j on whichi is blocked do
out (i ) out(i ) {j };
send REQUEST(i) to j ;
set p
i
to the number of replies needed;
t_block
i
:=t
i
;
wait
i
true;
REQUEST_RECEIVE(j )
/*Executedby node i whenit receives a request made byj */
in(i ) in(i ) j .
REPLY_SEND(j )
/*Executedby node i whenit replies to a request by j .*/
in(i ) in(i ) j ;
send REPLY(i) to j .
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
REPLY_RECEIVE(j )
/*Executed by nodei whenit receives a replyfromj to its
request.*/
if valid reply for the current request
then begin
out (i ) out(i ) j ;
p
i
p
i
1;
p
i
=0
{wait
i
false;
k out (i ), send CANCEL(i ) to k;
out(i ) .}
end
CANCEL_RECEIVE(j )
/*Executed by nodei whenit receives a cancel fromj .*/
if j in(i ) thenin(i ) in(i) j .
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
Informal Description of the Algorithm
When a node init blocks ona P-out-of-Q request, it
initiates the deadlock detection algorithm.
The algorithmrecords part a of the WFG that is reachable
frominit (henceforth, called the init s WFG) in a distributed
snapshot.
The distributed WFG is recorded using FLOODmessages
in the outwardsweepand recorded WFG is examined for
deadlocks using ECHO messages in the inwardsweep.
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
To detect a deadlock, the initiator init records its local state
and sends FLOODmessages alongall of its outward
dependencies.
When node i receives the rst FLOODmessage alongan
existing inwarddependency, it records its local state.
If node i is blocked at this time, it sends out FLOOD
messages alongall of its outwarddependencies to
continue the recording of the WFG in the outwardsweep.
If node i is active at this time, thenit initiates reductionof
the WFG by returning anECHO message along the
incoming dependency evenbefore the states of all
incoming dependencies have beenrecordedin the WFG
snapshot at the leaf node.
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
ECHO messages performreduction of the recorded WFG
by simulating the grantingof requests in the inwardsweep.
A node i in the WFG is reducedif it receives ECHOs along
p
i
out of its q
i
outgoingedges indicating that p
i
of its
requests can be granted.
Anedge is reducedif an ECHO is received on the edge
indicating that the request it represents can be granted.
The nodes that can be reduced do not forma deadlock
whereas the nodes that cannot be reduced are
deadlocked.
Node init detects the deadlock if it is not reducedwhenthe
deadlock detectionalgorithmterminates.
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
The Problemof Termination Detection
The algorithmrequires a terminationdetection technique
so that the initiator can determine that it will not receive
anymore ECHO messages.
The algorithmuses a termination detection technique
based on weights incojunction with SHORT messages to
detect the termination of the algorithm.
A weight of 1.0 at the initiator node, whenthe algorithmis
initiated, is distributed amongall FLOODmessages sent
out by the initiator.
When the rst FLOODis received at a non-leaf node, the
weight of the receivedFLOODis distributed amongthe
FLOODs sent out alongoutward edges at that node to
expand the WFG further.
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
Since any subsequent FLOODarriving at a non-leaf node
does not expand the WFG further, its weight is returnedto
the initiator in a SHORT message.
When a FLOODis received at a leaf node, its weight is
piggybackedto the ECHO sent bythe leaf node to reduce
the WFG.
When an ECHO that arrives at a node unblocks the node,
the weight of the ECHO is distributed amongthe ECHOs
that are sent by that node along the incoming edges in its
WFG snapshot.
When an ECHO arriving at a node does not unblock the
node, its weight is sent directly to the initiator in a SHORT
message.
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
The followinginvariant holds in an execution of the algorithm:
the sumof the weights inFLOOD, ECHO, andSHORT
messages plus the weight at the initiator (received in
SHORT andECHO messages) is always 1.0.
The algorithmterminates whenthe weight at the initiator
becomes 1.0, signifying that all WFG recordingand
reduction activity has completed.
FLOOD; ECHO, andSHORT messages carry weights for
termination detection. Variable w, a real number in the
range [0; 1], denotes the weight in a message.
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
The Algorithm
A node i stores the local snapshot for snapshots initiated
by other nodes in a data structure LS
i
(Local Snapshot),
which is an array of records.
LS
i
: array [1..n] of record;
A record has several elds to record snapshot related
informationandis dened belowfor an initiator init:
LS
i
[init]:out : set of integers (:= ); /*nodes onwhichi is
waitingin the snapshot.*/
LS
i
[init]:in : set of integers (:= ); /*nodes waiting on i in the
snapshot.*/
LS
i
[init]:t : integer (:=0); /*time wheninit initiated
snapshot.*/
LS
i
[init]:s : boolean (:=false); /*local blocked state as seen
by snapshot.*/
LS
i
[init]:p : integer; /*value of p
i
as seenin snapshot.*/
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
The deadlock detection algorithmis denedby the following
procedures. The procedures are executedatomically.
SNAPSHOT_INITIATE
/*Executedby node i to detect whether it is deadlocked. */
init i ;
w
i
0;
LS
i
[init ]:t t
i
;
LS
i
[init ]:out out(i );
LS
i
[init ]:s true;
LS
i
[init ]:in ;
LS
i
[init ]:p p
i
;
send FLOOD(i; i ; t
i
; 1=out(i) ) to each j in out (i ). /*
1=out(i ) is the fraction of weight sent in a FLOODmessage. */
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
FLOOD_RECEIVE(j , init , t _init, w)
/*Executedby node i onreceiving a FLOODmessage fromj . */
LS
i
[init]:t <t_init j in(i) /*Valid FLOODfor a newsnapshot.
*/
LS
i
[init ]:out out(i );
LS
i
[init ]:in j ;
LS
i
[init ]:t t_init ;
LS
i
[init ]:s wait
i
;
wait
i
=true /* Node is blocked. */
LS
i
[init]:p p
i
;
send FLOOD(i ;init; t_init; w=out (i ) ) to eachk out(i );
wait
i
=false /* Node is active. */
LS
i
[init]:p 0;
send ECHO(i ;init; t_init; w) to j;
LS
i
[init]:in LS
i
[init]:in j .

A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems


LS
i
[init]:t <t_init j in(i ) /* Invalid FLOODfor a newsnapshot. */
send ECHO(i ;init; t_init;w) to j.

LS
i
[init]:t =t_init j in(i ) /* Invalid FLOODfor current snapshot. */
send ECHO(i ;init; t_init;w) to j.

LS
i
[init]:t =t_init j in(i ) /*Valid FLOODfor current snapshot. */
LS
i
[init ]:s =false
send ECHO(i ;init; t_init;w) to j;
LS
i
[init ]:s =true
LS
i
[init]:in LS
i
[init]:in j ;
send SHORT(init; t_init ;w) to init .
LS
i
[init]:t >t_init discardthe FLOODmessage. /*Out-datedFLOOD. */
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
ECHO_RECEIVE(j , init , t_init , w)
/*Executedby node i onreceiving an ECHOfromj. */
/*Echo for out-dated snapshot. */
LS
i
[init]:t >t_init discardthe ECHO message.
LS
i
[init]:t <t_init cannot happen. /*ECHOfor unseensnapshot.
*/
LS
i
[init]:t =t_init /*ECHOfor current snapshot. */
LS
i
[init ]:out LS
i
[init]:out j ;
LS
i
[init ]:s =false send SHORT(init ;t_init ;w) to init .
LS
i
[init ]:s =true
LS
i
[init]:p LS
i
[init]:p 1;
LS
i
[init]:p =0 /*gettingreduced*/
LS
i
[init]:s false;
init =i declare not deadlocked; exit.
send ECHO(i; init; t_init ;w=LS
i
[init ]:in ) to all
k LS
i
[init ]:in;
LS
i
[init]:p =0
send SHORT(init; t_init ;w) to init .
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
SHORT_RECEIVE(init, t_init , w)
/*Executedby node i (whichis always init ) on receiving a SHORT. */
[
/*SHORT for out-dated snapshot. */
t_init <t_block
i
discardthe message.

/*SHORT for uninitiated snapshot. */


t_init >t_block
i
not possible.

/*SHORT for currentlyinitiated snapshot. */


t_init =t_block
i
LS
i
[init]:s =false discard. /* init is
active. */
t_init =t_block
i
LS
i
[init]:s =true
w
i
w
i
+w;
w
i
=1 declare a deadlock.
]
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
An Example
We nowillustrate the operationof the algorithmwith the
help of an example shownin Figures 3and 4.
Figure 3 shows initiation of deadlock detection by node A
and Figure 4 shows the state after node D is reduced.
The notation x=y beside a node in the gures indicates
that the node is blocked andneeds replies to x out of the y
outstandingrequests to unblock.
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
REQUEST
FLOOD
REPLY
ECHO
B
1/2
C
2/3
D
2/4 E
1/2
F
G
H
I
1/2
A (initiator)
Figure 3: An Example-runof the Algorithm.
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
In Figure 3, node A sends out FLOODmessages to nodes
B and C. When nodeC receives FLOODfromnode A, it
sends FLOODs to nodes D, E, and F.
If the node happens to be active whenit receives a FLOOD
message, it initiates reductionof the incomingwait-for
edge by returninganECHO message on it.
For example, in Figure 3, node H returns an ECHO to node
D in response to a FLOODfromit.
Note that node caninitiate reductioneven before the states
of all other incomingwait-for edges have beenrecordedin
the WFG snapshot at that node.
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
For example, nodeF in Figure 3 starts reductionafter
receiving a FLOODfromC even before it has received
FLOODs fromD andE.
Note that whena node receives a FLOOD, it neednot have
an incoming wait-for edge fromthe node that sent the
FLOODbecause it may have alreadysent back a REPLY
to the node.
In this case, the node returns anECHOin response to the
FLOOD.
For example, in Figure 3, whennode I receives a FLOOD
fromnode D, it returns an ECHO to node D.
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
ECHO messages performreduction of the nodes and
edges in the WFG by simulating the grantingof requests in
the inwardsweep.
A node that is waiting a p-out-of-q request, gets reduced
after it has received p ECHOs.
When a node is reduced, it sends ECHOs alongall the
incoming wait-for edges incident onit in the WFG snapshot
to continue the progress of the inward sweep.
In general, WFG reductioncan begin at a non-leaf node
before recording of the WFG has been completedat that
node.
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
This happens whenECHOs arrive andbeginreductionat a
non-leaf node before FLOODs have arrived alongall
incoming wait-for edges and recorded the complete local
WFG at that node.
For example, nodeD in Figure 3 starts reduction(by
sendinganECHO to node C) after it receives ECHOs from
H and G, evenbefore FLOODfromB has arrived at D.
When a FLOODonan incoming wait-for edge arrives at a
node whichis already reduced, the node simply returns an
ECHO alongthat wait-for edge.
For example, in Figure 4, whena FLOODfromnode B
arrives at node D, node D returns an ECHO to B.
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
REQUEST
FLOOD
REPLY
ECHO
B
1/2
C
2/3
D
E
1/2
F
A (initiator)
1/2
Figure 4: An Example-runof the Algorithm(continued).
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
In Figure 3, node C receives a FLOODfromnode A
followedby a FLOODfromnode B.
When node C receives a FLOODfromB, it sends a
SHORT to the initiator node A.
When a FLOODis received at a leaf node, its weight is
returnedin the ECHO message sent by the leaf node to
the sender of the FLOOD.
Note that an ECHO is like a replyin the simulated
unblockingof processes.
When an ECHO arriving at a node does not reduce the
node, its weight is sent directly to the initiator througha
SHORT message.
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
For example, in Figure 3, whennode Dreceives an ECHO
fromnode H, it sends a SHORT to the initiator node A.
When an ECHO that arrives at a node reduces that node,
the weight of the ECHO is distributed amongthe ECHOs
that are sent by that node along the incoming edges in its
WFG snapshot.
For example, in Figure 4, at the time node C gets reduced
(after receiving ECHOs fromnodes Dand F), it sends
ECHOs to nodes A and B. (Whennode A receives an
ECHO fromnode C, it is reducedand it declares no
deadlock.)
When an ECHO arrives at a reducednode, its weight is
sent directly to the initiator througha SHORT message.
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
For example, in Figure 4, whenan ECHO fromnode E
arrives at node C after node C has beenreduced(by
receiving ECHOs fromnodes Dand F), nodeC sends a
SHORT to initiator node A.
Correctness
Provingthe correctness of the algorithminvolves showingthat it
satises the followingconditions:
1
The execution of the algorithmterminates.
2
The entire WFG reachable fromthe initiator is recordedin
a consistent distributed snapshot in the outwardsweep.
3
Inthe inwardsweep, ECHO messages correctly reduce the
recordedsnapshot of the WFG.
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
The algorithmis initiatedwithina timeout periodafter a
node blocks on a P-out-of-Q request.
On the terminationof the algorithm, only all the nodes that
are not reduced, are deadlocked.
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems
Complexity Analysis
The algorithmhas a message complexity of 4e 2n +2l
and a time complexity
1
of 2d hops, where e is the number
of edges, n the number of nodes, l the number of leaf
nodes, andd the diameter of the WFG.
This gives the best time complexity that can be achieved
by an algorithmthat reduces a distributed WFG to detect
generalizeddeadlocks in distributed systems.
1
Time complexitydenotes the delayin detectinga deadlock after its
detectionhas beeninitiated.
A. Kshemkalyani andM. Singhal Deadlock Detectionin DistributedSystems

Das könnte Ihnen auch gefallen