deadlock in distributed enviornment (1)

Upload: tarun1992sharma2013

Post on 04-Jun-2018

224 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/13/2019 Deadlock in Distributed Enviornment (1)

    1/31

    Deadlock in Distributed

    Environment

  • 8/13/2019 Deadlock in Distributed Enviornment (1)

    2/31

    Introduction

    Deadlocks is a fundamental problem in distributedsystems.

    A process may request resources in any order,which may not be known a priori and a processcan request resource while holding others.

    If the sequence of the allocations of resources tothe processes is not controlled, deadlocks canoccur.

    A deadlock is a state where a set of processesrequest resources that are held by otherprocesses in the set.

  • 8/13/2019 Deadlock in Distributed Enviornment (1)

    3/31

    System Model

    A distributed program is composed of a set of n

    asynchronous processes p1, p2, . . . , pi , . . . , pn

    that communicates by message passing over the

    communication network.

    Without loss of generality we assume that each

    process is running on a different processor.

    The processors do not share a common globalmemory and communicate solely by passing

    messages over the communication network.

  • 8/13/2019 Deadlock in Distributed Enviornment (1)

    4/31

    System Model

    There is no physical global clock in the system to whichprocesses have instantaneous access.

    The communication medium may deliver messages outof order, messages may be lost garbled or duplicated

    due to timeout and retransmission, processors may failand communication links may go down.

    The following assumptions are made:

    The systems have only reusable resources.

    Processes are allowed to make only exclusive access to resources.

    There is only one copy of each resource.

  • 8/13/2019 Deadlock in Distributed Enviornment (1)

    5/31

    System Model

    A process can be in two states: running or

    blocked.

    In the running state (also called active state), a

    process has all the needed resources and is

    either executing or is ready for execution.

    In the blocked state, a process is waiting to

    acquire some resource.

  • 8/13/2019 Deadlock in Distributed Enviornment (1)

    6/31

    Wait-For-Graph (WFG)

    The state of the system can be modeled by

    directed graph, called a wait for graph (WFG).

    In a WFG , nodes are processes and there is a

    directed edge from node P1 to mode P2 if P1

    is blocked and is waiting for P2 to release

    some resource.

    A system is deadlocked if and only if there

    exists a directed cycle or knot in the WFG.

  • 8/13/2019 Deadlock in Distributed Enviornment (1)

    7/31

    WFG: An Example

  • 8/13/2019 Deadlock in Distributed Enviornment (1)

    8/31

  • 8/13/2019 Deadlock in Distributed Enviornment (1)

    9/31

    Deadlock prevention

    Deadlock prevention is commonly achieved

    either by having a process acquire all the

    needed resources simultaneously before it

    begins executing or by preempting a process

    which holds the needed resource.

    This approach is highly inefficient and

    impractical in distributed systems.

  • 8/13/2019 Deadlock in Distributed Enviornment (1)

    10/31

    Deadlock avoidance

    In deadlock avoidance approach to distributed

    systems, a resource is granted to a process if

    the resulting global system state is safe (note

    that a global state includes all the processes

    and resources of the distributed system).

    However, due to several problems, deadlock

    avoidance is impractical in distributedsystems.

  • 8/13/2019 Deadlock in Distributed Enviornment (1)

    11/31

    Deadlock detection

    Deadlock detection requires examination of

    the status of process-resource interactions for

    presence of cyclic wait.

    Deadlock detection in distributed systems

    seems to be the best approach to handle

    deadlocks in distributed systems.

  • 8/13/2019 Deadlock in Distributed Enviornment (1)

    12/31

    Issues in Deadlock Detection

    Deadlock handling using the approach ofdeadlock detection entails addressing two basicissues:

    (i) Detection of existing deadlocks

    (ii) Resolution of detected deadlocks.

    Detection of deadlocks involves addressing twoissues:

    (i) Maintenance of the WFG(ii) Searching of the WFG for the presence of cycles

    (or knots).

  • 8/13/2019 Deadlock in Distributed Enviornment (1)

    13/31

    Correctness Criteria

    A deadlock detection algorithm must satisfy

    the following two conditions:

    (i) Progress (No undetected deadlocks)

    (ii) Safety (No false/phantom deadlocks)

  • 8/13/2019 Deadlock in Distributed Enviornment (1)

    14/31

    Resolution of a Detected Deadlock

    Deadlock resolution involves breaking existing

    wait-for dependencies between the processes

    to resolve the deadlock.

    It involves rolling back one or more deadlocked

    processes and assigning their resources to

    blocked processes so that they can resume

    execution.

  • 8/13/2019 Deadlock in Distributed Enviornment (1)

    15/31

    Phantom Deadlock

  • 8/13/2019 Deadlock in Distributed Enviornment (1)

    16/31

    Classification of Deadlock Detection

    Algorithms

    Deadlock Detection algorithm can be classifiedinto three categories based upon how theydetect deadlock.

    The categories are: Centralized Approach

    Ho-Rammoorthy Algorithm (One phase and Two Phase)

    Distributed Approach

    Path Pushing Algorithm: Obermark Algorithm

    Edge Chasing Algorithm: Chandy-Misra-Haas

    Hierarchical Approach

  • 8/13/2019 Deadlock in Distributed Enviornment (1)

    17/31

    Centralized Deadlock Detection

    Algorithm

    Every process sends its request/release resource requests to a

    central control site which performs deadlock detection and

    resolution

    Advantages

    Simple and easy to implement

    Disadvantages

    Inefficient (requests for local resources are sent to control

    site)

    Large communication delays

    Congestion

    Fault-tolerance

    Phantom deadlocks

  • 8/13/2019 Deadlock in Distributed Enviornment (1)

    18/31

    Ho-Ramamoorthy 2-phase Algorithm

    Each site maintains a status table of all processes initiated atthat 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 forcycle(s).

    If no cycles, no deadlocks.

    Otherwise, (cycle exists): Request for state tables again.

    Construct WFG based only on common transactions in the 2tables.

    If the same cycle is detected again, system is in deadlock.

    This algorithm detects false deadlocks.

  • 8/13/2019 Deadlock in Distributed Enviornment (1)

    19/31

    Ho-RamamoorthysOne-Phase

    A control site periodically requests a status reportfrom all sites each site maintains resource statustable which lists for each resource the processesthat hold/request local resources

    Process status table which keeps track ofresources held/requested by all local processes

    WFG is constructed by adding arequest/assignment edge between P and R if only

    if P and R appear consistently in both the relevantprocess status and resource status tables

    cons: storage and larger messages

  • 8/13/2019 Deadlock in Distributed Enviornment (1)

    20/31

    Path-Pushing Algorithms

    In path-pushing algorithms, distributed deadlocks aredetected by maintaining an explicit global WFG.

    The basic idea is to build a global WFG for each site of thedistributed system.

    In this class of algorithms, at each site whenever deadlockcomputation is performed, it sends its local WFG to all theneighboring sites.

    After the local data structure of each site is updated, thisupdated WFG is then passed along to other sites, and the

    procedure is repeated until some site has a sufficientlycomplete picture of the global state to announce deadlockor to establish that no deadlocks are present.

    This feature of sending around the paths of global WFG hasled to the term path-pushing algorithms.

  • 8/13/2019 Deadlock in Distributed Enviornment (1)

    21/31

    ObermarcksAlgorithm

    Used for databases

    Transactions lock and wait on resources.

    One transaction can initiate at most one sub-

    transaction at a given point in time.

  • 8/13/2019 Deadlock in Distributed Enviornment (1)

    22/31

    ObermarcksAlgorithm

    A site waits for deadlock-related information(produced in previous iteration) from other sites.

    The site combines the received information andlocal graph to build an updated (global) graph.

    Non-local portion of graph: distinguished bynodes called Ex (External).

    The site detects all cycles and breaks local cycles,i.e., those that do not contain Ex nodes.

    Cycles with Ex nodes are potential globaldeadlocks.

  • 8/13/2019 Deadlock in Distributed Enviornment (1)

    23/31

  • 8/13/2019 Deadlock in Distributed Enviornment (1)

    24/31

    ObermarcksAlgorithm

    Problems: Obermarcksdetect false deadlocks

    -> snapshot of the distributed system taken

    asynchronously by different sites. Global

    cycles can change with time and may not byreflected in the local information

  • 8/13/2019 Deadlock in Distributed Enviornment (1)

    25/31

    Edge Chasing Algorithm

    Chandy-Misra-Haassdistributed deadlock detectionalgorithm for AND model is based on edge-chasing.

    The algorithm uses a special message calledprobe,which is a triplet (i, j, k), denoting that it belongs to adeadlock detection initiated for process Piand it isbeing sent by the home site of process Pjto the homesite of process Pk.

    A probe message travels along the edges of the global

    WFG graph, and a deadlock is detected when a probemessage returns to the process that initiated it.

  • 8/13/2019 Deadlock in Distributed Enviornment (1)

    26/31

    Edge Chasing Algorithm

    A process Pjis said to be dependent on another

    process Pk if there exists a sequence of processes

    Pj, Pi1, Pi2, ...,Pim, Pksuch that each process except

    Pkin the sequence is blocked and each process,except the Pj, holds a resource for which the

    previous process in the sequence is waiting.

    Process Pj is said to be locally dependent uponprocess Pkif Pjis dependent upon Pkand both the

    processes are on the same site.

  • 8/13/2019 Deadlock in Distributed Enviornment (1)

    27/31

    Data Structures

    Each process Pimaintains a boolean array,

    dependenti, where dependenti(j) is true only if

    Pi knows that Pjis dependent on it.

    Initially, dependenti(j) is false for all i and j.

  • 8/13/2019 Deadlock in Distributed Enviornment (1)

    28/31

  • 8/13/2019 Deadlock in Distributed Enviornment (1)

    29/31

    Algorithm

    then

    begin

    dependentk(i) = true;

    if k=i

    then declare that Piis deadlocked

    else for all Pmand Pnsuch that

    (a) Pkis locally dependent upon Pm, and

    (b) Pmis waiting on Pn, and(c) Pmand Pnare on different sites, send aprobe (i, m, n) to the home site of Pn

    End.

  • 8/13/2019 Deadlock in Distributed Enviornment (1)

    30/31

    Performance Analysis

    One probe message (per deadlock detection

    initiation) is sent on every edge of the WFG which

    that two sites.

    Thus, the algorithm exchanges at most m(n 1)/2messages to detect a deadlock that involves m

    processes and that spans over n sites.

    The size of messages is fixed and is very small(only 3 integer words).

    Delay in detecting a deadlock is O(n).

  • 8/13/2019 Deadlock in Distributed Enviornment (1)

    31/31

    P8

    P10

    P9

    P7

    P6

    P5

    P4

    P3

    P2P1

    S1

    S3S2

    Example