chap4
chap4
● Execution of program started via GUI mouse clicks, command line entry of its name,
etc
● When CPU switches to another process, the system must save the state of the
old process and load the saved state for the new process via a context switch
● Context of a process represented in the PCB
● Context-switch time is overhead; the system does no useful work while
switching
● The more complex the OS and the PCB the longer the context switch
● Time dependent on hardware support
● Some hardware provides multiple sets of registers per CPU multiple contexts
loaded at once
Process Scheduling
● Maximize CPU use, quickly switch processes onto CPU for time sharing
● Process scheduler selects among available processes for next execution on
CPU
● Maintains scheduling queues of processes
● Job queue – set of all processes in the system
● Ready queue – set of all processes residing in main memory, ready and
waiting to execute
● Device queues – set of processes waiting for an I/O device
● Processes migrate among the various queues
Ready Queue And Various I/O Device
Queues
Representation of Process Scheduling
● Queueing diagram represents queues, resources, ows
Schedulers
● Short-term scheduler (or CPU scheduler) – selects which process should be executed next and
allocates CPU
● Sometimes the only scheduler in a system
● Short-term scheduler is invoked frequently (milliseconds) ⇒ (must be fast)
● Long-term scheduler (or job scheduler) – selects which processes should be brought into the
ready queue
● Long-term scheduler is invoked infrequently (seconds, minutes) ⇒ (may be slow)
● The long-term scheduler controls the degree of multiprogramming
Addition of Medium Term Scheduling
• Kernel-level
• Support multiprocessing
• Independently schedulable by OS
• Can continue to run if one thread blocks on a system call.
• User-level
• Less overhead than k-level; faster execution
• Hybrid Threads
• Combination of kernel and user level Support multiprocessing
User-level Threads
2. Multithreaded Server
Multithreaded Clients
Multithreaded web client
• Hiding network latencies:
• Web browser scans an incoming HTML page, and finds that more files need to be fetched.
• Each file is fetched by a separate thread, each doing a (blocking) HTTP request.
• As files come in, the browser displays them
• Multiple request-response calls to other machines (RPC):
• A client does several calls at the same time, each one by a different thread.
• It then waits until all results have been returned.
Multithreaded Servers
Finite-state machine
• The file server is single threaded but block for I/O operations
• Instead, save state of current request, switch to a new task – client
request or disk reply.
• Outline of operation:
• Get request, process until blocking I/O is needed
• Save state of current request, start I/O, get next task
• If task = completed I/O, resume process waiting on that I/O using saved state,
else service a new request if there is one.
Multithreaded Servers
Execution Segment
• Weak => only code transferred
• Strong => Code and execute segment can transferred
• Sender-initiated versus receiver-initiated
• Sender-initiated (code is with sender)
• Client sending a query to database server
• Client should be pre-registered
• Receiver-initiated
• Downloading code from server by a client
• Java applets
Models for Code Migration
Migration in Heterogeneous Systems
3. Flexible
Desirable Features of global Scheduling algorithm
4. Stable
• Also note that in case of m tasks and q nodes, there are mq possible
assignments of tasks to nodes . In practice, however, the actual number of
possible assignments of tasks to nodes may be less than mq due to the restriction
that certain tasks cannot be assigned to certain nodes due to their specific
requirements (e.g. need a certain amount of memory or a certain data file).
Task Assignment Approach
Task assignment example
□ There are two nodes, {n1, n2} and six tasks {t1, t2, t3, t4, t5, t6}. There are two task assignment parameters – the task
execution cost (xab the cost of executing task a on node b) and the inter-task communication cost (cij the inter-task
communication cost between tasks i and j).
Inter-task communication cost Execution costs
t1 t2 t3 t4 t5 t6 Nodes
t1 0 6 4 0 0 12 n1 n2
t2 6 0 8 12 3 0 t1 5 10
t3 4 8 0 0 11 0 t2 2 ∞
t4 0 12 0 0 5 0 t3 4 4
t5 0 3 11 5 0 0 t4 6 3
t6 12 0 0 0 0 0 t5 5 2
t6 ∞ 4
Task t6 cannot be executed on node n1 and task t2 cannot be executed on node n2 since the resources they need are not available on
these nodes.
Task Assignment Approach
Task assignment example
1) Serial assignment, where tasks t1, t2, t3 are assigned to node n1 and tasks t4, t5, t6 are assigned to node
n2:
Execution cost, x = x11 + x21 + x31 + x42 + x52 + x62 = 5 + 2 + 4 + 3 + 2 + 4 = 20
Communication cost, c = c14 + c15 + c16 + c24 + c25 + c26 + c34 + c35 + c36 = 0 + 0 + 12 + 12 + 3 + 0 + 0 +
11 + 0 = 38.
Hence total cost = 58.
2) Optimal assignment, where tasks t1, t2, t3, t4, t5 are assigned to node n1 and task t6 is assigned to node n2.
Execution cost, x = x11 + x21 + x31 + x41 + x51 + x62
= 5 + 2 + 4 + 6 + 5 + 4 = 26
Communication cost, c = c16 + c26 + c36 + c46 + c56
= 12 + 0 + 0 + 0 + 0 = 12
Total cost = 38
Task Assignment Approach
Assignment Graph
Optimal assignments are found by first creating a static assignment
graph. In this graph, the weights of the edges joining pairs of task nodes
represent inter-task communication costs. The weight on the edge
joining a task node to node n1 represents the execution cost of that task
on node n2 and vice-versa. Then we determine a minimum cutset in this
graph.
A cutset is defined to be a set of edges such that when these edges are
removed, the nodes of the graph are partitioned into two disjoint subsets
such that nodes in one subset are reachable from n1 and the nodes in the
other are reachable from n2. Each task node is reachable from either n1
or n2. The weight of a cutset is the sum of the weights of the edges in
the cutset. This sums up the execution and communication costs for that
assignment. An optimal assignment is found by finding a minimum
cutset.
Load balancing Approach
Load balancing
Load-balancing algorithms
Static Dynamic
Cooperative Non-cooperative
• In some cases the true load could vary widely depending on the
remaining service time, which can be measured in several way:
• Memoryless method assumes that all processes have the same expected
remaining service time, independent of the time used so far
• Pastrepeats assumes that the remaining service time is equal to the time used
so far
• Distribution method states that if the distribution service times is known, the
associated process’s remaining service time is the expected remaining time
conditioned by the time already used
Load estimation policy III.
for Load-balancing algorithms
Overloaded
Overloaded
High mark
Threshold Normal
Low mark
Underloaded
Underloaded
• Periodic broadcast
• Each node broadcasts its state information after the elapse of every T units of
time
• Problem: heavy traffic, fruitless messages, poor scalability since information
exchange is too large for networks having many nodes
• Broadcast when state changes
• Avoids fruitless messages by broadcasting the state only when a process
arrives or departures
• Further improvement is to broadcast only when state switches to another
region (double-threshold policy)
State information exchange policy III.
for Load-balancing algorithms
• On-demand exchange
• In this method a node broadcast a State-Information-Request message when
its state switches from normal to either underloaded or overloaded region.
• On receiving this message other nodes reply with their own state information
to the requesting node
• Further improvement can be that only those nodes reply which are useful to
the requesting node
• Exchange by polling
• To avoid poor scalability (coming from broadcast messages) the partner node
is searched by polling the other nodes on by one, until poll limit is reached
Location policy I.
for Load-balancing algorithms
• Threshold method
• Policy selects a random node, checks whether the node is able to receive the
process, then transfers the process. If node rejects, another node is selected
randomly. This continues until probe limit is reached.
• Shortest method
• L distinct nodes are chosen at random, each is polled to determine its load.
The process is transferred to the node having the minimum value unless its
workload value prohibits to accept the process.
• Simple improvement is to discontinue probing whenever a node with zero
load is encountered.
Location policy II.
for Load-balancing algorithms
• Bidding method
• Nodes contain managers (to send processes) and contractors (to receive
processes)
• Managers broadcast a request for bid, contractors respond with bids (prices
based on capacity of the contractor node) and manager selects the best offer
• Winning contractor is notified and asked whether it accepts the process for
execution or not
• Full autonomy for the nodes regarding scheduling
• Big communication overhead
• Difficult to decide a good pricing policy
Location policy III.
for Load-balancing algorithms
• Pairing
• Contrary to the former methods the pairing policy is to reduce the variance of
load only between pairs
• Each node asks some randomly chosen node to form a pair with it
• If it receives a rejection it randomly selects another node and tries to pair
again
• Two nodes that differ greatly in load are temporarily paired with each other
and migration starts
• The pair is broken as soon as the migration is over
• A node only tries to find a partner if it has at least two processes
Priority assignment policy
for Load-balancing algorithms
• Selfish
• Local processes are given higher priority than remote processes.
• Altruistic
• Remote processes are given higher priority than local processes.
• Intermediate
• When the number of local processes is greater or equal to the number of
remote processes, local processes are given higher priority than remote
processes. Otherwise, remote processes are given higher priority than local
processes.
Migration limiting policy
for Load-balancing algorithms
• This policy determines the total number of times a process can migrate
• Uncontrolled
• A remote process arriving at a node is treated just as a process originating at a node, so a
process may be migrated any number of times
• Controlled
• Avoids the instability of the uncontrolled policy
• Use a migration count parameter to fix a limit on the number of time a process can
migrate
• Irrevocable migration policy: migration count is fixed to 1
• For long execution processes migration count must be greater than 1 to adapt for
dynamically changing states
Load-sharing approach
Load-sharing approach
• Drawbacks of Load-balancing approach
• Load balancing technique with attempting equalizing the workload on all the nodes is not an
appropriate object since big overhead is generated by gathering exact state information
• Load balancing is not achievable since number of processes in a node is always fluctuating
and temporal unbalance among the nodes exists every moment
• Basic ideas for Load-sharing approach
• It is necessary and sufficient to prevent nodes from being idle while some other nodes have
more than two processes
• Load-sharing is much simpler than load-balancing since it only attempts to ensure that no
node is idle when heavily node exists
• Priority assignment policy and migration limiting policy are the same as that for the
load-balancing algorithms
Load estimation policies
for Load-sharing algorithms
• Location policy decides whether the sender node or the receiver node of the
process takes the initiative to search for suitable node in the system, and this
policy can be the following:
• Sender-initiated location policy
• Sender node decides where to send the process
• Heavily loaded nodes search for lightly loaded nodes
• Receiver-initiated location policy
• Receiver node decides from where to get the process
• Lightly loaded nodes search for heavily loaded nodes
Location policies II.
for Load-sharing algorithms
• In load-sharing algorithms it is not necessary for the nodes to periodically exchange state
information, but needs to know the state of other nodes when it is either underloaded or
overloaded
• Broadcast when state changes
• In sender-initiated/receiver-initiated location policy a node broadcasts State Information Request when
it becomes overloaded/underloaded
• It is called broadcast-when-idle policy when receiver-initiated policy is used with fixed threshold value
value of 1
• Poll when state changes
• In large networks polling mechanism is used
• Polling mechanism randomly asks different nodes for state information until find an appropriate one or
probe limit is reached
• It is called poll-when-idle policy when receiver-initiated policy is used with fixed threshold value value
of 1
SUMMARY