0% found this document useful (0 votes)
120 views

File and Disk Managment Allocation Methods

The document discusses various file allocation methods used in disk management systems. It describes contiguous allocation, linked allocation, clustering, FAT, indexed allocation, linked indexed allocation, multilevel indexed allocation, and inodes. For each method, it outlines the advantages and disadvantages in terms of fragmentation, file growth ability, random access support, and other factors. It also discusses file allocation table (FAT) usage in DOS/Windows systems and free space management techniques like bitmap, linked list, and disk scheduling algorithms.

Uploaded by

Md Asif Alam
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
120 views

File and Disk Managment Allocation Methods

The document discusses various file allocation methods used in disk management systems. It describes contiguous allocation, linked allocation, clustering, FAT, indexed allocation, linked indexed allocation, multilevel indexed allocation, and inodes. For each method, it outlines the advantages and disadvantages in terms of fragmentation, file growth ability, random access support, and other factors. It also discusses file allocation table (FAT) usage in DOS/Windows systems and free space management techniques like bitmap, linked list, and disk scheduling algorithms.

Uploaded by

Md Asif Alam
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

File and Disk managment

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.

There are following methods which can be used for allocation.


1. Contiguous Allocation.
2. Linked Allocation
3. Clustering
4. FAT
5. Indexed Allocation
6. Linked Indexed Allocation
7. Multilevel Indexed Allocation
8. Inode

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.

In order to access a block, we need to access all its previous blocks.

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

Ans:- Cluster size= 4*512=2048 bytes

Number of clusters = (40*1,000,000)/2048=19531 approximately

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%

2.File size = 20,000 bytes


No. of clusters = 20,000/512 = 40(approximately)
Total cluster capacity = 40 * 512 = 20480 bytes
Wasted space = 20480-20,000 = 480 bytes
Percentage Wasted space = (480 / 20480) * 100 = 2.3%
Indexed Allocation
Instead of maintaining a file allocation table of all the disk pointers, Indexed
allocation scheme stores all the disk pointers in one of the blocks called as
indexed block. Indexed block doesn't hold the file data, but it holds the
pointers to all the disk blocks allocated to that particular file. Directory entry
will only contain the index block address.

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,

o Small header giving the name of the file


o Set of the first 100 block addresses
o Pointer to another index block

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.

Advantage: It removes file size limitations

Disadvantage: Random Access becomes a bit harder

Multilevel Index Allocation


In Multilevel index allocation, we have various levels of indices. There are
outer level index blocks which contain the pointers to the inner level index
blocks and the inner level index blocks contain the pointers to the file data.

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.

Disadvantage: Access time for a file will be higher.


Inode
In UNIX based operating systems, each file is indexed by an Inode. Inode
are the special disk block which is created with the creation of the file
system. The number of files or directories in a file system depends on the
number of Inodes in the file system.

An Inode includes the following information

1. Attributes (permissions, time stamp, ownership details, etc) of the file


2. A number of direct blocks which contains the pointers to first 12 blocks
of the file.
3. A single indirect pointer which points to an index block. If the file
cannot be indexed entirely by the direct blocks then the single indirect
pointer is used.
4. A double indirect pointer which points to a disk block that is a
collection of the pointers to the disk blocks which are index blocks.
Double index pointer is used if the file is too big to be indexed entirely
by the direct blocks as well as the single indirect pointer.
5. A triple index pointer that points to a disk block that is a collection of
pointers. Each of the pointers is separately pointing to a disk block
which also contains a collection of pointers which are separately
pointing to an index block that contains the pointers to the file blocks.
Operating System | Free space management
The system keeps tracks of the free disk blocks for allocating space to files when they are
created. Also, to reuse the space released from deleting the files, free space management
becomes crucial. The system maintains a free space list which keeps track of the disk
blocks that are not allocated to some file or directory. The free space list can be
implemented mainly as:
1. Bitmap or Bit vector –
A Bitmap or Bit Vector is series or collection of bits where each bit corresponds to a disk
block. The bit can take two values: 0 and 1: 0 indicates that the block is allocated and 1
indicates a free block.
The given instance of disk blocks on the disk in Figure 1 (where green blocks are
allocated) can be represented by a bitmap of 16 bits as: 0000111000000110.

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.

Let's discuss some important terms related to 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 time taken to transfer the data.

Disk Access Time

Disk access time is given as,

Disk Access Time = Rotational Latency + Seek Time + Transfer Time

Disk Response Time

It is the average of time spent by each request waiting for the IO operation.
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.

Goal of Disk Scheduling Algorithm


o Fairness
o High throughout
o Minimal traveling head time

Disk Scheduling Algorithms


The list of various disks scheduling algorithm is given below. Each algorithm
is carrying some advantages and disadvantages. The limitation of each
algorithm leads to the evolution of a new algorithm.

o FCFS scheduling algorithm


o SSTF (shortest seek time first) algorithm
o SCAN scheduling
o C-SCAN scheduling
o LOOK Scheduling
o C-LOOK scheduling

