File and Disk Managment Allocation Methods
File and Disk Managment Allocation Methods
Allocation Methods
There are various methods which can be used to allocate disk space to the
files. Selection of an appropriate allocation method will significantly affect
the performance and efficiency of the system. Allocation method provides a
way in which the disk will be utilized and the files will be accessed.
Contiguous Allocation
If the blocks are allocated to the file in such a way that all the logical blocks of the file
get the contiguous physical block in the hard disk then such allocation scheme is known
as contiguous allocation.
In the image shown below, there are three files in the directory. The starting block and
the length of each file are mentioned in the table. We can check in the table that the
contiguous blocks are assigned to each file as per its need.
Advantages
1. It is simple to implement.
2. We will get Excellent read performance.
3. Supports Random Access into files.
Disadvantages
1. The disk will become fragmented.
2. It may be difficult to have a file grow.
Linked List Allocation
In linked list allocation, each file is considered as the linked list of disk
blocks. However, the disks blocks allocated to a particular file need not to
be contiguous on the disk. Each disk block allocated to a file contains a
pointer which points to the next disk block allocated to the same file.
Advantages
1. There is no external fragmentation with linked allocation.
2. Any free block can be utilized in order to satisfy the file block requests.
3. File can continue to grow as long as the free blocks are available
Dynamic growth.
4. Directory entry will only contain the starting block address.
Disadvantages
1. Random Access is not provided.
2. Pointers require some space in the disk blocks.
3. Any of the pointers in the linked list must not be broken otherwise the
file will get corrupted.
4. Need to traverse each block.
File Allocation Table
The main disadvantage of linked list allocation is that the Random access to
a particular block is not provided.
File Allocation Table overcomes this drawback of linked list allocation. In this
scheme, a file allocation table is maintained, which gathers all the disk block
links. The table has one entry for each disk block and is indexed by block
number.
It simply accesses the file allocation table, read the desired block entry from
there and access that block. This is the way by which the random access is
accomplished by using FAT. It is used by MS-DOS and pre-NT Windows
versions.
Advantages
1. Uses the whole disk block for data.
2. A bad disk block doesn't cause all successive blocks lost.
3. Random access is provided although its not too fast.
4. Only FAT needs to be traversed in each file operation.
Disadvantages
1. Each Disk block needs a FAT entry.
2. FAT size may be very big depending upon the number of FAT entries.
3. Number of FAT entries can be reduced by increasing the block size but
it will also increase Internal Fragmentation.
Q1.In an MS-DOS disk system, calculate the number of entries (i.e., No. of clusters) required in
the FAT table. Assume the following parameters: Disk Capacity - 40 Mbytes Block Size - 512
Bytes Blocks/Cluster- 4
Q2.Assuming a cluster size of 512 bytes calculate the percentage wastage in file space due to
incomplete filling of last cluster, for the file sizes below: (i) 1000 bytes (ii) 20,000 bytes
Ans 1.File size = 1000 bytes
No. of clusters = 1000/512 = 2(approximately)
Total cluster capacity = 2*512 = 1024 bytes
Wasted space = 1024-1000 = 24 bytes
Percentage Wasted space = (24 / 1024)*100 = 2.3%
Advantages
1. Supports direct access
2. A bad data block causes the lost of only that block.
Disadvantages
1. A bad index block could cause the lost of entire file.
2. Size of a file depends upon the number of pointers, a index block can
hold.
3. Having an index block for a small file is totally wastage.
4. More pointer overhead
Linked Index Allocation
Single level linked Index Allocation
In index allocation, the file size depends on the size of a disk block. To allow
large files, we have to link several index blocks together. In linked index
allocation,
For the larger files, the last entry of the index block is a pointer which points
to another index block. This is also called as linked schema.
o The outer level index is used to find the inner level index.
o The inner level index is used to find the desired data block.
Advantage: Random Access becomes better and efficient.
Advantages –
o Simple to understand.
Linked List –
In this approach, the free disk blocks are linked together i.e. a free block contains a
pointer to the next free block. The block number of the very first disk block is stored at a
separate location on disk and is also cached in memory.
In Figure-2, the free space list head points to Block 5 which points to Block 6, the next free
block and so on. The last free block would contain a null pointer indicating the end of free
list.
A drawback of this method is the I/O required for free space list traversal.
Disk Scheduling
As we know, a process needs two type of time, CPU time and IO time. For
I/O, it requests the Operating system to access the disk.
However, the operating system must be fare enough to satisfy each request
and at the same time, operating system must maintain the efficiency and
speed of process execution.
The technique that operating system uses to determine the request, which is
to be satisfied next, is called disk scheduling.
Seek Time
Seek time is the time taken in locating the disk arm to a specified track
where the read/write request will be satisfied.
Rotational Latency
It is the time taken by the desired sector to rotate itself to the position from
where it can access the R/W heads.
Transfer Time
It is the average of time spent by each request waiting for the IO operation.
Purpose of Disk Scheduling
• As the name suggests, this algorithm entertains requests in the order they arrive in the
disk queue.
• It is the simplest disk scheduling algorithm.
Advantages-
It is simple, easy to understand and implement.
• It does not cause starvation to any request.
Disadvantages-
It results in increased total seek time.
• It is inefficient.
Problem-
Consider a disk queue with requests for I/O to blocks on cylinders 98, 183, 41, 122, 14,
124, 65, 67. The FCFS scheduling algorithm is used. The head is initially at cylinder number
53. The cylinders are numbered from 0 to 199. The total head movement (in number of
cylinders) incurred while servicing these requests is _______.
Solution-
Solution-
• As the name suggests, this algorithm scans all the cylinders of the disk back and forth.
• Head starts from one end of the disk and move towards the other end servicing all the
requests in between.
• After reaching the other end, head reverses its direction and move towards the starting
end servicing all the requests in between.
• The same process repeats.
NOTE-
SCAN Algorithm is also called as Elevator Algorithm.
• This is because its working resembles the working of an elevator.
Advantages-
It is simple, easy to understand and implement.
• It does not lead to starvation.
• It provides low variance in response time and waiting time.
Disadvantages-
It causes long waiting time for the cylinders just visited by the head.
• It causes the head to move till the end of the disk even if there are no requests to be
serviced.
Problem-
Consider a disk queue with requests for I/O to blocks on cylinders 98, 183, 41, 122, 14,
124, 65, 67. The SCAN scheduling algorithm is used. The head is initially at cylinder
number 53 moving towards larger cylinder numbers on its servicing pass. The cylinders are
numbered from 0 to 199. The total head movement (in number of cylinders) incurred while
servicing these requests is _______.
Solution-
Solution-
Total head movements incurred while servicing these requests
= (65 – 53) + (67 – 65) + (98 – 67) + (122 – 98) + (124 – 122) + (183 – 124) + (199 – 183) +
(199 – 0) + (14 – 0) + (41 – 14)
= 12 + 2 + 31 + 24 + 2 + 59 + 16 + 199 + 14 + 27
= 386
Alternatively,
Total head movements incurred while servicing these requests
= (199 – 53) + (199 – 0) + (41 – 0)
= 146 + 199 + 41
= 386
LOOK Disk Scheduling Algorithm-
Problem-
Consider a disk queue with requests for I/O to blocks on cylinders 98, 183, 41, 122, 14,
124, 65, 67. The LOOK scheduling algorithm is used. The head is initially at cylinder
number 53 moving towards larger cylinder numbers on its servicing pass. The cylinders are
numbered from 0 to 199. The total head movement (in number of cylinders) incurred while
servicing these requests is _______.
Solution-
Problem-01:
Consider a disk queue with requests for I/O to blocks on cylinders 98, 183, 41, 122, 14,
124, 65, 67. The C-LOOK scheduling algorithm is used. The head is initially at cylinder
number 53 moving towards larger cylinder numbers on its servicing pass. The cylinders are
numbered from 0 to 199. The total head movement (in number of cylinders) incurred while
servicing these requests is _______.
Solution-
Alternatively,
Total head movements incurred while servicing these requests
= (183 – 53) + (183 – 14) + (41 – 14)
= 130 + 169 + 27
= 326