PROPRIETARY MATERIAL. © 2007 The McGrawHill Companies, Inc. All rights reserved. No part of this PowerPoint slide may be displayed, reproduced or distributed
in any form or by any means, without the prior written permission of the publisher, or used beyond the limited distribution to teachers and educators permitted by McGrawHill
for their individual course preparation. If you are a student using this PowerPoint slide, you are using it without permission.
Chapter 17: Distributed
Control Algorithms
Dhamdhere: Operating Systems—
A ConceptBased Approach , 2 ed
Slide No: 1
Copyright © 2008
OS control functions in a distributed environment
•
Special features of distributed OS control functions
– Mutual exclusion
* Involves synchronization of processes in different computers
– Deadlock handling
* Deadlocks may involve use of resources in different computers
– Scheduling
* Perform load balancing to ensure uniform loading of computers
– Termination detection
* Check whether all processes of a computation, which may operate
in different computers, have completed
– Election
* Elect a coordinator for a privileged function like resource allocation
Chapter 17: Distributed
Control Algorithms
Dhamdhere: Operating Systems—
A ConceptBased Approach , 2 ed
Slide No: 2
Copyright © 2008
Nature of a distributed control algorithm
•
A distributed control function offers services to both
system and user processes
– It operates in parallel with its clients
•
Following terminology is used to differentiate between
the distributed control algorithm and its clients
– Basic computation: Operation of a client
* Interprocess messages used by it are called basic messages
– Control computation: Operation of the control algorithm
* Interprocess messages exchanged in the control computation are
called control messages
– Basic part and control part of a process
* Participate in the basic and control computations, respectively
Chapter 17: Distributed
Control Algorithms
Dhamdhere: Operating Systems—
A ConceptBased Approach , 2 ed
Slide No: 3
Copyright © 2008
Basic and control parts of a process Pi
• The basic part of Pi interacts with basic parts of other processes through
basic messages; analogously for control part of Pi
• The control part provides services such as resource allocation to the
basic part
Chapter 17: Distributed
Control Algorithms
Dhamdhere: Operating Systems—
A ConceptBased Approach , 2 ed
Slide No: 4
Copyright © 2008
Correctness of a distributed control algorithm
•
Processes of a distributed control algorithm exchange
control data and coordinate through control messages
– New correctness issues arise because
* Exchange of control messages incurs delays
Control data used in processes may become stale or may
appear inconsistent
– Hence correctness has two new facets
* Liveness
The algorithm must eventually perform the correct action
* Safety
The algorithm must not perform wrong actions
Chapter 17: Distributed
Control Algorithms
Dhamdhere: Operating Systems—
A ConceptBased Approach , 2 ed
Slide No: 5
Copyright © 2008
Liveness and safety of
distributed control algorithms
Chapter 17: Distributed
Control Algorithms
Dhamdhere: Operating Systems—
A ConceptBased Approach , 2 ed
Slide No: 6
Copyright © 2008
Distributed mutual exclusion algorithms
•
At any time, at most one process may be in a CS for a
data item ds
– Permission-based algorithms
* A process seeks the permission of a set of processes and enters a
CS only when all processes in the set have granted the permission
– Token-based algorithms
* A token represents a special privilege of some kind, e.g., privilege to
enter a CS
* Only a process possessing the token may perform a privileged
operation
* Processes send the token to one another to pass on the privilege
Chapter 17: Distributed
Control Algorithms
Dhamdhere: Operating Systems—
A ConceptBased Approach , 2 ed
Slide No: 7
Copyright © 2008
Ricart–Agrawala algorithm
•
Steps of the algorithm
1. Process wishing to enter CS sends time-stamped requests to
all other processes
2. When a process receives a request
a. If it is not interested in entering CS, it sends a ‘go ahead’
immediately
b. If it is also interested in entering CS, it sends a ‘go ahead’ only if
the received request’s time-stamp < its own time-stamp
c. If it is in a CS, it adds the request to the pending list
3. When a process receives n -1 ‘go ahead’ replies, it enters CS
4. When a process exits a CS, it sends ‘go ahead’ replies to each
request in its pending list
The algorithm requires 2 x (n – 1) messages per CS entry
Chapter 17: Distributed
Control Algorithms
Dhamdhere: Operating Systems—
A ConceptBased Approach , 2 ed
Slide No: 8
Copyright © 2008
Basic and control actions in
Ricart–Agrawala algorithm
1, 2(b), 3
Chapter 17: Distributed
Control Algorithms
Dhamdhere: Operating Systems—
A ConceptBased Approach , 2 ed
Slide No: 9
Copyright © 2008
Maekawa algorithm
•
Each process has a request set of processes; it seeks
the permission of only processes in the request set (Ri
represents the request set of process Pi)
– Correctness is ensured through the following rules:
* For all Pi :
Pi is included in Ri
* For all Pi, Pj: Ri ∩ Rj is non-null
– The algorithm requires 2 x √n messages per CS entry
Chapter 17: Distributed
Control Algorithms
Dhamdhere: Operating Systems—
A ConceptBased Approach , 2 ed
Slide No: 10
Copyright © 2008
Token-based algorithm for a ring
•
Only the process holding the token can enter a CS
– An abstract ring is superimposed on a system (see next slide)
– A process wishing to enter a CS sends its request along the ring
and enters the CS only when it receives the token
* A Process not holding the token simply forwards the request to the
next process
* If the process holds the token and is not in a CS
It sends the token to the next process
The token travels over the ring until it reaches the requester
* If the process holds the token and is in a CS
The request is entered in a request queue in the token
When the process finishes the CS, it sends token to the next
process for delivery to the first process in its request queue
Chapter 17: Distributed
Control Algorithms
Dhamdhere: Operating Systems—
A ConceptBased Approach , 2 ed
Slide No: 11
Copyright © 2008
Token-based algorithm for a ring
(a) The system
(b) Abstract ring for the system: P4 has the token, requests by P2 and
P6 exist in the token’s request queue
Chapter 17: Distributed
Control Algorithms
Dhamdhere: Operating Systems—
A ConceptBased Approach , 2 ed
Slide No: 12
Copyright © 2008
Raymond’s token-based algorithm
•
Features of the algorithm
– The algorithm uses an abstract inverted tree to reduce the
number of messages. It has three invariants
*
Pholder, the process holding the token, is at root of the tree
*
Each process in the system belongs to the tree
*
Each process other than the Pholder has only one edge, which points
to its parent in the tree
Consequently, each process has a path that ends on Pholder
– Each process has a local request queue
*
When it receives a request, it puts the requestor’s id in the queue
*
When it makes a request, it puts its own id in the queue
Chapter 17: Distributed
Control Algorithms
Dhamdhere: Operating Systems—
A ConceptBased Approach , 2 ed
Slide No: 13
Copyright © 2008
Raymond’s token-based algorithm
(a) A system
(b) Abstract inverted tree for the system: P5 holds the token
Chapter 17: Distributed
Control Algorithms
Dhamdhere: Operating Systems—
A ConceptBased Approach , 2 ed
Slide No: 14
Copyright © 2008
Raymond’s token-based algorithm
1. Process wishes to make a request:
a. It enters the request in its local queue
b. Sends it on the out-edge if it has not sent a request earlier
2. When a process receives a request:
a. It enters the request in its local queue
b. Sends it on the out-edge if it has not sent a request earlier
3. When a process completes execution of a CS:
a. It removes first requester id from its queue,
b. sends the token to that process and inverts the edge to it
4. When a process receives the token:
a. It removes first requester id from its queue.
b. If it is its own id, it enters a CS; otherwise, it sends the token to the
process with that id and inverts the edge to it
Chapter 17: Distributed
Control Algorithms
Dhamdhere: Operating Systems—
A ConceptBased Approach , 2 ed
Slide No: 15
Copyright © 2008
An example of Raymond's algorithm
(a) Process P5 is in CS. Requests made by P3 and P1 have reached it
(b) Process P5 finishes execution of CS and passes token to P4
Chapter 17: Distributed
Control Algorithms
Dhamdhere: Operating Systems—
A ConceptBased Approach , 2 ed
Slide No: 16
Copyright © 2008
Distributed deadlock handling
•
A distributed computation may wish to use resources
located in many nodes of the system
– Information about allocated resources and pending requests in
many nodes has to be collected
– Correctness problems may arise due to
* Delays in obtaining information
* Consistency of information
– Consider building a global wait-for graph (WFG) by collecting
information about wait-for relationships in all nodes
* Inconsistent information due to delays may cause phantom
deadlocks, i.e., declaration of deadlock when none exists
* Next slide contains an example
Chapter 17: Distributed
Control Algorithms
Dhamdhere: Operating Systems—
A ConceptBased Approach , 2 ed
Slide No: 17
Copyright © 2008
Phantom deadlock
1. P5 requests and obtains r5 in node N3
2. P6 requests and obtains r4 in N3
3. P5 requests and obtains r6 in N4
4. P4 requests r5 in N3
5. P5 requests r4 in N3
Chapter 17: Distributed
Control Algorithms
6. N3 sends local WFG
7. P6 releases r4 in N3
8. P6 requests r6 in N4
9. N4 sends local WFG
Dhamdhere: Operating Systems—
A ConceptBased Approach , 2 ed
Slide No: 18
Copyright © 2008
Diffusion computation-based deadlock detection
•
Diffusion computation: used to collect info about nodes
– Diffusion phase
* Computation that has originated in one node, spreads to other
nodes
A control message called a query is sent along each edge
The first query received by a node is called an engaging query.
On receiving it, the node sends queries along all its out-edges
– Information collection phase
* Each node sends information in response to each query
It sends a dummy reply that contains null information for a nonengaging query
It collects information from all replies it received, adds its own
information, and sends the result as the reply to the engaging
query. We call it an engaging reply
Chapter 17: Distributed
Control Algorithms
Dhamdhere: Operating Systems—
A ConceptBased Approach , 2 ed
Slide No: 19
Copyright © 2008
Diffusion computation-based deadlock detection
1. When a process becomes blocked on a resource request: It
initiates a diffusion computation as follows:
a. Send queries along all out-edges in WFG
b. Remember the number of queries sent; await replies
c. After receiving a matching number of replies, declare a deadlock if
it has been continuously in blocked state after sending queries
2. When a process receives an engaging query: If it is blocked, it
performs the following actions:
a. Send queries along all out-edges in WFG
b. Remember the number of queries sent; await replies
c. After receiving a matching number of replies, compute and send
an engaging reply, if continuously blocked after sending queries
3. When a process receives a non-engaging query:
a. Send dummy reply if continuously blocked after sending queries
Chapter 17: Distributed
Control Algorithms
Dhamdhere: Operating Systems—
A ConceptBased Approach , 2 ed
Slide No: 20
Copyright © 2008
Illustration of diffusion computation-based
distributed deadlock detection
• P2, P3 are blocked. P1 becomes blocked and sends a query but does
not receive a reply because P4 is not blocked
• P4 requests a resource held by P1, becomes blocked and sends a query.
It would receive a reply and declare a deadlock
Chapter 17: Distributed
Control Algorithms
Dhamdhere: Operating Systems—
A ConceptBased Approach , 2 ed
Slide No: 21
Copyright © 2008
Mitchell–Merritt algorithm
for distributed deadlock detection
•
It is an edge chasing algorithm—control messages are
sent over WFG edges to detect cycles
– A provision is made to ensure that the cycle has not been
broken before it was detected
* Each process is assigned a public label and a private label
The labels are identical when a process is created
The public label of a process changes when it gets blocked on
a resource request
It also changes when it waits for a process having a larger
public label
* A wait-for edge with a specific relation between public and private
labels of its source and destination processes indicates presence of
a deadlock
Chapter 17: Distributed
Control Algorithms
Dhamdhere: Operating Systems—
A ConceptBased Approach , 2 ed
Slide No: 22
Copyright © 2008
Rules of Mitchell–Merritt algorithm
• Block rule changes the labels of a process when it blocks; z = inc(u, x),
where inc generates a unique label larger than both u and x
• The transmit rule changes public label of a process waiting for a process
with a larger public label
• Outedge of the process with largest label in a cycle satisfies detect condition
Chapter 17: Distributed
Control Algorithms
Dhamdhere: Operating Systems—
A ConceptBased Approach , 2 ed
Slide No: 23
Copyright © 2008
Distributed deadlock prevention
•
Cycles are prevented as follows:
– A pair (local time, node id) is used to time-stamp creation of a
process
– When process Pi requests a resource allocated to Pj, timestamps of Pi, Pj are used to decide whether Pi can wait for Pj
•
Two approaches
– Wait-or-die
* Pi is allowed to wait if it is older than Pj; otherwise, it is killed
– Would-or-wait
* Pi is allowed to wait if it is younger than Pj; otherwise Pj is killed
Chapter 17: Distributed
Control Algorithms
Dhamdhere: Operating Systems—
A ConceptBased Approach , 2 ed
Slide No: 24
Copyright © 2008
Distributed scheduling algorithms
•
Computational load in nodes is balanced through the
technique of process migration
• Process Pi is migrated from N1 to N2 during the interval t1–t2
• It is preemptive migration
Chapter 17: Distributed
Control Algorithms
Dhamdhere: Operating Systems—
A ConceptBased Approach , 2 ed
Slide No: 25
Copyright © 2008