Você está na página 1de 24

Scheduling ,I/O Management and Disk scheduling

Structure
4.0 Introduction
4.1 Objectives
4.2 Types of Processor Scheduling
4.2.1 Long-Term Scheduling
4.2.2 Medium-Term Scheduling
4.2.3 Short-Term Scheduling
4.3 Scheduling Algorithms
4.3.1 Short-term Scheduling Criteria
4.3.2 First-Come-First-Served
4.3.3. Round Robin
4.3.4 Shortest Process Next
4.3.5 Fair-Share Scheduling
Check your progress
4.4 I/O Devices
4.5 Organization I/O Function
4.5.1 The Evolution of the I/O function
4.5.2 Direct Memory Access
4.6 Operating System Design Issues
4.7 I/O Buffering
4.8 Disk Scheduling
4.8.1 Disk performance parameters
4.8.2 Disk Scheduling Policies
4.9 Disk Cache
Check your progress
4.10 Let us Sum up
4.0 Introduction
The first half of this unit begins with an examination of types of processor scheduling
showing the way in which they are related. We will see how short-term scheduling is
used on a single processor system and discuss the various Scheduling algorithms. The
next part of this unit focuses on discussion of I/O devices, Organization of I/O functions,
Operating design issues, the way in I/O function can be structured and also we will
examine the different disk scheduling algorithms.

4.1 Objectives
At the end of this unit you will be able to
• Identify the various external devices that are used in I/O
• Discuss the various techniques for performing I/O
• Explain the concept of DMA
• List the various design issues of Operating System
• Describe the various I/O buffering
• Explain the working of Disk Scheduling
• Capture the concept of Disk Cache.

4.2Types of Processor Scheduling


The aim of processor scheduling is to assign processes to be executed by the
processor of processors over time, in a way that meets system objectives, such as
response, throughput, and processor efficiency. Scheduling activities can be divided into
three functions Long-term, Medium term and Short term scheduling.
New
Long-term
Scheduling Long-term scheduling

Ready/
Runnin
Suspen Ready Exit
g
d
Medium-term Short-term scheduling

Scheduling

Blocked
/
Blocked
Suspen
d
Figure 4.1 Scheduling and Process State Transitions

4.2.1 Long term scheduling


Long term scheduling is performed when a new process is created. This is the
decision to add a new process to the set of processes that are currently active. It controls
the degree of multiprogramming. In a batch system, or for the batch portion of a general-
purpose operating system, newly submitted jobs are routed to disk and held in batch
queue. The long-term scheduler creates processes from the queue when it can. There are
two decisions involved here. First, the scheduler must decide that the operating system
can take on one or more additional processes. Second, the scheduler must decide which
job or jobs to accept and turn into processes. Each tune job terminates, the scheduler may
make the decision to add one or more new jobs. The decision as to which job to admit
next can be on a simple first-come-first-served basis.

4.2.2 Medium-Term Scheduling


It is a part of the swapping function. The decision to add the number of processes
that are partially or fully in main memory. Typically, the swapping-in decision is based
on the need to manage the degree of multiprogramming. The swapping-in decision will
consider the memory requirements of the swapped-out processes also.

4.2.3 Short-Term Scheduling


Short-term scheduling is the actual decision of which ready process to execute
next. It is invoked whenever an even occurs that may lead to the suspension of the current
process or that may provide an opportunity to preempt a currently running process in
favor of another. Eg. Clock interrupts, I/O interrupts, Operating system calls, Signals.

4.3 Scheduling algorithms


4.3.1 Short term scheduling Criteria
• User Oriented, Performance Related
The main objective of short-term scheduling is to allocate processor time in such
a way to optimize one or more aspects of behavior. The commonly used criteria can be
categorized along two dimensions: User oriented criteria and system oriented criteria.
• User oriented, Performance related
Turnaround time: This is the interval of time between the submission of a process and its
completion. Includes actual execution time plus time spent waiting for resources,
including the processor. This is an appropriate measure for a batch job.
Response time: For and interactive process, this is the time from the submission of a
request until the response begins to be received. Often a process can begin producing
some output to the user while continuing to process the request. Thus, this is better
measure than turnaround time from the user’s point of view. The scheduling discipline
should attempt to achieve low response time and to maximize the number of interactive
users receiving acceptable response time.
Deadlines: When process completion deadline can be specified, the scheduling
discipline should subordinate other goals to that of maximizing the percentage of
deadlines met.