FCFS Disk Scheduling Algorithm-

• 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-

Total head movements incurred while servicing these requests


= (98 – 53) + (183 – 98) + (183 – 41) + (122 – 41) + (122 – 14) + (124 – 14) + (124 – 65) +
(67 – 65)
= 45 + 85 + 142 + 81 + 108 + 110 + 59 + 2
= 632
SSTF Disk Scheduling Algorithm-
• SSTF stands for Shortest Seek Time First.
• This algorithm services that request next which requires least number of head
movements from its current position regardless of the direction.
• It breaks the tie in the direction of head movement.
Advantages-
It reduces the total seek time as compared to FCFS.
• It provides increased throughput.
• It provides less average response time and waiting time.
Disadvantages-
There is an overhead of finding out the closest request.
• The requests which are far from the head might starve for the CPU.
• It provides high variance in response time and waiting time.
• Switching the direction of head frequently slows down the algorithm.
Problem-01:
Consider a disk queue with requests for I/O to blocks on cylinders 98, 183, 41, 122, 14, 124,
65, 67. The SSTF 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-

Total head movements incurred while servicing these requests


= (65 – 53) + (67 – 65) + (67 – 41) + (41 – 14) + (98 – 14) + (122 – 98) + (124 – 122) + (183
– 124)
= 12 + 2 + 26 + 27 + 84 + 24 + 2 + 59 = 236
SCAN Disk Scheduling Algorithm-

• 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-

Total head movements incurred while servicing these requests


= (65 – 53) + (67 – 65) + (98 – 67) + (122 – 98) + (124 – 122) + (183 – 124) + (199 – 183) +
(199 – 41) + (41 – 14)
= 12 + 2 + 31 + 24 + 2 + 59 + 16 + 158 + 27
= 331
Alternatively,
Total head movements incurred while servicing these requests
= (199 – 53) + (199 – 14)
= 146 + 185
= 331
C-SCAN Disk Scheduling Algorithm-
• Circular-SCAN Algorithm is an improved version of the SCAN Algorithm.
• 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.
• It then returns to the starting end without servicing any request in between.
• The same process repeats.
Advantages-
• The waiting time for the cylinders just visited by the head is reduced as compared to the
SCAN Algorithm.
• It provides uniform waiting time.
• It provides better response time.
Disadvantages-
• It causes more seek movements as compared to SCAN Algorithm.
• 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 C-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-
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-

• LOOK Algorithm is an improved version of the SCAN Algorithm.


• Head starts from the first request at one end of the disk and moves towards the last
request at the other end servicing all the requests in between.
• After reaching the last request at the other end, head reverses its direction.
• It then returns to the first request at the starting end servicing all the requests in between.
• The same process repeats.
NOTE-
The main difference between SCAN Algorithm and LOOK Algorithm is-
• SCAN Algorithm scans all the cylinders of the disk starting from one end to the other end
even if there are no requests at the ends.
• LOOK Algorithm scans all the cylinders of the disk starting from the first request at one
end to the last request at the other end.
Advantages-
It does not causes the head to move till the ends of the disk when there are no requests to
be serviced.
• It provides better performance as compared to SCAN Algorithm.
• It does not lead to starvation.
• It provides low variance in response time and waiting time.
Disadvantages-
There is an overhead of finding the end requests.
• It causes long waiting time for the cylinders just visited by the head.

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-

Total head movements incurred while servicing these requests


= (65 – 53) + (67 – 65) + (98 – 67) + (122 – 98) + (124 – 122) + (183 – 124) + (183 – 41) +
(41 – 14)
= 12 + 2 + 31 + 24 + 2 + 59 + 142 + 27
= 299
Alternatively,
Total head movements incurred while servicing these requests
= (183 – 53) + (183 – 14)
= 130 + 169
= 299

C-LOOK Disk Scheduling Algorithm-


• Circular-LOOK Algorithm is an improved version of the LOOK Algorithm.
• Head starts from the first request at one end of the disk and moves towards the last
request at the other end servicing all the requests in between.
• After reaching the last request at the other end, head reverses its direction.
• It then returns to the first request at the starting end without servicing any request in
between.
• The same process repeats.
Advantages-
• It does not causes the head to move till the ends of the disk when there are no requests
to be serviced.
• It reduces the waiting time for the cylinders just visited by the head.
• It provides better performance as compared to LOOK Algorithm.
• It does not lead to starvation.
• It provides low variance in response time and waiting time.
Disadvantages-
There is an overhead of finding the end requests.

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-

Total head movements incurred while servicing these requests


= (65 – 53) + (67 – 65) + (98 – 67) + (122 – 98) + (124 – 122) + (183 – 124) + (183 – 14) +
(41 – 14)
= 12 + 2 + 31 + 24 + 2 + 59 + 169 + 27
= 326

Alternatively,
Total head movements incurred while servicing these requests
= (183 – 53) + (183 – 14) + (41 – 14)
= 130 + 169 + 27
= 326

You might also like