66
Deadlocks – An Introduction What Are DEADLOCKS ? A Blocked Process which can never be resolved unless there is some outside Intervention. Resource R1 is requested by Process P1 but is held by Process P2. For Example:-

Deadlocks – An Introduction What Are DEADLOCKS ? A Blocked Process which can never be resolved unless there is some outside Intervention. Resource

Embed Size (px)

Citation preview

Page 1: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

Deadlocks – An Introduction

• What Are DEADLOCKS ? A Blocked Process which can never be resolved

unless there is some outside Intervention.

Resource R1 is requested by Process P1 but is held by Process P2.

• For Example:-

Page 2: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

2

Deadlock

Deadlock is a situation where a process or a set of processes is blocked on an event that never occurs

Processes while holding some resources may request for additional allocation of resources which are held by other processes

Processes are in circular wait for the resources

Page 3: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

3

Deadlock vs Starvation

Starvation occurs when a process waits for a resource that becomes available continuously but is not allocated to a process

Two Main Differences - In starvation it is not certain that a process will ever get

the requested resource where as a deadlocked process is permanently blocked because required resource never become available

- In starvation the resource under contention is in continuation use where as this is not true in case of deadlock

Page 4: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

Causes Of Deadlocks

• Mutual Exclusion – Resources being held must be in non-shareable mode.

• Hold n Wait – A Process is holding one resource and is waiting for another, which is held by another process.

• No Preemption – Resource cannot be preempted even if it is being requested.

• Circular Wait – Presence of a cycle of waiting processes.

Page 5: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

5

Models of Deadlock

Single-Unit Request Model- Process is restricted to request only one resource at a

time- Outdegree in WFG is one- Cycle in WFG means deadlock

P1 P2

P3

Page 6: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

6

Models of Deadlock ………

AND Request Model- Process can simultaneously request multiple resources- Process Remain blocked until all the resources are granted- Outdegree of WFG can be more than 1- Cycle in WFG means system is deadlocked - Process can be involved in more than one deadlock

P1 P2

P3 P4

Page 7: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

7

Models of Deadlock ………

OR Request Model- Process can simultaneously request multiple resources- Process Remain blocked until it is granted any of the requested

resources- Outdegree of WFG can be more than 1- Cycle in WFG is not a sufficient condition for the deadlock - Knot in the WFG is a sufficient condition for deadlock - Knot is a subset of graph such that starting from any node in the

subset it is impossible to leave the knot by following the edges of the graph

Page 8: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

Cycle vs Knot

P1 P2

P3

P4

P5

Cycle but no Knot

Deadlock in AND Model

But no Deadlock in OR Model

P1 P2

P3

P4

P5

Cycle & Knot

Deadlock in both AND & OR Model

Page 9: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

Resources