• User Oriented, Other


Predictability: A given job should the same amount of time and at about the same
cost regardless of the load on the system. A wide variation in response time or turnaround
time is distracting to users. It may signal a wide swing in system workloads or the need
for system tuning to cure instabilities
• System Oriented, Performance Related
Throughput: The scheduling policy should attempt to maximize the number of
processes completed per unit of time. This is a measure of how much work is being
performed. This clearly depends on the average length of a process but is also influenced
by the scheduling policy, which may affect utilization.
Processor utilization: This is the percentage of time that the processor is busy. For
an expensive shared system, this is a significant criterion. In single-user systems and in
some other systems, such as real-time systems, this criterion is less important than some
of the others.
• System oriented, other
Fairness: In the absence of guidance from the user or other system-supplied
guidance, processes should be treated the same and no process should suffer
starvation
Enforcing priorities: When processes are assigned priorities, the scheduling
policy should favor higher priority processes.
Balancing resources: The scheduling policy should keep the resources of the
system busy. Processes that will underutilize stressed resources should be favored. This
criterion also involves medium-term and long-term scheduling.
There are several scheduling policies. The selection function determines which
process, among ready processes, is selected next for execution. The function may be
based on priority, resource requirements, or the execution characteristics of the process.
In the latter case, three quantities are specialized.
w = time spent in system so far, waiting and executing
e = time spent in execution so far
s = total service time required by the process, including e, generally, this quantity must be
estimated or supplied by the user
Eg. The selection function max[w] indicates a first-come-first-served.
The decision mode specifies the instants in time at which the selection function is
exercised. There two general categories:
• Nonpreemptive : In this case, once a process is in the running state, it continues to
execute until it terminates or blocks itself to wait for I/O or to request some
operating system service
• Preemptive: The currently running process may be interrupted and moved to the
Ready state by the operating system. The decision to preempt may be performed
when a new process arrives, when an interrupt occurs that places blocked process
in the Ready stat, or periodically based on a clock interrupt.

Process Arrival Time Service Time


A 0 3
B 2 6
C 4 4
D 6 5
E 8 2

Figure 4.2 Process scheduling

4.3.2 First-come-First-Served
The simplest scheduling policy is first-come-first-served (FCFS), also known as
first-in-first-out (FIFO) or a strict queue scheme. As each process becomes ready, it joins
the ready queue. When the currently running process finished execution the process that
has been in the ready queue the longest is selected.

In terms of the queuing model, Turn Around Time (TAT) is the residence time Tr,
or total time that the item spends in the system. (Waiting time plus service time).The
normalized turnaround time, which is the ratio of turnaround time to service time. This
value indicates the relative delay experienced by a process. Typically, the longer the
process execution time, the greater the absolute amount of delay that can be tolerated.
The minimum possible value for this ratio is 1.0 increasing values correspond to a
decreasing level of service. FCFS performs much better for long processes than short
ones and it favor processor-bound processes over I/O bound processes.

4.3.3 Round Robin


A straightforward way to reduce the penalty that short jobs suffer with FCFS is to
use preemption based on a clock. The simplest such policy is round robin. A clock
interrupt is generated at periodic intervals. When the interrupt occurs, the currently
running process is placed in the ready queue, and the next ready job is selected on a
FCFS Basis. This technique is also known as time slicing, because each process is given a
slice of time before being preempted.
With round robin, the principal design issue is the length of the time quantum, or
slice, to be used. If the quantum is very short, then short processes will move through the
system relatively quickly. On the other hand, there is processing overhead involved in
handling the clock interrupt and performing the scheduling and dispatching function.
Thus, very short time quantum should be avoided.
Round robin is particularly effective in a general-purpose time-sharing system or
transaction processing system. One drawback to round robin is its relative treatment of
processor-bound and I/O bound processes. I/O-bound process has a shorter processor
Burst than a processor-bound process.

