Syllabus   Blank Homework  
Notes   Labs   Scores   Blank

Lecture Notes
Dr. Tong Lai Yu, March 2010
    0. Review and Overview
    1. An Introduction to Distributed Systems
    2. Deadlocks
    3. Distributed Systems Architecture
    4. Processes
    5. Communication
    6. Distributed OS Theories
        7. Distributed Mutual Exclusions
    8. Agreement Protocols
    9. Distributed Scheduling
    10. Distributed Resource Management
    11. Recovery and Fault Tolerance
    12. Security and Protection
     
    
    I know of no more encouraging fact,
    than the unquestionable ability of man
    to elevate his life by conscious endeavor.
    
                            Henry David Thoreau
    
    Deadlocks
    1. Introduction

      processes are blocked, waiting on events that could never happen

      different from starvation ( the associated resource is in continuous use )

      Four necessary conditions for deadlock:

      e.g. Resources are two books: Java Programming, OS Principles,
             need the two books to finish project

    2. Deadlock handling strategies
      deadlock prevention, avoidance, detection, recovery

    3. Resource graph for single-unit resource type

      cycle => deadlock
      deadlock => cycle

    4. Graph-theoretic model
      reusable resource -- can be used again and again ( e.g. CPU, main-memory, I/O devices )
      consumable resource -- vanish as a result of its use ( e.g. messages, signals )
    5. Created (produced) by a process
    6. Destroyed (consumed) by a process
    7. Operations: request/receive (implies consume), produce/send
    8. Deadlock may occur if the receive operation can block
    9. Potential deadlock situations are more difficult to detect, and reproduce, by testing

    10. resource access -- can be exclusive or shared

      General resource system

    11. nonempty set of processes P = { P1, P2, P3, ..., Pn}
    12. nonempty set of resources G = { R1, R2, R3, ..., Rm}

      G = Gr    ∪    Gc
         reusable    consumable

      Gr       Gc = Ø    ( disjoint )

    13. for every reusable Ri
      ti = |Ri| = # of units of resource of type i
          ≥ 0
    14. for every consumable Ri
      there exists subset R C P
      producers of Ri

      consumable resource -- concentric rectangle  
      process -- circle    O

    15. General resource graph

      a bi-partite directed graph with set of nodes:
      P = { P1, P2, P3, ..., Pn}
      G = { R1, R2, R3, ..., Rm}

      available units vector ( a1, a2, a3, ..., am)
      A bi-partite graph ( bigraph ) is a graph whose nodes can be divided into two disjoint sets such that two adjacent nodes cannot come from the same set.

      for every reusable resource Ri:

      • # of assignment edges #( Ri, * ) ≤ ti

      • ai = ti - #(Ri, * )

      • a process cannot request more than the total number of units of a resusable resource
        #(Pj, Ri ) ≤ ti - #(Ri, Pj )

      for every consumable resource Ri

      • ( Ri, Pj ) exists iff Pj is a producer of Ri

      • ai ≥ 0
      if #( Pi, Rj ) > aj => pi blocked ( more requests than available resources )

    16. Reduction of Resource Graph
      If a process's resource requests can be granted, then we say that the graph can be reduced by that process
      ( i.e. the process is allowed to complete its execution and return all its resources )
      consider reusable resources only If a graph can be reduced by all the processes, then there is no deadlock.
      If a graph cannot be reduced by all the processes, the irreducible processes constitute the set of deadlock processes in the graph
      An example of reduction of an RAG ( Resource Allocation Graph )

      Example of RAG with loop but no deadlock

      Now if we consider both reusable and consumable resources:

      graph completely reducible => state deadlock free
      but deadlock free may not => graph completely reducible

      necessary and sufficient conditions for deadlock

      A state is an expedient state if all processes having outstanding requests are blocked.

      Expedient State

      if node only has incoming edges => sink


      Definition
      A knot K in a graph is a nonempty set of nodes such that for every node x in K, all nodes in K and only the nodes in K are reachable from x.
      ( all x, all y ∈ K => x → y ) AND ( all x ∈ K, some z, such that x → z => z ∈ K )

      Question: Any knot? Any deadlock?


      Question: Any knot? Any deadlock?

      Example

      Question: Any knot in the above figure?

      Theorem

    17. A cycle is a necessary condition for a deadlock.
    18. If the graph is expedient, then a knot is a sufficient condition for deadlock.
    19. Note: A knot is a sufficient condition but not a necessary condition for deadlock. (i.e. A set of processes can have deadlock without a knot.)

      Systems with Single-unit Requests

    20. A process can only request one resource unit at a time.
    21. Theorem: A knot is a necessary and sufficient condition for deadlock.
    22. Systems with Single-unit Resources

    23. There is only one unit of every resource.
    24. Theorem: A cycle in an expedient graph is a necessary and sufficient condition for deadlock.
    25. System with only consumable resources

    26. such as interrupts, signals, messages, and data in I/O buffers
    27. deadlock may occur if a receive operation is blocking

      Definition: claim-limited graph of a consumable resource system:
    28. each resource has 0 available units
    29. it has a request edge ( pi, Rj ) iff Pi is a consumer of Rj
    30. This claim-limited graph cannot be reduced (R1, R2 has zero available unit)
      Theorem: A consumable resource only system is deadlock free if its claim-limited graph is completely reducible.
      But a system may fail the claim-limited graph reducibility test, and still be free from deadlock.

    31. Example: Both P1 and P2 are producers and consumers.

      Process P1Process P2
      .
      down ( mutex );
      critical_section();
      up ( mutex );
      .
      loop
        .
      down ( mutex );
      critical_section();
      up ( mutex );
      .
      loop

      System with only Reusable Resources

      A system is not in a deadlock state if and only if the resource graph is completely reducible.

    32. Deadlock Avoidance requires that the maximum resource requirement of a process be known at every state during its execution ( claim of the process )
      resource is granted only if the resulting state is safe
      a state is safe if there exists at least one sequence of execution for all processes such that all of them can run to completion

      Trajectory Diagram

      A deadlock path

      Question: What is the difference between a safe state and a deadlock-free state?

      How do we know a state is safe?

      • Start in the given state
      • Simulate running each process to completion, by allocating its maximum resource requirements, and then releasing all resources
      • If all processes can complete, the state is safe

      Habermann's Algorithm ( generalization of Dijkstra's Algorithm )

      n processes, m types of resources

      Max-Avail matrix A = ( a1 a2 ... am )
      where ai = ti = |Ri|
      Max-Claim matrix B =
      b 11 b 12 ... b 1m
      b 21 b 22 ... b 2m
      . .   .    .
      b n1 b n2 ... b nm
      =
      B1
      B2
      .
      Bn
      where bij = max number of units of Resource Rj that will ever be held by process Pi
      Allocation matrix C =
      c 11 c 12 ... c 1m
      c 21 c 22 ... c 2m
      . .   .    .
      c n1 c n2 ... c nm
      =
      C1
      C2
      .
      Cn
      where cij = number of units of Resource Rj that are currently held by process Pi

    33. all k, Bk ≤ A ( no process can claim more units of Resources than are available )
    34. C ≤ B ( no process attempts to request more resources than its maximum claim )

    35. n
      k=1
      Ck ≤ A ( never allocate more resources than are available )
    36. Available matrix D:
      D = ( d1 d2 ... dm ) = A - n
      k=1
      Ck
      di = number of units of Resourc Ri available in current state
    37. Need matrix E:
      Need matrix E =
      e 11 e 12 ... e 1m
      e 21 e 22 ... e 2m
      . .   .    .
      e n1 e n2 ... e nm
      = B - C =
      E1
      E2
      .
      En
    38. Request matrix F:
      Request matrix F =
      f 11 f 12 ... f 1m
      f 21 f 22 ... f 2m
      . .   .    .
      f n1 f n2 ... f nm
      =
      F1
      F2
      .
      Fn
    39. tentative state:
      Suppose we grant all requests and see what would happen.

      D ← D - Fi ( avialable - requests )
      Ci ← Ci + Fi ( allocated + requests )
      Ei ← Ei - Fi ( need - requests )


      The request is granted only if the tentative state is a safe state

    40. Safe-State Check Algorithm
      1. Pick an unfinished process Pi such that Ei ≤ D (i.e more resources available than needed by Pi ). If no such process exists, go to Step 3.
      2. D ← D + Ci. Tag Pi as finished. Go to step 1.
      3. If all processes are tagged finished, the system state is safe; otherwise it is not safe.

      If the system is not safe, the request is blocked and the system state is reset by

      D ← D + Fi
      Ci ← Ci - Fi
      Ei ← Ei + Fi
      In addition, a process tagged with finished in step 2 is reset by:
      D ← D - Ci

      and retag Pi as unfinished.

    41. Example

      max-Avail A = ( 2 4 3 )

      Max-Claim B =
      1 2 2
      1 2 1
      1 1 1
      Allocation C =
      1 2 0
      0 1 1
      1 0 1

      Available D = ( 0 1 1 )

      Need E =
      0 0 2
      1 1 0
      0 1 0

      Suppose process P1 makes a request
      F1 = ( 0 0 1 )

      The tentative state would be:

      Available D = ( 0 1 0 )

      Allocation C =
      1 2 1
      0 1 1
      1 0 1
      Need E =
      0 0 1
      1 1 0
      0 1 0
      In this state, P3 can complete because E3 ≤ D returning ( 1 0 1 ) to the available pool of resources,

      D = ( 1 1 1 )

      Thus, the outstanding needs of both P1 and P2 can be satisfied and consequently the tentative state resulting from the request P1 is safe and the request F1 of P1 can be granted.