Reusable (CPU, Main-memory, I/O Devices) Consumable (Messages, Interrupt Signals

Page 10: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

10

Distributed Deadlock Detection• Assumptions:

a. System has only reusable resourcesb. Only exclusive access to resourcesc. Only one copy of each resourced. States of a process: running or blockede. Running state: process has all the resourcesf. Blocked state: waiting on one or more resource

Page 11: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

11

Resource vs Communication Deadlocks

• Resource Deadlocks• A process needs multiple resources for an activity.• Deadlock occurs if each process in a set request resources held by another process in the same set, and it must receive all the requested resources to move further.

• Communication Deadlocks• Processes wait to communicate with other processes in a set.• Each process in the set is waiting on another process’s message, and no process in the set initiates a message until it receives a message for which it is waiting.

Page 12: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

12

Graph Models

Nodes of a graph are processes. Edges of a graph the pending requests or assignment of resources.

Wait-for Graphs (WFG): P1 -> P2 implies P1 is waiting for a resource from P2.

Transaction-wait-for Graphs (TWF): WFG in databases. Deadlock: directed cycle in the graph. Cycle example:

P1 P2

Page 13: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

13

Graph Models

Wait-for Graphs (WFG): P1 -> P2 implies P1 is waiting for a resource from P2.

P1

P2

R1

R2

Request Edge

Assignment Edge

Page 14: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

Illustrating A Deadlock

• Wait-For-Graph (WFG) Nodes – Processes in the system Directed Edges – Wait-For blocking relation

• A Cycle represents a Deadlock• Starvation - A process’ execution is permanently halted.

Process 1 Process 2

Resource 1

Resource 2Waits For

Waits For

Held By

Held By

Page 15: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

WFG (Wait For Graph) & TWF (Transaction WF)

Page 16: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

16

AND, OR Models

AND Model A process/transaction can simultaneously request for

multiple resources. Remains blocked until it is granted all of the requested

resources.

OR Model A process/transaction can simultaneously request for

multiple resources. Remains blocked till any one of the requested resource is

granted.

Page 17: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

17

Sufficient Condition

P1 P2

P3P4

P5

P6

Deadlock ??

Page 18: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

18

AND, OR Models

AND Model Presence of a cycle.

P1 P2

P3P4

P5

Page 19: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

19

AND, OR Models

OR Model Presence of a knot. Knot: Subset of a graph such that starting from any

node in the subset, it is impossible to leave the knot by following the edges of the graph.

P1 P2

P3P4

P5

P6

Page 20: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

20

Deadlock Handling Strategies

Deadlock Prevention: difficult Deadlock Avoidance: before allocation, check for

possible deadlocks. Difficult as it needs global state info in each site (that

handles resources). Deadlock Detection: Find cycles. Focus of discussion. Deadlock detection algorithms must satisfy 2 conditions:

No undetected deadlocks. No false deadlocks.

Page 21: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

Deadlocks in Distributed Systems

• Resource Deadlock Most Common. Occurs due to lack of requested Resource. Set of deadlocked processes, where each process waits for a

resource held by another process (e.g., data object in a database, I/O resource on a server)

• Communication Deadlock

A Process waits for certain messages before it can proceed.

Set of deadlocked processes, where each process waits to receive messages (communication) from other processes in the set. 

Page 22: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

Handling Deadlocks

• Deadlock Avoidance

Only fulfill those resource requests that won’t cause deadlock in the future.

Inefficient. Requires Prior resource requirement information for all

processes. High Cost of scalability. Every site has to maintain global state of system (extensive

overhead in storage and communication) Different sites may determine (concurrently) that state is safe, but

global state may be unsafe: verification for safe global state by different sites must be mutually exclusive

Large overhead to check for every allocation (distributed system may have large number of processes and resources

Conclusion: Deadlock avoidance impractical in distributed systems

• Drawbacks

Simulate resource allocation and determine if resultant state is safe or not.

Decision made dynamically, before allocating a resource, the resulting global system state is checked - if safe, allow allocation

Page 23: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

Handling Deadlocks

• Deadlock Prevention

Provide all required resources from start itself.

Prioritize processes. Assign resources accordingly.

Inefficient and effects Concurrency.

Make Prior Rules: For Ex. – Process P1 cannot request resource

R1 unless it releases resource R2.

Future resource requirement unpredictable.

• Drawbacks

Starvation possible.

Page 24: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

1.a Prevent the circular-wait condition by defining a linear ordering of resource types

A process can be assigned resources only according to the linear ordering

Disadvantages- Resources cannot be requested in the order that are needed- Resources will be longer than necessary

1.b Prevent the hold-and-wait condition by requiring the process to acquire all needed resources before starting execution

Disadvantages Inefficient use of resources Reduced concurrency Process can become deadlocked during the initial resource

acquisition Future needs of a process cannot be always predicted

Page 25: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

25

Deadlock Detection Principle of operation

Detection of a cycle in WFG proceeds concurrently with normal operation

Requirements for the deadlock detection and resolution algorithms Detection

The algorithm must detect all existing deadlock in finite time The algorithm should not report non-existent (phantom) deadlock

Resolution (recovery) All existing wait-for dependencies in WFG must be removed, i.e. roll-

back one or more processes that are deadlocked and give their resources to other blocked processes

Observation Deadlock detection is the most popular strategy for handling

deadlocks in distributed systems

Page 26: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

Handling Deadlocks

• Deadlock Detection

Resource allocation with an optimistic outlook. Periodically examine process status. Detect then break the Deadlock.

• Resolution – Roll back 1 or More processes and break dependency.

CSE - 8344

Page 27: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

Issues in distributed systems Special issues in distributed systems

Resources are distributed across many sites The control processes that control access to

resources do not have complete, up-to-date information on the global state of the system

Page 28: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

28

Distributed Deadlocks Centralized Control

One control node (Coordinator) maintains Global WFG and searches for cycles A control site constructs wait-for graphs (WFGs) and checks for directed cycles. WFG can be maintained continuously (or) built on-demand by requesting WFGs

from individual sites. Distributed Control

Each node equally responsible in maintaining Global WFG and detecting Deadlocks.

WFG is spread over different sites.Any site can initiate the deadlock detection process.

Hierarchical Control Nodes organized in a tree, where each site detects deadlocks involving only its

descendants. Sites are arranged in a hierarchy. A site checks for cycles only in descendents.

Page 29: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

29

Deadlock in resource allocation:Algorithms for distributed deadlock detection 3) Deadlock Detection (cont.)

Control for distributed deadlock detection can be:a. Centralized

b. Distributed

c. Hierarchical

 a.1 Centralized deadlock detection algorithms A central control site constructs the global WFG and searches for cycles Control site an maintain WFG continuously (with every assignment) or when

running deadlock detection (and asking all sites for WFG updates) Disadvantages: single point of failure and congestion

 a.2

Page 30: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

30

Deadlock in resource allocation:Algorithms for distributed deadlock detection   3) Deadlock Detection (cont.)