Time-out
Admit Ready Queue Dispatch Release
Processor

Auxiliary queue

I/O 1 wait

I/O 1 queue
I/O 2 wait

I/O 2 queue

I/O n wait

I/O n queue

Figure 4.3 Queuing Diagram for Virtual Round-Robin Scheduler

4.3.4 Shortest Process Next


The Shortest Process Next (SPN) policy is a nonpreemptive policy in which the
process with the shortest expected processing time is selected next. Thus a short process
will jump to the head of the queue past longer jobs. One difficulty with the SPN policy is
the need to know or at least estimate the required processing time of each process. For
batch jobs, the system may require the programmer to estimate the value and supply it to
the operating system. If the programmer’s estimate is substantially under the actual
running time, the may abort the job. The simple calculation would be:

n
Sn+1 =1/n ΣT i

i=1
Where
Ti = processor execution time for the ith instance of this process
S = Predicated value for the ith instance
S1 = predicated value for first instance; not calculated

4.3.5 Fair-Share Scheduling


All of the scheduling algorithms discussed so far treat the collection of ready
processes as a single pool of processes from which to select the next running process.
However, in a multi-user system, if individual user applications or jobs may be organized
as multiple processes, then there is a structure to the collection of processes that is not
recognized by traditional scheduler. In fair-share scheduling, the scheduling decisions
made based on how a set of processes performs

Check your progress


1. Define scheduling.
2. Describe Long term scheduling.
3. Give two examples for short term scheduling.
4. What is nonpreemptive process?
5. Mention the two type decision modes.
6. Expand FCFS.
7. What is turnaround time?
8. List various scheduling policies.
9. Define round robin.
10. What is the difficulty in SPN policy?
11. Describe Fair-Share Scheduling.
I/O Devices and disk scheduling
4.4. I/O Devices
External Devices that are used in I/O with computer systems can be roughly grouped into
three classes
• Human readable: Suitable for communicating with the computer user. Eg.Display,
Keyboard, and perhaps other devices such as mouse
• Machine Readable: Suitable for communication with electronic equipment Eg.
disk ,tape drives, sensors, controllers, and actuators
• Communication: Suitable for communication with remote devices. Eg. Digital
line drivers and modems.
There are great differences across these classes are
• Data rate : There may be differences in data transfer rate
• Application: The use of the device on the software and policies in the operating
system and supporting utilities.
For eg. A disk used for files requires the support of file management.
• Complexity of control: A printer requires a relatively simple control interface.
A disk is much more complex.
• Unit of transfer : Data may transferred as a stream of bytes or
characters(eg.terminal I/O) or in larger blocks(e.g disk I/O)
• Data representation : Different data encoding schemes are used by different
device, including differences in character code and parity conventions
• Error conditions : The nature errors, the way in which they are reported, their
consequences, and the available range of responses differ widely from one device
to another

4.5 Organization of the I/0 functions


Programmed I/O: The processor issues and I/O command, on behalf of a process, to
and I/O module; that process then busy waits for the operation to be completed before
proceeding.
Interrupt-driven I/O: The processor issues an I/O command on behalf of a process.
After that the processor continues to execute subsequent instructions and is
interrupted by I/O module when the latter has completed its work. The subsequent
instructions may be in the same process, if it is not necessary for that process to wait
for the completion of the I/O.
Direct memory access: A DMA module controls the exchange of data between main
memory and an I/O module.

4.5.1 The Evolution of the I/O Function


The evolutionary steps of I/O are
1. The processor controls a peripheral device. This is seen in simple microprocessor-
controlled device.
2. A controller or I/O module is added. The processor uses programmed I/O without
interrupts.
3. The same configuration as step 2 is used, but now interrupts are employed. The
processor need not spend time waiting for an I/O operation to be performed, thus
increasing efficiency
4. The I/O module is given direct control of memory view DMA. I t can now more a
block of data to or from memory without involving the processor, except at the
beginning and end of the transfer
5. The I/O module is enhanced to become a separate processor, with a specialized
instruction. The CPU directs the I/O processor to execute program in main memory.
The I/O processor to execute theses instructions without processor intervention.
6. The I/O module has a local memory is its own and is, in fact, a computer in its own
right. With this architecture, a large set of I/O devices can be controlled with minimal
processor involvement. A common use for such architecture has been to control
communications with interactive terminals. The I/O processor takes care most of the
tasks involved in controlling the terminals.
For all of the modules described in steps 4 through steps 6, the term direct
memory access is appropriate, because all of these types involve direct control of main
memory by the I/O module. Also, the I/O module in step 5 often referred to as an I/O
channel and that in step 6 as an I/O processor

