UNIT-5
UNIT-5
Page 2
Unit-5 Device Management
Page 3
Unit-5 Device Management
Thus, the disk space manager hides details of the underlying hardware (and possibly the operating
system) and allows higher levels of the software to think of the data as a collection of pages.
Track:
A disk surface contains several concentric tracks. In
fact, a track contains data which can be read by
signal read head without changing its position.
The maximum amount of information that can be
read by a single read/write head system in one
revolution is determined by the track length.
The track length is expressed in bytes, words or
characters.
Each track, in addition to the data, contents some
extra information such as : the address of tracks
(i.e., cylinder number and track number), block
number, gap between blocks cyclic check code etc.
information are used by Input/output controls for
proper processing of data.
Sectors:
The tracks are sub-divided into smaller regions called
sectors.
A sector is the smallest addressable segment (part) of a
track.
The division of a track into sectors is done by hardware or
software format operation.
Blocks:
Since the entire track length is too large for data to be
transferred by a single Input/Output command, the data is
stored on the track in a number of blocks of equal length.
Page 4
Unit-5 Device Management
A block may be equal to a sector or a number of sectors. Infact, the block size determines the basic
unit of data which is read or written by a single Input/Output command. The blocks are separated by a
gap (G) and this gap reduces this storage capacity of data.
A small block size increases the number of gaps thereby causing wastage of storage space. Very large
blocks on the other hand create problems for processor requiring larger main memory in which data is
to be transferred.
1. Contiguous Allocation:
This allocation method requires each file to occupy a set of contiguous blocks on the disk.
Contiguous allocation of file is defined by disk address and length [ In Block Unit]
Page 5
Unit-5 Device Management
The directory entry for each file indicated the address of starting block and length of area allocated for
this file.
Sequential and direct access method can be supported by contiguous allocation.
One difficulty with contiguous allocation is finding a space for new file of dynamic storage allocation.
It is also suffer from external fragmentation.
As file are allocated and deallocated, the free disk space is broken into pieces. External fragmentation
exists whenever a free space is broken into chunks.
It becomes a problem when the largest contiguous chunk is insufficient for a request, depending on
total amount of disk storage and average file size; external fragmentation may be either a minor or
major problem.
We can solve external fragmentation using compaction technique.
🞜 Copy the entire file system onto another floppy disk or tap. The original disk was then free
completely.
🞜 Creating one large contiguous free space then copy the files back onto the floppy disk by
allocating contiguous space.
🞜 That also makes one large contiguous free space chunks.
🞜 The cost of this compaction is time.
Another major problem is determining how much space is needed for a file.
A file that grow slowly over long period of time must be allocated enough space for its final size, even
through much of that space may be unused for a long time. This is known as a Internal Fragmentation.
2. Linked Allocation:
It solves all the problem of contiguous allocation.
With linked allocation each file is linked list of disk block, the disk block may be scattered anywhere on
the disk.
Page 6
Unit-5 Device Management
The directory contains a pointer to the first and last block of file.
To create a new file, we simply create a new entry in the directory.
With linked allocation, each directory entry has a pointer to the first disk block of the file. This pointer
is initialized to nil (the end-of-list pointer value) to signify an empty file. The value -1 may be used for
NIL to differentiate it from block 0.
The size field also set to zero.
A write to a file removes the first free block and writes to that block. This new block is then linked to
the end of the file. To read a file, the pointers are just followed from block to block.
Advantages:
1. There is no external fragmentation with linked allocation. Any free block can be used to satisfy a
request.
2. There is no need to declare the size of a file when that file is created.
Disadvantages:
1. The major problem is that it is inefficient to support direct-access; it is effective only for sequential-
access files. E.g. To find the i th block of a file, it must start at the beginning of that file and follow the
pointers until the ith block is reached. Note that each access to a pointer requires a disk read.
2. Space required for the pointer that can be solves using clusters and to allocate clusters rather than
blocks.
3. A bug in OS or disk hardware failure might result in pointers being lost and damaged. It also solves
using doubly link list.
A section of disk at the beginning of each volume is reserved to store a table, called FAT.
This table has one entry for each block in the file system.
It is indexed by block number.
Then FAT is used just as linked list.
The only difference is instead of block itself, the FAT has pointers.
An important variation on linked allocation method is the use of file allocation table (FAT).
Page 7
Unit-5 Device Management
3. Indexed Allocation:
Indexed allocation solves the problem by bringing all the pointers together into one location is called
indexed block.
Each file has its own indexed block which is
an array of disk block addresses.
To read the ith block we use the pointer to find
and read desire block.
When the file is created all the pointers in the
indexed block are set to NIL.
When the ith block is first written, a block is
obtained from free space manager, and its
address is put in the ith indexed block entry.
It support direct access method without
suffering from external fragmentation.
It suffers from wastage space.
It also raises the question of how long the
indexed block should be.
Every file must have an indexed block so it
should be as small as possible and if it is too
small however it will not able to hold enough
pointers for large file and mechanism will have to be available to deal with this issue.
Advantages:
1. This supports direct access to the blocks occupied by the file and therefore provides fast access to
the file blocks.
2. It overcomes the problem of external fragmentation.
Page 8
Unit-5 Device Management
Disadvantages:
1. The pointer overhead for indexed allocation is greater than linked allocation.
2. For very small files, say files that expand only 2-3 blocks, the indexed allocation would keep one
entire block (index block) for the pointers which is inefficient in terms of memory utilization.
However, in linked allocation we lose the space of only 1 pointer per block.
3. For files that are very large, single index block may not be able to hold all the pointers.
Following mechanisms can be used to resolve this:
1. Linked scheme: This scheme links two or more index blocks together for holding the pointers.
Every index block would then contain a pointer or the address to the next index block.
2. Multilevel index: In this policy, a first level index block is used to point to the second level index
blocks which in turn points to the disk blocks occupied by the file. This can be extended to 3 or more
levels depending on the maximum file size.
3. Combined Scheme: In this scheme, a
special block called the Inode
(information Node) contains all the
information about the file such as the
name, size, authority, etc and the
remaining space of Inode is used to
store the Disk Block addresses which
contain the actual file as shown in the
image below. The first few of these
pointers in Inode point to the direct
blocks i.e the pointers contain the
addresses of the disk blocks that
contain data of the file. The next few
pointers point to indirect blocks.
Indirect blocks may be single indirect,
double indirect or triple indirect. Single
Indirect block is the disk block that
does not contain the file data but the
disk address of the blocks that contain
the file data. Similarly, double indirect
blocks do not contain the file data but
the disk address of the blocks that
contain the address of the blocks
containing the file data.
Since disk space is limited, we need to reuse the space from deleted files for new files, if possible.
To keep track of free disk space, the system maintains a free-space list.
The free-space list records all free disk blocks.
To create a file, we search the free-space list for the required amount of space and allocate that space
to the new file.
When a file is deleted, its disk space is added to the free-space list.
Page 9
Unit-5 Device Management
Free space is generally not managed by a simple free list. It can be implemented by various techniques
Like,
1. Bit Vector
2. Linked List
3. Grouping
4. Counting
1. Bit- Vector
The Free space list is implemented as a bit map or bit vector
Each block is represented by one bit (0 or 1)
If the block is free the bit is 1. If the block is allocated bit is 0.
For e.g. Consider a disk where blocks 2,3,5,8,9,12 are free and rest of the blocks are allocated.
Then the free space bit map would be
001101001100100…
The main advantages of this approach are that it is relatively simple and efficient to find first free
block from ‘n’ consecutive free blocks on
the disk.
2. Linked List
Another approach is to link together all the
free disk blocks, keeping a pointer to the
first free block in a special location on the
disk and coaching it in memory.
The first block contains a pointer to the next
free disk block and so on.
For e.g. We would keep a pointer to the
block no.2 as the first free block, the block
no.2 would contain the pointer to block no.3
which would point to block no.5 and so on.
This scheme is not efficient to traverse a list
we must read each block.
3. Grouping
A modification of free list approach is to store the addresses of N free blocks in the first free block.
The importance of this implementation is that the addresses of large number of free blocks can be
found quickly.
4. Counting
Another approach is to take the advantage of fact that, several contiguous block may be allocated
or free simultaneously.
In this approach keeping a list of n free disk addresses and the number n of free contiguous blocks
that follow the first block.
Each entry in the free space list consists of disk address and count.
Page 10
Unit-5 Device Management
Disk Scheduling Algorithms
Disk scheduling is done by operating systems to schedule I/O requests arriving for the disk.
Disk scheduling is also known as I/O scheduling.
Disk scheduling is important because:
🞜 Multiple I/O requests may arrive by different processes and only one I/O request can be served at a
time by the disk controller. Thus other I/O requests need to wait in the waiting queue and need to be
scheduled.
🞜 Two or more request may be far from each other so can result in greater disk arm movement.
🞜 Hard drives are one of the slowest parts of the computer system and thus need to be accessed in an
efficient manner.
There are many Disk Scheduling Algorithms but before discussing them let’s have a quick look at some of
the important terms:
Seek Time: Seek time is the time taken to locate the disk arm to a specified track where the data is
to be read or write. So the disk scheduling algorithm that gives minimum average seek time is better.
Rotational Latency: Rotational Latency is the time taken by the desired sector of disk to rotate into a
position so that it can access the read/write heads. So the disk scheduling algorithm that gives
minimum rotational latency is better.
Transfer Time: Transfer time is the time to transfer the data. It depends on the rotating speed of the
disk and number of bytes to be transferred.
Disk Access Time: Disk Access Time is:
Disk Access Time = Seek Time + Rotational Latency + Transfer Time
Disk Response Time: Response Time is the average of time spent by a request waiting to perform its
I/O operation. Average Response time is the response time of the all requests. Variance Response
Time is measure of how individual request are serviced with respect to average response time. So the
disk scheduling algorithm that gives minimum variance response time is better.
Purpose of Disk Scheduling
The main purpose of disk scheduling algorithm is to select a disk request from the queue of IO requests
and decide the schedule when this request will be processed.
Page 11
Unit-5 Device Management
1. FCFS: FCFS is the simplest of all the Disk Scheduling Algorithms. In FCFS, the requests are addressed
in the order they arrive in the disk queue.
Advantages:
1. Every request gets a fair chance
2. No indefinite postponement
Disadvantages:
1. Does not try to optimize seek time
2. May not provide the best possible service
Example
Consider the following disk request sequence for a disk with 100 tracks 45, 21, 67, 90, 4, 50, 89, 52, 61,
87, 25. Head pointer is starting at 50 and moving in left direction. Find the number of head movements in
cylinders using FCFS scheduling.
2. SSTF: In SSTF (Shortest Seek Time First), requests having shortest seek time are executed first. So,
the seek time of every request is calculated in advance in the queue and then they are scheduled
according to their calculated seek time. As a result, the request near the disk arm will get executed
first. SSTF is certainly an improvement over FCFS as it decreases the average response time and
increases the throughput of system.
Advantages:
1. Average Response Time decreases
2. Throughput increases
Disadvantages:
1. Overhead to calculate seek time in advance
2. Can cause Starvation for a request if it has higher seek time as compared to incoming requests
Page 12
Unit-5 Device Management
3. High variance of response time as SSTF favours only some requests
Example
Consider the following disk request sequence for a disk with 100 tracks
45, 21, 67, 90, 4, 89, 52, 61, 87, 25
Head pointer starting at 50. Find the number of head movements in cylinders using SSTF scheduling.
Solution:
3. SCAN: In SCAN algorithm the disk arm moves into a particular direction and services the requests
coming in its path and after reaching the end of disk, it reverses its direction and again services the
request arriving in its path. So, this algorithm works as an elevator and hence also known
as elevator algorithm. As a result, the requests at the midrange are serviced more and those
arriving behind the disk arm will have to wait.
Advantages:
1. High throughput
2. Low variance of response time
3. Average response time
Disadvantages:
1. Long waiting time for requests for locations just visited by disk arm
Example
Consider the following disk request sequence for a disk with 100 tracks
98, 137, 122, 183, 14, 133, 65, 78
Head pointer is starting at 54 and moving in left direction. Find the number of head movements in
cylinders using SCAN scheduling.
Page 13
Unit-5 Device Management
4. CSCAN: In SCAN algorithm, the disk arm again scans the path that has been scanned, after
reversing its direction. So, it may be possible that too many requests are waiting at the other end or
there may be zero or few requests pending at the scanned area. These situations are avoided
in CSCAN algorithm in which the disk arm instead of reversing its direction goes to the other end of
the disk and starts servicing the requests from there. So, the disk arm moves in a circular fashion
and this algorithm is also similar to SCAN algorithm and hence it is known as C-SCAN (Circular
SCAN).
Advantages:
Provides more uniform wait time compared to SCAN
Example
Consider the following disk request sequence for a disk with 100 tracks
98, 137, 122, 183, 14, 133, 65, 78
Head pointer is starting at 54 and moving in left direction. Find the number of head movements in
cylinders using C-SCAN scheduling.
Page 14
Unit-5 Device Management
5. LOOK: It is similar to the SCAN disk scheduling algorithm except for the difference that the disk arm
in spite of going to the end of the disk goes only to the last request to be serviced in front of the
head and then reverses its direction from there only. Thus it prevents the extra delay which occurred
due to unnecessary traversal to the end of the disk.
Example
Consider the following disk request sequence for a disk with 100 tracks
98, 137, 122, 183, 14, 133, 65, 78
Head pointer is starting at 54 and moving in left direction. Find the number of head movements in
cylinders using LOOK scheduling.
6. CLOOK: As LOOK is similar to SCAN algorithm, in similar way, CLOOK is similar to CSCAN disk
scheduling algorithm. In CLOOK, the disk arm in spite of going to the end goes only to the last
request to be serviced in front of the head and then from there goes to the other end’s last request.
Thus, it also prevents the extra delay which occurred due to unnecessary traversal to the end of the
disk.
Example
Consider the following disk request sequence for a disk with 100 tracks
98, 137, 122, 183, 14, 133, 65, 78
Head pointer is starting at 54 and moving in left direction. Find the number of head movements in
cylinders using C LOOK scheduling.
Page 15
Unit-5 Device Management
2. Oct/Nov 2018
3. March/April 2018
Page 16
Unit-5 Device Management
March/april-2017
October 2017
Page 17