1
Distributed process management:
Distributed deadlock
Created By:
Er. Shikha Manrai
2
Distributed deadlock
• Problem definition
– Permanent blocking of a set of processes that either compete for system
resources or communicate with each other
– No node has complete and up-to-date knowledge of the entire distributed
system
– Message transfers between processes take unpredictable delays
• Types of distributed deadlock
– Resource deadlock
• 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 deadlocks:
• Set of deadlocked processes, where each process waits to receive messages
(communication) from other processes in the set.
3
Distributed deadlock (cont.)
• System state representation with wait-for graphs (WFG)
– Nodes are processes, P1, P2, etc.
– Directed edge from P1 to P2 if P1 blocked and waiting for P2 to release a
resource
– System is deadlocked if there is a directed cycle
4
Deadlock in resource allocation
• Conditions for deadlock in resource allocation
– Mutual exclusion: The resource can be used by only one process at a time
– Hold and wait: A process holds a resource while waiting for other resources
– No preemption: A process cannot be preempted to free up the resource
– Circular wait: A closed cycle of processes is formed, where each process
holds one or more resources needed by the next process in the cycle
• Strategies
– Prevent the formation of a circular wait
– Detect the potential or the actual occurrence of a circular wait
• Types of algorithms
– Deadlock prevention
– Deadlock avoidance
– Deadlock detection
• 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
5
Deadlock in resource allocation: Deadlock handling strategies
(1) Deadlock prevention
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
6
Deadlock in resource allocation: Deadlock handling strategies
(1) Deadlock prevention (cont.)
1.c Use of time-stamps
• Example: Use time-stamps for transactions to a database – each transaction
has the time-stamp of its creation
• The circular wait condition is avoided by comparing time-stamps: strict
ordering of transactions is obtained, the transaction with an earlier time-
stamp always wins
• “Wait-die” method
if [ e (T2) < e (T1) ]
halt_T2 (‘wait’);
else
kill_T2 (‘die’);
• “Wound-wait” method
if [ e (T2) < e (T1) ]
kill_T1 (‘wound’);
else
halt_T2 (‘wait’);
7
Deadlock in resource allocation (cont.)
(2) Deadlock avoidance
– Decision made dynamically, before allocating a resource, the resulting
global system state is checked - if safe, allow allocation
– Disadvantages
• 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
8
Deadlock in resource allocation (cont.)
(3) 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
9
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 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
10
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
11
Deadlock in resource allocation:
Algorithms for distributed deadlock detection (cont.)
3) Deadlock Detection (cont.)
c. Distributed deadlock detection algorithms
– Principles
• All sites responsible for detecting a global deadlock
• Global state graph distributed over many sites: several of them participate in detection
• Detection initiated when a process suspected to be deadlocked
• Advantages: No single point of failure, no congestion
• Disadvantages: Difficult to implement (no shared memory)
– Types of algorithms
• Path-pushing algorithms
– Each node builds a WFG based on local info & info from other sites
– Detect and resolves local deadlocks
– Transmits to other sites deadlock info in form of (waiting path)
• Edge-chasing algorithms
– Special messages (probes) sent along edges of WFG to detect a cycle
– When blocked process receives probe, resends it on its outgoing edges of WFG
– When a process receives a probe it initiated, declares deadlock
12
Deadlock in message communication
• Mutual Waiting
– Deadlock conditions
• Each of a group of processes is waiting for a message from another member of
the group
• There are no messages in transit
– Concepts
• Dependence set (DS) of process Pi is the set of all processes from which Pi is
expecting a message
• Pi can proceed when any of the expected messages arrive
• Deadlock in a set S of processes
– All processes in S are stopped, waiting for messages
– S contains the dependence set of all processes in S
– No messages are in transit between processes in S
13
Deadlock in message communication
• Mutual Waiting (cont.)
– Resource deadlock vs. message deadlock
• Resource deadlock
– A deadlock exists if there is a cycle in the WFG
– A process Pi is dependent on process Pj if Pj holds a resource that Pi needs
• Message deadlock
– All successors Pj of a process Pi in S are also in S
– Example
• Fig. 14.16a
– P1 is waiting for a message from either P2 or P5
– P5 is not waiting for any message; sends a message to P1, which is released
– Links (P1, P5) and (P1, P2) are removed
– No deadlock
• Fig. 14.16b
– P5 is now waiting for a message from P2
– P2 is waiting for a message from P3
– P3 is waiting for a message from P1
– P1 is waiting for a message from P2
– Deadlock
– Solution: prevention or detection
14
Deadlock in message communication: Mutual waiting (cont.)
15
Deadlock in message communication
• Unavailability of Message Buffers
– Deadlock can occur in the allocation of buffers for the storage of messages
in transit (Example: packet-switching data networks)
1. Direct store-and-forward deadlock
• Example:
– Two packet switching nodes, each using a common buffer pool from which buffers
are assigned to packets on demand
– Buffer space for A is filled with packets destined for B
– Buffer space for B is filled with packets destined for A
– Neither node can transmit or receive packets: deadlock
• Solution: Use separate buffers, one for each link
16
Deadlock in message communication (cont.)
• Unavailability of Message Buffers (cont.)
2. Indirect store-and-forward deadlock
• For each node, the queue to the adjacent node in one direction is full with
packets destined for the next node beyond
17
Deadlock in message communication (cont.)
• Unavailability of Message Buffers (cont.)
2. Indirect store-and-forward deadlock:
Solution
• Use a structured buffer pool,
hierarchically organized, with N+1 levels
(N is the maximum number of hops an any
network path)
• Common pool – class 0 is unrestricted:
any incoming packet can be stored there
• Buffers at level k (where 0 < k  N) are
reserved for packets that have traveled at
least k hops so far
• Under heavy load, buffers will fill from 0
to N
• When buffers fill to level k, new incoming
packets that passed k hops or less are
discarded
• No direct or indirect store-and-forward
deadlock can occur
18
Deadlock in message communication: (cont.)
• Unavailability of Message Buffers (cont.)
3. Deadlock in a distributed OS using message passing for inter-process
communication
• A non-blocking Send operation requires a buffer to hold outgoing messages
• Example 1
• Process X has a buffer of size n
• After sending n messages, buffer is full
• When sending message n+1, process X will block until sufficient buffer is freed
• Example 2
• Process X has a buffer of size n
• Process Y has a buffer of size m
• Both buffers, n and m, become full and the two processes are blocked: deadlock
• Possible solutions
• Prevention: estimate maximum number of messages in transit and allocate
corresponding number of buffers
• Detection: detect deadlock and roll back one of the processes
19
Deadlock in message communication:
Unavailability of message buffers (cont.)