4.5.2 Direct Memory Access


The DMA module controls the exchange of data between main memory and an
I/O module. It needs system bus to do this. The DMA module must use the bus only
when the processor does not need it, or it must force the processor to suspend operation
temporarily. The latter technique is more common and is referred to as cycle stealing,
because the DMA unit in effect steals a bus cycle.

Data count

Data Register
Data lines

Address Address lines


Register

DMA request
DMA acknowledge
Control Logic Interrupt
Read
rEAD
Write

Figure 4.4 DMA Controller

The DMA technique works as follows.


• Whether a read or write is requested, using read or write control line between the
processor and the DMA module
• The address of the I/O device involved, communicated on the data lines
• The starting location in memory to read from or write to, communicated on the
data lines and stored by the DMA module in its address register
• The number of words to be read or written, again communicated via the data lines
and stored in the data count register
The Processor then continues with other work. It has assigned this I/O operation
to DMA module. The DMA module transfers the entire block of data, one word at a
time, directly to or from memory, without going through the processor. When the
transfer is complete, the DMA module sends an interrupt signal to the processor.
Thus, the processor is involved only at the beginning and end of the transfer.
The DMA mechanism can be in different ways. Some possibilities are shown in
figure.


Processor
DMA I/O I/O Memory

(a) Single bus, detached DMA

DMA
Processor DMA Memory
I/O

I/O I/O

(b). Single bus, integrated DMA-I/O


Figure 4.5 Alternative DMA Configurations

4.6 Operating system Design Issues


Design Objectives
Two main objectives in designing the I/O facility: Efficiency and generality.
Efficiency is important because I/O operation often form a problem in a computing
system. One way to tackle this problem in multiprogramming, allows some processes to
be waiting on I/O operations while another process is executing. Thus, a major effort on
I/O design has been schemes for improving the efficiency of the I/O.
The other major objective is generality. In the interests of simplicity and freedom
from error, it is desirable to handle all devices in a uniform manner. Because of diversity
of device characteristics, it is difficult in practice to achieve true generality. What can be
done is to use a hierarchical, modular approach to the design of the I/O.

Logical structure of the I/O function


The local peripheral device communicates in a simple fashion, such as a stream
of bytes or records. The important layers are:
• Logical I/O: The logical I/O module deals with device as a logical resource. This
module is concerned with managing general I/O functions on behalf of user
processes. It deals the device in terms of simple commands such as open, close,
read, write.
• Device I/O: The requested operations and data are converted into appropriate
sequences of I/O instructions, channel commands. And controller orders.
Buffering techniques may be used to improve utilization.
• Scheduling and control : The actual queuing and scheduling of I/O operations
Occurs at this layer, as well as the control of the operations. Thus, interrupts are
handled at this layer and I/O status is collected and reported. This is the layer of
software that actually interacts with the I/O module and hence the device
hardware.
The next structure is communication port looks much the same as the first case. The Only
difference is that the logical I/O module is replaced by communications architecture. The
last one is File system. The layers are
• Directory management: At this layer, symbolic file names are converted to
identifiers. The identifiers either reference the file directly or indirectly through a
file descriptor or index table.
• File system: This layer deals with the logical structure of files and with the
operations that can be specified by users, such as open, close, read, write.
Access rights are also managed at this layer.
• Physical organization: In segmentation and paging structure, logical references to
files and records must be converted to physical secondary storage addresses,
taking into account the physical track and sector structure of the secondary
storage device. Allocation of secondary storage space and main storage buffers is
treated in this layer.

4.7 I/O Buffering