b. Hierarchical deadlock detection algorithms Sites organized in a tree structure with one site at the root of the

tree Each node (except for leaf nodes) has information about the

dependent nodes Deadlock is detected by the node that is the common ancestor of

all sites which have resource allocations in conflict Deadlock is detected at the lowest level

Page 31: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

Deadlock Detection Algorithms

• Centralized Deadlock Detection

• Distributed Deadlock Detection

• Hierarchical Deadlock Detection

Ho-Ramamoorthy’s one and two phase algorithms. Completely Centralized Algorithm

Obermarck’s Path Pushing Algorithm. Chandy-Misra-Haas Edge Chasing algorithm.

Menasce-Muntz Algorithm. Ho-Ramamoorthy’s Algorithm.

Page 32: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

The completely centralized

algorithm All sites request resources and release resources by sending

corresponding messages to control site Control site updates WFG for each request/release For every new request edge added to WFG, control site checks WFG for

deadlock Alternative: each site maintain its WFG and update control site periodically

or on request

32

Page 33: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

33

Centralized Algorithms

Ho-Ramamurthy 2-phase Algorithm Each site maintains a status table of all processes initiated at

that site: includes all resources locked & all resources being waited on.

Controller requests (periodically) the status table from each site. Controller then constructs WFG from these tables, searches for

cycle(s). If no cycles, no deadlocks. Otherwise, (cycle exists): Request for state tables again. Construct WFG based only on common transactions in the 2

tables. If the same cycle is detected again, system is in deadlock. Later proved: cycles in 2 consecutive reports need not result in

a deadlock. Hence, this algorithm detects false deadlocks.

Page 34: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

34

Centralized Algorithms...

Ho-Ramamoorthy 1-phase Algorithm Each site maintains 2 status tables: resource status table and

process status table. Resource table: transactions that have locked or are waiting

for resources. Process table: resources locked by or waited on by

transactions. Controller periodically collects these tables from each site. Constructs a WFG from transactions common to both the

tables. No cycle, no deadlocks. A cycle means a deadlock.

Page 35: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

35

Distributed Algorithms

Path-pushing: resource dependency information disseminated through designated paths (in the graph) [Examples : Menasce-Muntz & Obermarck]

Edge-chasing: special messages or probes circulated along edges of WFG. Deadlock exists if the probe is received back by the initiator. [Examples :CMH for AND Model , Sinha-Natarajan]

Diffusion computation: queries on status sent to process in WFG. [Examples :CMH for OR Model, Chandy-Herman]

Global state detection: get a snapshot of the distributed system. [Examples :Bracha-Toueg,Kshemkalyani-Singhal]

Page 36: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

36

Path-pushing Obermarck’s Algorithm (AND model)

Path Propagation Based Algorithm Based on a database model using transaction

processing Sites which detect a cycle in their partial WFG views

convey the paths discovered to members of the (totally ordered) transaction

Algorithm can detect phantoms due to its asynchronous snapshot method

Page 37: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

S1 S2

S4 S3

Obermark’s Algorithm Example

Intial State

Page 38: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

Obermark’s Algorithm Example

Iteration 1

Page 39: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

Obermark’s Algorithm Example

Iteration 2

Page 40: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

Obermark’s Algorithm Example

Iteration 3

Page 41: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

Obermark’s Algorithm Example

Iteration 4

Page 42: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

42

Edge-Chasing Algorithm

Chandy-Misra-Haas’s Algorithm (AND MODEL): A probe(i, j, k) is used by a deadlock detection process Pi.

This probe is sent by the home site of Pj to Pk. This probe message is circulated via the edges of the graph.

Probe returning to Pi implies deadlock detection. Terms used:

Pj is dependent on Pk, if a sequence of Pj, Pi1,.., Pim, Pk exists.

Pj is locally dependent on Pk, if above condition + Pj,Pk on same site.

Each process maintains an array dependenti: dependenti(j) is true if Pi knows that Pj is dependent on it. (initially set to false for all i & j).

Page 43: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

43

Chandy-Misra-Haas’s AlgorithmSending the probe:

if Pi is locally dependent on itself then deadlock.else for all Pj and Pk such that (a) Pi is locally dependent upon Pj, and (b) Pj is waiting on Pk, and (c ) Pj and Pk are on different sites, send probe(i,j,k) to the home site of Pk.

Receiving the probe:if (d) Pk is blocked, and (e) dependentk(i) is false, and (f) Pk has not replied to all requests of Pj,then begin dependentk(i) := true;

if k = i then Pi is deadlockedelse ...

Page 44: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

44

Chandy-Misra-Haas’s Algorithm

Receiving the probe:…….

else for all Pm and Pn such that (a’) Pk is locally dependent upon Pm, and (b’) Pm is waiting on Pn, and (c’) Pm and Pn are on different sites, send probe(i,m,n) to the home site of Pn.

end.

Performance:For a deadlock that spans m processes over n sites, m(n-1)/2 messagesare needed. Size of the message 3 words.Delay in deadlock detection O(n).

Page 45: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

45

C-M-H Algorithm: Example

P1 P2 P6 P7

P3

P4 P5

Site 1

Site 2

Site 3

( 1,1,2 )

( 1,2,3 )

( 1,2,4 )

( 1,4,5 )

( 1,5,6 )

( 1,6,7 )

( 1,7,1 )

P1 initiates Deadlock Detection by sending Probe Message (1,1,2) to P2

Page 46: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

46

Diffusion-based AlgorithmCMH Algorithm for OR

ModelInitiation by a blocked process Pi: send query(i,i,j) to all processes Pj in the dependent set DSi of Pi; num(i) := |DSi|; waiti(i) := true;

Blocked process Pk receiving query(i,j,k): if this is engaging query for process Pk /* first query from Pi */

then send query(i,k,m) to all Pm in DSk;numk(i) := |DSk|; waitk(i) := true;

else if waitk(i) then send a reply(i,k,j) to Pj.

Process Pk receiving reply(i,j,k) if waitk(i) then

numk(i) := numk(i) - 1;if numk(i) = 0 then if i = k then declare a deadlock. else send reply(i, k, m) to Pm, which sent the engaging query.

Page 47: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

47

Diffusion Algorithm: Example

Page 48: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource
Page 49: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

49

Engaging Query

How to distinguish an engaging query? query(i,j,k) from the initiator contains a unique

sequence number for the query apart from the tuple (i,j,k).

This sequence number is used to identify subsequent queries.

(e.g.,) when query(1,7,1) is received by P1 from P7, P1 checks the sequence number along with the tuple.

P1 understands that the query was initiated by itself and it is not an engaging query.

Hence, P1 sends a reply back to P7 instead of forwarding the query on all its outgoing links.

Page 50: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

Mitchell-Merritt Algorithm(Edge-Chasing Category)

Each Node has two labels : Public & Private Private Label is unique to node but may change Initially both private and public label values are same Guarantees that only one process will detect the deadlock Process/Node/Site responsible for deadlock detection propagates

public label in reverse direction When a blocked transaction reads the public label of waiting upon

process it changes its public label if its own public label value is less than read value.

When a initiator process reads the message with public label equals to its own then deadlock is detected.

Page 51: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

Mitchell-Merritt AlgorithmThe algorithm exhibits 4 nondeterministic

state transitions

u v

State BeforeState After

Outdegree =0

1. Block State

x vx

Value x should be computed as per function inc(u,v) i.e. any value which is larger than both u,v

1. This block step occurs when a process begins to wait on some resource held by other [ Creates an edge in WFG]

2. Label change occurs in this step for waiting process

3. Both public and private labels of the waiting process are increased to a value greater than their previous values & greater than the public label of the process being waited on.

Page 52: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

State Before

2. Activate

• Earlier there is an edge in the before state, but there will be no edge in the after state

• Edge disappeared [Either process may be allocated resource, or timed out or owner of the resource may have changed]

State After

Page 53: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

u v

State Before

3. Transmit State

v v

1. When a waiting process reads public variable of waiting upon process

2. If the public label of waiting process is smaller than the public label of the process upon whom it is waiting, then waiting process will change its public label equal to the public label of the process upon whom it is waiting.

3. Waiting process’s private label remains unchanged

State After

If u < v

Page 54: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

u u

State Before

4. Detect State

u u

1. When a process sees its own public label comes back to itself

2. When a process reads a public label of the waiting upon process and finds that the public label value of waiting upon process is equals to its own public label value then it determines that a cycle exists and declares deadlock

State After

uu

Page 55: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

Mitchell-Merritt Algorithm Example

public