Distributed process management Distributed deadlock.ppt

  • 1.
    1 Distributed process management: Distributeddeadlock Created By: Er. Shikha Manrai
  • 2.
    2 Distributed deadlock • Problemdefinition – Permanent blocking of a set of processes that either compete for system resources or communicate with each other – No node has complete and up-to-date knowledge of the entire distributed system – Message transfers between processes take unpredictable delays • Types of distributed deadlock – Resource deadlock • 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 deadlocks: • Set of deadlocked processes, where each process waits to receive messages (communication) from other processes in the set.
  • 3.
    3 Distributed deadlock (cont.) •System state representation with wait-for graphs (WFG) – Nodes are processes, P1, P2, etc. – Directed edge from P1 to P2 if P1 blocked and waiting for P2 to release a resource – System is deadlocked if there is a directed cycle
  • 4.
    4 Deadlock in resourceallocation • Conditions for deadlock in resource allocation – Mutual exclusion: The resource can be used by only one process at a time – Hold and wait: A process holds a resource while waiting for other resources – No preemption: A process cannot be preempted to free up the resource – Circular wait: A closed cycle of processes is formed, where each process holds one or more resources needed by the next process in the cycle • Strategies – Prevent the formation of a circular wait – Detect the potential or the actual occurrence of a circular wait • Types of algorithms – Deadlock prevention – Deadlock avoidance – Deadlock detection • 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
  • 5.
    5 Deadlock in resourceallocation: Deadlock handling strategies (1) Deadlock prevention 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
  • 6.
    6 Deadlock in resourceallocation: Deadlock handling strategies (1) Deadlock prevention (cont.) 1.c Use of time-stamps • Example: Use time-stamps for transactions to a database – each transaction has the time-stamp of its creation • The circular wait condition is avoided by comparing time-stamps: strict ordering of transactions is obtained, the transaction with an earlier time- stamp always wins • “Wait-die” method if [ e (T2) < e (T1) ] halt_T2 (‘wait’); else kill_T2 (‘die’); • “Wound-wait” method if [ e (T2) < e (T1) ] kill_T1 (‘wound’); else halt_T2 (‘wait’);
  • 7.
    7 Deadlock in resourceallocation (cont.) (2) Deadlock avoidance – Decision made dynamically, before allocating a resource, the resulting global system state is checked - if safe, allow allocation – Disadvantages • 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
  • 8.
    8 Deadlock in resourceallocation (cont.) (3) 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
  • 9.
    9 Deadlock in resourceallocation: 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 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
  • 10.
    10 Deadlock in resourceallocation: 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
  • 11.
    11 Deadlock in resourceallocation: Algorithms for distributed deadlock detection (cont.) 3) Deadlock Detection (cont.) c. Distributed deadlock detection algorithms – Principles • All sites responsible for detecting a global deadlock • Global state graph distributed over many sites: several of them participate in detection • Detection initiated when a process suspected to be deadlocked • Advantages: No single point of failure, no congestion • Disadvantages: Difficult to implement (no shared memory) – Types of algorithms • Path-pushing algorithms – Each node builds a WFG based on local info & info from other sites – Detect and resolves local deadlocks – Transmits to other sites deadlock info in form of (waiting path) • Edge-chasing algorithms – Special messages (probes) sent along edges of WFG to detect a cycle – When blocked process receives probe, resends it on its outgoing edges of WFG – When a process receives a probe it initiated, declares deadlock
  • 12.
    12 Deadlock in messagecommunication • Mutual Waiting – Deadlock conditions • Each of a group of processes is waiting for a message from another member of the group • There are no messages in transit – Concepts • Dependence set (DS) of process Pi is the set of all processes from which Pi is expecting a message • Pi can proceed when any of the expected messages arrive • Deadlock in a set S of processes – All processes in S are stopped, waiting for messages – S contains the dependence set of all processes in S – No messages are in transit between processes in S
  • 13.
    13 Deadlock in messagecommunication • Mutual Waiting (cont.) – Resource deadlock vs. message deadlock • Resource deadlock – A deadlock exists if there is a cycle in the WFG – A process Pi is dependent on process Pj if Pj holds a resource that Pi needs • Message deadlock – All successors Pj of a process Pi in S are also in S – Example • Fig. 14.16a – P1 is waiting for a message from either P2 or P5 – P5 is not waiting for any message; sends a message to P1, which is released – Links (P1, P5) and (P1, P2) are removed – No deadlock • Fig. 14.16b – P5 is now waiting for a message from P2 – P2 is waiting for a message from P3 – P3 is waiting for a message from P1 – P1 is waiting for a message from P2 – Deadlock – Solution: prevention or detection
  • 14.
    14 Deadlock in messagecommunication: Mutual waiting (cont.)
  • 15.
    15 Deadlock in messagecommunication • Unavailability of Message Buffers – Deadlock can occur in the allocation of buffers for the storage of messages in transit (Example: packet-switching data networks) 1. Direct store-and-forward deadlock • Example: – Two packet switching nodes, each using a common buffer pool from which buffers are assigned to packets on demand – Buffer space for A is filled with packets destined for B – Buffer space for B is filled with packets destined for A – Neither node can transmit or receive packets: deadlock • Solution: Use separate buffers, one for each link
  • 16.
    16 Deadlock in messagecommunication (cont.) • Unavailability of Message Buffers (cont.) 2. Indirect store-and-forward deadlock • For each node, the queue to the adjacent node in one direction is full with packets destined for the next node beyond
  • 17.
    17 Deadlock in messagecommunication (cont.) • Unavailability of Message Buffers (cont.) 2. Indirect store-and-forward deadlock: Solution • Use a structured buffer pool, hierarchically organized, with N+1 levels (N is the maximum number of hops an any network path) • Common pool – class 0 is unrestricted: any incoming packet can be stored there • Buffers at level k (where 0 < k  N) are reserved for packets that have traveled at least k hops so far • Under heavy load, buffers will fill from 0 to N • When buffers fill to level k, new incoming packets that passed k hops or less are discarded • No direct or indirect store-and-forward deadlock can occur
  • 18.
    18 Deadlock in messagecommunication: (cont.) • Unavailability of Message Buffers (cont.) 3. Deadlock in a distributed OS using message passing for inter-process communication • A non-blocking Send operation requires a buffer to hold outgoing messages • Example 1 • Process X has a buffer of size n • After sending n messages, buffer is full • When sending message n+1, process X will block until sufficient buffer is freed • Example 2 • Process X has a buffer of size n • Process Y has a buffer of size m • Both buffers, n and m, become full and the two processes are blocked: deadlock • Possible solutions • Prevention: estimate maximum number of messages in transit and allocate corresponding number of buffers • Detection: detect deadlock and roll back one of the processes
  • 19.
    19 Deadlock in messagecommunication: Unavailability of message buffers (cont.)