There is a speed mismatch between I/O devices and CPU. This leads to
inefficiency in processes being completed. To increase the efficiency, it may be
convenient to perform input transfers in advance of requests being made and to
perform output transfers some time after the request is made. This technique is known
as buffering.
In discussing the various approaches to buffering, it is sometimes important to
make a distinction between two types of I/O devices:
• Block-oriented Devices stores information in blocks that are usually of fixed size
and transfers are made one block at a time. Eg.Disk,tape
• Stream-oriented devices transfer data in and out as a stream of bytes, with no
block structure. Eg. Terminals, printers, communications port, mouse.

Single Buffer
The simplest type of buffering is single buffering. When a user process issues and
I/O request, the operating system assigns a buffer in the system portion of main
memory to the operation. For block-oriented devices, the single buffering scheme can
be described as follows: Input transfers are made to the system buffer. When the
transfer is complete, the process moves the block into user space and immediately
requests another block.
Operating System User Process

I/O devices
In

(a) No buffering

Operating System User Process


I/O devices
In Move

(b) Single buffering

Operating System User Process

I/Odevice In Move

(c)Double buffering

Operating System User Process

I/O device In Move

. .
(d) Circular Buffering

Figure 4.6 I/O Buffering schemes


For stream oriented I/O, the single buffering scheme can be used in a line- at- a
time Fashion or a byte-at-a-time fashion. In line-at-a-time fashion user input and
output to the terminal is one line at a time. For eg. Scroll-mode terminals, line printer.
Suppose that T is the required to input one block and that C is the computation time.
Without buffering, the execution time per block is essentially T+C. With a single
buffer, the time is max[C, T] +M, Where M is the time required to move the data
from the system buffer to user memory.
Double Buffer
An improvement over single buffering can be done by assigning two system
buffers to operation. A process now transfers data to one buffer while the operating
system empties the other. This technique is known as double buffering or buffer
swapping.
For block-oriented transfer, we can roughly estimate the execution time as
max[C,T].In both cases(C<= T and C>T) an improvement over single buffering in
achieved. Again, this improvement comes at the cost of increased complexity. For
stream-oriented input, there are two alternative modes operation. For line-at-a time
I/O, the user process need not be suspended for input or output, unless the process
runs ahead of the double buffers. For byte-at-a time operation, the double buffer
offers no particular advantage over a single buffer of twice the length.

Circular Buffering
Double buffering may be inadequate if the process performs rapid bursts of I/O.
In this case, the problem can be solved by using more than one buffer. When more
than two buffers are used, the collection of buffers is itself referred to as a circular
buffer.

The utility of buffering


Buffering is a technique that smooths out peaks in I/O demand. However, no
amount of buffering will allow an I/O device to keep pace with a process indefinitely
when average demand of the process is greater than the I/O device can service. Even
with multiple buffers, all of the buffers will eventually fill up and the process will
have to wait after processing each chunk of data.

4.8 Disk scheduling


In this section, we highlight some of the key issues of the performance of disk
system.

4.8.1Disk performance parameters


The actual details of disk I/O operation depend on the computer system, operating
system and the nature of I/O channel and disk controller hardware. When the disk
drive is operating, the disk is rotating at constant speed. To read or write, the head
must be positioned at the desired track and at the beginning of desired sector on that
track. Track can be selected using either moving-head or fixed-head. On a movable-
head system, the time it takes to position the head at the track is known as seek time.
In either case, once the track is selected, the disk controller waits until the appropriate
sector reached. The time it takes to find the right sector is known as rotational delay
or rotational latency. The sum of seek time, and the rotational delay is access time
(the time taken to read or write).
In addition to these times, there are several queuing time associated with disk
operation. When a process issues an I/O request, it must first wait in a queue for the
device to be available. At that time, the device is assigned to the process. If the device
shares a single I/O channel or a set of I/O channels with other disk drives, then there
may be an additional wait for the channel to be available.
Seek time
Seek time is the time required to move the disk arm to the required track. The
seek time consists of two key components: the initial startup time, and the time taken
to traverse the tracks. The traversal time is not a linear function of the number of
tracks but includes a startup time and a settling time.
Rotational delay
Magnetic disks, other than floppy disks, have rotational speeds in the range 400 to
10,000 rpm. Floppy disks typically rotate at between 300 to 600rpm. Thus the average
delay will be between 100 and 200 ms.
Transfer Time
The transfer time to or from the disk depends on the rotation speed of the disk in the
following fashion:
T=b/rN
Where
T=transfer time
B= number bytes to be transferred
N = number of bytes on a track
R= rotation speed, in revolutions per second
Thus the total average access time can be expressed as Ta=Ts+1/2r+b/rN
Where Ts is the average seek time