privateNode

(public-value,node-id)

(private-value,node-id)

1,1

1,1

3,3

3,3

5,5

5,5

4,4

4,4

Initially both public and private label values at each node are equal

P1

P5

P3

P4

Page 56: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

Mitchell-Merritt Algorithm Example cont…

4,1

4,1

3,3

3,3

5,5

5,5

4,4

4,4

P1

P5

P3

P4

Now suppose P1 is waiting for P3 (P1 P3)

Block state will occur for P1

Block

Page 57: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

Mitchell-Merritt Algorithm Example cont…

4,1

4,1

3,3

3,3

6,5

6,5

4,4

4,4

P1

P5

P3

P4

Now suppose P5 is waiting for P1 (P5 P1)

Block state will occur for P5

Block

Block

Page 58: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

Mitchell-Merritt Algorithm Example cont…

4,1

4,1

7,3

7,3

6,5

6,5

4,4

4,4

P1

P5

P3

P4

Block

BlockBlock

Now suppose P3 is waiting for P5 (P3 P5)

Block state will occur for P3

Page 59: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

Mitchell-Merritt Algorithm Example cont…

7,34,1

7,3

7,3

6,5

6,5

4,4

4,4

P1

P5

P3

P4

Now P3 initiates Transmit Phase

P3 will transmit its public label to P1 (Reverse Direction)

Transmit

Here P1 reads public label of P3

P1’s public label =(4,1)

P3’s public label =(7,3)

So P1 will change is public label to (7,3)

But No change for private label of P1

Page 60: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

Mitchell-Merritt Algorithm Example cont…

7,34,1

7,3

7,3

7,36,5

4,4

4,4

P1

P5

P3

P4

P1 will transmit its public label to P5 (Reverse Direction)

Transmit

P1’s public label =(7,3)

P5’s public label =(6,5)

So P5 will change is public label to (7,3)

But No change for private label of P5

Transmit

Page 61: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

Mitchell-Merritt Algorithm Example cont…

7,34,1

7,3

7,3

7,36,5

4,4

4,4

P1

P5

P3

P4

P5 will transmit its public label to P3 (Reverse Direction)

Transmit

P5’s public label =7,3

P3’s public label =7,3

So P3 Detects DeadlockTransmit

Transmit

Page 62: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

Hierarchical Deadlock Detection

• Menasce-Muntz Algorithm

Sites (controllers) organized in a tree structure.

Leaf controllers manage local WFG.

Upper controllers handle Deadlock Detection. Each Parent node maintains a Global WFG,

union of WFG’s of its children. Deadlock detected for its children.

Changes propagated upwards in the tree.

CSE - 8344

Page 63: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

• Ho-Ramamoorthy’s Algorithm

Hierarchical Deadlock Detection

Sites grouped into clusters.

Periodically 1 site chosen as central control site: Central control site chooses controls site

for other clusters. Control site for each cluster collects the status

graph there: Ho-Ramamoorthy’s 1-phase algorithm

centralized DD algorithm used. All control sites forward status report to Central

Control site which combines the WFG and performs cycle search.

Page 64: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

64

Hierarchical Deadlock Detection

• Follows Ho-Ramamoorthy’s 1-phase algorithm. More than 1 control site organized in hierarchical manner. • Each control site applies 1-phase algorithm to detect (intracluster) deadlocks.• Central site collects info from control sites, applies 1-phase algorithm to detect intracluster deadlocks.

Central Site

Controlsite

Controlsite

Controlsite

Page 65: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

65

Persistence & Resolution

Deadlock persistence: Average time a deadlock exists before it is resolved.

Implication of persistence: Resources unavailable for this period: affects utilization Processes wait for this period unproductively: affects response

time. Deadlock resolution:

Aborting at least one process/request involved in the deadlock. Efficient resolution of deadlock requires knowledge of all

processes and resources. If every process detects a deadlock and tries to resolve it

independently -> highly inefficient ! Several processes might be aborted.

Page 66: Deadlocks – An Introduction What Are DEADLOCKS ?  A Blocked Process which can never be resolved unless there is some outside Intervention.  Resource

66

Deadlock Resolution

Priorities for processes/transactions can be useful for resolution. Consider priorities introduced in Obermarck’s algorithm. Highest priority process initiates and detects deadlock

(initiations by lower priority ones are suppressed). When deadlock is detected, lowest priority process(es) can

be aborted to resolve the deadlock. After identifying the processes/requests to be aborted,

All resources held by the victims must be released. State of released resources restored to previous states. Released resources granted to deadlocked processes.

All deadlock detection information concerning the victims must be removed at all the sites.