4.8.2.Disk Scheduling Policies


There are several disk scheduling Policies with different seek time.
Random scheduling: The requested track is selected randomly.
FIFO SSTF SCAN C-SCAN
Next track No.of Next track No.of Next track No.of Next track No.of
accessed tracks accessed tracks accessed tracks accessed tracks
traversed traversed traversed traversed
55 45 90 10 150 50 150 50
58 3 58 32 160 10 160 10
39 19 55 3 184 24 184 24
18 21 39 16 90 94 90 164
90 72 38 1 58 32 58 20
160 70 18 20 55 3 55 1
150 10 150 132 39 16 39 16
38 112 160 10 38 1 38 3
184 146 184 24 18 20 18 32
Average 55.3 Average 27.5 Average 27.8 Average 35.8
seek seek seek seek
length length length length

Figure 4.7 Comparison of Disk scheduling algorithms

First –in-first out


The I/O requests are satisfied in the order in which they arrived.
Eg. Assume a disk with 200 tracks and that the disk request queue has random requests
in it. The requested tracks, in the order received, are 55, 58, 39, 18, 90, 160, 150, 38, 184.
Priority
With a system based on priority (PRI), the control of the scheduling is outside the
control of disk management. The short batch jobs and interactive jobs are given higher
priority than longer jobs that require longer computation. This type of policy tends to be
poor for database systems.
Last in first out
In this policy the most recent requests are given preference. In transaction
processing systems, giving the device to the most recent user should result in little or no
arm movement for moving through a sequential file. FIFO, Priority, and LIFO scheduling
are based solely on attributes of the queue or the requester.
Shortest service time first
The SSTF policy is to select the disk I/O request that requires the least movement
of the disk arm from its current position. Thus, we always choose to incur the minimum
seek time. This policy provides better performance than FIFO.
SCAN
With the exception of FIFO, all of the policies can leave some request unfulfilled
until the entire queue is emptied. That is, there may always be new requests arriving that
will be chosen before an existing request. With SCAN, the arm is required to move in
one direction only, satisfying all outstanding requests, until it reaches the last track in that
direction or until there are no more requests in that direction.
C-SCAN
The C-SCAN (circular SCAN) policy restricts scanning to one direction only.
Thus, when the last track has been visited in one direction, the arm is returned to the
opposite end of the disk and the scan begins again. This reduces the maximum delay
experienced by new requests. With SCAN, if the expected time for a scan from inner
track to outer track is t, then the expected service interval for sectors at the periphery is
2t. With C-SCAN, the interval is on the order of t + s max where smax is the maximum seek
time.
N-step-SCAN and FSCAN
With SSTF, SCAN AND C-SCAN it is possible that the arm may not move for a
considerable period of time. High-density disks are more likely to be affected. By this
characteristic than lower density disks and/or disks with only one or two surfaces. To
avoid this “arm stickiness” the disk request queue can be segmented, with one segment at
a time being processed completely.
The N-step-SCAN policy segments the disk request queue into sub queues of
length N. Subqueues are processed one at a time, SCAN. While a queue is being
processed, new requests must be added to some other queue. If Fewer than N requests are
available at the end of a scan, then all of them are processed with the next scan. With
large values of N, the performance of N-step-SCAN approaches that of SCAN; with a
value of N=1, the FIFO policy is adopted.
FSCAN is a policy that uses two sub queues. When a scan begins, all of the
requests are in one of the queues, with the other empty. During the scan, all new requests
are put into the other queue. Thus service of new requests is deferred until all of the old
requests have been processed.

4.9 Disk Cache


The term Cache memory is usually used to apply to memory that is smaller and
faster than main memory and that is interposed between main memory and the processor.
Such a cache memory reduces average memory access time by exploiting the principle of
locality.
A disk cache is a buffer in main memory for disk sectors. The cache contains a
copy of some of the sectors on the disk. When an I/O request is made for a particular
sector, a check is made to determine if the sector is in the disk cache. If so, the request is
satisfied via the cache. If not, the requested sector is read into the disk cache from the
disk. Because of the phenomenon of locality of reference, when a block of data is fetched
into the cache to satisfy a single I/O request, it is likely that there will be future references
to that same block.
Design Considerations
Several design issues are of interest. First, when an I/O request is satisfied from
the disk cache, the data in the disk cache must be delivered to requesting process. This
can be done either by transferring the block of data from disk cache to user process or
simply by using a shared memory capability and passing a pointer to the appropriate slot
in the disk cache. The latter approach saves the time of a memory-to-memory transfer
and also
A second design issue has to do with the replacement strategy. When a sector is
brought into the disk cache, one of the existing blocks must be replaced. For this
replacement, the most commonly used algorithm is least recently used (LRU): Replace
that block that has been in the cache longest with no reference to it. Logically, the cache
consists of a stack of blocks, with the most recently reference block on the top of the
stack.
Another possibility is least frequently used (LFU): Replace the block that is not
frequently used. The LFU can be implemented by associating a counter with each block.
When a block is brought in, it is assigned a count of 1; with each reference to the block,
its count is incremented by 1. When replacement required, the block with smallest count
is selected. One problem of LFU is the effect of locality may actually cause the LFU
algorithm to make poor replacement choices.
To overcome this difficulty, a technique known as frequency-based replacement
is proposed.
New section Old section

MRU LRU

Re-reference;
count unchanged Re-reference
Count:=count+1

Miss(new block brought in)


count :=1

(a) FIIFO

New section Middle section Old section


MRU LRU
… … …

(b)Use of three sections


Figure 4.8 Frequency-based Replacement
First consider a simplified version, given figure 4.8 a. The blocks are organized in a
stack, as with the LRU algorithm. A certain portion of the top part of the stack is set aside
as a new section. When there is cache hit, the referenced block is moved to the top of the
stack. If the block was already in the new section, its reference count is not incremented;
otherwise incremented by 1. Given a sufficiently large new section, this result in the
reference counts for blocks that are repeatedly re-referenced within a short interval
remaining unchanged. On a miss, the block with the smallest reference count that is not
in the new section is chosen for replacement; the least recently-used such block is chosen
in the event of a tie.

Check your progress


1. What are the two design objectives of I/O?
2. Define buffering.
3. Write the two types of I/O devices.
4. Define buffer swapping.
5. What is seek time?
6. What is rotational delay?
7. How will you calculate Transfer time?
8. List out the disk scheduling policies.
9. Expand SSTF.
10. What is C-SCAN?
11. Define Cache memory.
12. Define LRU and LFU?

4.10 Let us Sum up


The operating system must make three types of scheduling decisions with respect to the
execution of process. Long term scheduling determines when new processes are admitted
to the system. Medium term scheduling is part of the swapping function and determines
when a program is bought partially or fully into main memory so that it may be executed.
Short term scheduling determines which ready process will be executed next by the
processor. A variety of algorithms has been used in short term scheduling like First-
Come, First-Served, Round Robin, Shortest process next, Shortest remaining time,
Highest response ratio next and Feedback. The Choice of scheduling algorithm depends
on expected performance and on implementation complexity.
The computer system’s interface to the outside world is its I/O architecture. The I/O
architecture is designed to provide a systematic means of controlling information and to
provide operating system with the information it needs. The I/O function is broken into
number of layers, with lower layer dealing with details closer to the physical functions to
be performed, and higher layers dealing with I/O in a logical and generic fashion. A key
aspect of I/O is the use of buffer rather than application processes. Buffering smooth out
the difference between the internal speeds of the computer system and speeds of the I/O
device. Two of the approaches used to improve the disk I/O performance are Disk
scheduling and Disk Cache.