Os Notes Module5
Os Notes Module5
'Disk Scheduling Algorithm' is an algorithm that keeps and manages input and output
requests arriving for the disk in a system. As we know, for executing any process memory is
required. And when it comes to accessing things from a hard disk, the process becomes very
slow as a hard disk is the slowest part of our computer. There are various methods by which
the process can be scheduled and can be done efficiently.
There are many terms that we need to know for a better understanding of Disk Scheduling.
We are going to have a brief look at each of them one by one:
Seek Time: As we know, the data may be stored on various blocks of disk. To
access these data according to the request, the disk arm moves and find the
required block. The time taken by the arm in doing this search is known as "Seek
Time".
Rotational Latency: The required data block needs to move at a particular position
from where the read/write head can fetch the data. So, the time taken in this
movement is known as "Rotational Latency". This rotational time should be as less
as possible so, the algorithm that will take less time to rotate will be considered a
better algorithm.
Transfer Time: When a request is made from the user side, it takes some time to
fetch these data and provide them as output. This taken time is known as "Transfer
Time".
Disk Access Time: It is defined as the total time taken by all the above processes.
Disk access time = (seek time + rotational latency time + transfer time)
Disk Response Time: The disk processes one request at a single time. So, the other
requests wait in a queue to finish the ongoing process of request. The average of
this waiting time is called "Disk Response Time".
Starvation: Starvation is defined as the situation in which a low-priority job keeps
waiting for a long time to be executed. The system keeps sending high-priority jobs
to the disk scheduler to execute first.
We have various types of Disk Scheduling Algorithms available in our system. Each one has
its own capabilities and weak points.
1. FCFS disk scheduling algorithm-
It stands for 'first-come-first-serve'. As the name suggests, the request which comes first will
be processed first and so on. The requests coming to the disk are arranged in a proper
sequence as they arrive. Since every request is processed in this algorithm, so there is no
chance of 'starvation'.
"Seek time" will be calculated by adding the head movement differences of all the requests:
Seek time= "(82-50) + (170-82) + (170-43) + (140-43) + (140-24) + (24-16) + (190-16) = 642
Advantages:
1. Implementation is easy.
2. No chance of starvation.
Disadvantages:
It stands for 'Shortest seek time first'. As the name suggests, it searches for the request
having the least 'seek time' and executes them first. This algorithm has less 'seek time' as
compared to FCFS Algorithm.
Explanation: The disk arm searches for the request which will have the least difference in
head movement. So, the least difference is (50-43). Here the difference is not about the
shortest value but it is about the shortest time the head will take to reach the nearest next
request. So, after 43, the head will be nearest to 24, and from here the head will be nearest to
the request 16, After 16, the nearest request is 82, so the disk arm will move to serve request
82 and so on.
Hence, Calculation of Seek Time = (50-43) + (43-24) + (24-16) + (82-16) + (140-82) + (170-140)
+ (190-170) = 208
Advantages
Disadvantages:
Explanation: In the above image, we can see that the disk arm starts from position 50 and
goes in a single direction until it reaches the end of the disk i.e.- request position 199. After
that, it reverses and starts servicing in the opposite direction until reached the other end of the
disk. This process keeps going on until the process is executed. Hence, Calculation of 'Seek
Time' will be like: (199-50) + (199-16) =332
Advantages:
1. Implementation is easy.
2. Requests do not have to wait in a queue.
Disadvantage:
1. The head keeps going on to the end even if there are no requests in that
direction.
Explanation: In the above figure, the disk arm starts from position 50 and reached the
end(199), and serves all the requests in the path. Then it reverses the direction and moves to
the other end of the disk i.e.- 0 without serving any task in the path. After reaching 0, it will
again go move towards the largest remaining value which is 43. So, the head will start from 0
and moves to request 43 serving all the requests coming in the path. And this process keeps
going.
Advantages:
1. The waiting time is uniformly distributed among the requests.
2. Response time is good in it.
Disadvantages:
1. The time taken by the disk arm to locate a spot is increased here.
2. The head keeps going to the end of the disk.
5. LOOK the disk scheduling algorithm:
In this algorithm, the disk arm moves to the 'last request' present and services them. After
reaching the last requests, it reverses its direction and again comes back to the starting point.
It does not go to the end of the disk, in spite, it goes to the end of requests.
Explanation: The disk arm is starting from 50 and starts to serve requests in one direction
only but in spite of going to the end of the disk, it goes to the end of requests i.e.-190. Then
comes back to the last request of other ends of the disk and serves them. And again starts
from here and serves till the last request of the first side. Hence, Seek time =(190-50) + (190-
16) =314
Advantages:
Disadvantage:
The C-Look algorithm is almost the same as the Look algorithm. The only difference is that
after reaching the end requests, it reverses the direction of the head and starts moving to the
initial position. But in moving back, it does not serve any requests.
Explanation: The disk arm is starting from 50 and starts to serve requests in one direction
only but in spite of going to the end of the disk, it goes to the end of requests i.e.-190. Then
comes back to the last request of other ends of a disk without serving them. And again starts
from the other end of the disk and serves requests of its path. Hence, Seek Time = (190-50) +
(190-16) + (43-16) =341
Advantages:
Disadvantage:
File Organization
File organization ensures that records are available for processing. It is used to determine an
efficient file organization for each base relation. For example, if we want to retrieve employee
records in alphabetical order of name. Sorting the file by employee name is a good file
organization. However, if we want to retrieve all employees whose marks are in a certain
range, a file is ordered by employee name would not be a good file organization.
Types of File Organization
There are three types of organizing the file:
1. Sequential access file organization
2. Direct access file organization
3. Indexed sequential access file organization
1. Sequential access file organization
• Storing and sorting in contiguous block within files on tape or disk is called as sequential
access file
organization.
• In sequential access file organization, all records are stored in a sequential order. The
records are arranged in the ascending or descending order of a key field.
• Sequential file search starts from the beginning of the file and the records can be added at
the end of the file.
• In sequential file, it is not possible to add a record in the middle of the file without rewriting
the file.
Advantages of sequential file
• It is simple to program and easy to design.
• Sequential file is best use if storage space.
Disadvantages of sequential file
• Sequential file is time consuming process.
• It has high data redundancy.
• Random searching is not possible.
2. Direct access file organization
• Direct access file is also known as random access or relative file organization.
• In direct access file, all records are stored in direct access storage device (DASD), such as
hard disk. The records are randomly placed throughout the file.
• The records does not need to be in sequence because they are updated directly and
rewritten back in the same location.
• This file organization is useful for immediate access to large amount of information. It is
used in accessing large databases.
• It is also called as hashing.
Advantages of direct access file organization
• Direct access file helps in online transaction processing system (OLTP) like online railway
reservation system.
• In direct access file, sorting of the records are not required.
• It accesses the desired records immediately.
• It updates several files quickly.
• It has better control over record allocation.
Disadvantages of direct access file organization
• Direct access file does not provide back up facility.
• It is expensive.
• It has less storage space as compared to sequential file.
3. Indexed sequential access file organization
• Indexed sequential access file combines both sequential file and direct access file
organization.
• In indexed sequential access file, records are stored randomly on a direct access device
such as magnetic disk by a primary key.
• This file have multiple keys. These keys can be alphanumeric in which the records are
ordered is called primary key.
• The data can be access either sequentially or randomly using the index. The index is stored
in a file and read into memory when the file is opened.
Advantages of Indexed sequential access file organization
• In indexed sequential access file, sequential file and random file access is possible.
• It accesses the records very fast if the index table is properly organized.
• The records can be inserted in the middle of the file.
• It provides quick access for sequential and direct processing.
• It reduces the degree of the sequential search.
Disadvantages of Indexed sequential access file organization
• Indexed sequential access file requires unique keys and periodic reorganization.
• Indexed sequential access file takes longer time to search the index for the data access or
retrieval.
• It requires more storage space.
• It is expensive because it requires special software.
• It is less efficient in the use of storage space as compared to other file organizations.
File-System Structure
Computers can store information on various storage media, such as magnetic disks,
magnetic tapes, and optical disks. So that the computer system will be convenient to use,
the operating system provides a uniform logical view of information storage.
The operating system abstracts from the physical properties of its storage devices to
define a logical storage unit, the file.
Files are mapped by the operating system onto physical devices. These storage devices
are usually nonvolatile, so the contents are persistent through power failures and system
reboots.
A file is a named collection of related information that is recorded on secondary storage.
From a user's perspective, a file is the smallest allotment of logical secondary storage;
that is, data cannot be written to secondary storage unless they are within a file.
Commonly, files represent programs (bothsource and object forms) and data.
Data files may be numeric, alphabetic, alphanumeric, or binary.
Files may be free form, such as text files, or may be formatted rigidly.
In general, a file is a sequence of bits, bytes, lines, or records, the meaning of which is
defined by the file's creator and user.
The concept of a file is thus extremely generaL The information in a file is defined by its
creator. Many different types of information may be stored in a file-source programs,
object programs, executable programs, numeric data, text, payroll records, graphic images,
sound recordings, and so on.
A file has a certain defined which depends on its type.
A text file is a sequence of characters organized into lines (and possibly pages).
A source file is a sequence of subroutines and functions, each of which is further
organized as declarations followed by executable statements.
An object file is a sequence of bytes organized in.to blocks nnderstandable by the
system's linker. An executable file is a series of code sections that the loader can
bring into memory and execute.
The layered approach to file systems means that much of the code can be used uniformly
for a wide variety of different file systems, and only certain layers need to be file system
specific. Common file systems in use include the UNIX file system, UFS, the Berkeley Fast
File System, FFS, Windows systems FAT, FAT32, NTFS, CD-ROM systems ISO 9660, and
for Linux the extended file systems ext2 and ext3 ( among 40 others supported. )
File Attributes
A file is named, for the convenience of its human users, and is referred to by its name. A name
is usually a string of characters, such as example.c. Some systems differentiate between
uppercase and lowercase characters in names, whereas other systems do not. When a file is
named, it becomes independent of the process, the user, and even the system that created it.
A file's attributes vary from one operating system to another but typically consist of these:
Name. The symbolic file name is the only information kept in humanreadable form.
Identifier. This unique tag, usually a number, identifies the file within the file system; it is
the non-human-readable name for the file.
Type. This information is needed for systems that support different types of files.
Location. This information is a pointer to a device and to the location of the file on that
device.
Size. The current size of the file (in bytes, words, or blocks) and possibly the maximum
allowed size are included in this attribute.
Protection. Access-control information determines who can do reading, writing, executing,
and so on.
Time, date, and user identification. This information may be kept for creation, last
modification, and last use. These data can be useful for protection, security, and usage
monitoring.
File Operations
A file is an To define a file properly, we need to consider the operations that can be
performed on files. The operating system can provide system calls to create, write, read,
reposition, delete, and truncate files. Let's examine what the operating system must do to
perform each of these six basic file operations. It should then be easy to see how other
similar operations, such as renaming a file, can be implemented.
Creating a file. Two steps are necessary to create a file. First, space in the file system must
be found for the file. Second, an entry for the new file must be made in the directory.
Writing a file. To write a file, we make a system call specifying both the name of the file and
the information to be written to the file. Given the name of the file, the system searches the
directory to find the file's location. The system must keep a write pointer to the location in the
file where the next write is to take place. The write pointer must be updated whenever a write
occurs.
Reading a file. To read from a file, we use a system call that specifies the name of the file and
where (in memory) the next block of the file should be put. Again, the directory is searched for
the associated entry, and the system needs to keep a read pointer to the location in the file
where the next read is to take place. Once the read has taken place, the read pointer is
updated. Because a process is usually either reading from or writing to a file, the current
operation location can be kept as a per-process . Both the read and write operations use this
same pointer, saving space and reducing system complexity.
Repositioning within a file. The directory is searched for the appropriate entry, and the current
-file-position pointer is repositioned to a given value. Repositioning within a file need not
involve any actual I/0. This file operation is also kn.own as a file seek.
Deleting a file. To delete a file, we search the directory for the named file. Having found the
associated directory entry, we release all file space, so that it can be reused by other files, and
erase the directory entry.
Truncating a file. The user may want to erase the contents of a file but keep its attributes.
Rather than forcing the user to delete the file and then recreate it, this function allows all
attributes to remain unchanged -except for file length-but lets the file be reset to length zero
and its file space released.
File-System Implementation
Physical disks are commonly divided into smaller units called partitions. They
can also be combined into larger units, but that is most commonly done for
RAID installations and is left for later chapters.
Partitions can either be used as raw devices ( with no structure imposed
upon them ), or they can be formatted to hold a filesystem ( i.e. populated
with FCBs and initial directory structures as appropriate. ) Raw partitions are
generally used for swap space, and may also be used for certain programs
such as databases that choose to manage their own disk storage system.
Partitions containing filesystems can generally only be accessed using the
file system structure by ordinary users, but can often be accessed as a raw
device also by root.
The boot block is accessed as part of a raw partition, by the boot program
prior to any operating system being loaded. Modern boot programs
understand multiple OSes and filesystem formats, and can give the user a
choice of which of several available systems to boot.
The root partition contains the OS kernel and at least the key portions of the
OS needed to complete the boot process. At boot time the root partition is
mounted, and control is transferred from the boot program to the kernel
found there. ( Older systems required that the root partition lie completely
within the first 1024 cylinders of the disk, because that was as far as the boot
program could reach. Once the kernel had control, then it could access
partitions beyond the 1024 cylinder boundary. )
Continuing with the boot process, additional filesystems get mounted, adding
their information into the appropriate mount table structure. As a part of the
mounting process the file systems may be checked for errors or
inconsistencies, either because they are flagged as not having been closed
properly the last time they were used, or just for general principals.
Filesystems may be mounted either automatically or manually. In UNIX a
mount point is indicated by setting a flag in the in-memory copy of the inode,
so all future references to that inode get re-directed to the root directory of
the mounted filesystem.
Directory Structure
Single-level directory
The single-level directory is the simplest directory structure. In it, all files are
contained in the same directory which makes it easy to support and understand. A
single level directory has a significant limitation, however, when the number of files
increases or when the system has more than one user.
The Advantages:
The Disadvantages:
As several users can log in at the same system for logging their files
maintaining a unique name becomes difficult leading to a collision. This also
means that if the file with the same name is created then the old file will get
destroyed first, then the new file (having the same name ) created will be
replacing it.
If the size of the files is bigger then searching the files in one root directory of
the single-level directory structure will become time taking and hence difficult.
The single-level directory structure restricts the grouping of the same type of
files together.
Advantages:
In the two-level directory structure in OS different users have the right to have
the same directory as well as a file name as the user has its own USD which
can give a filename that can match other users but won't cause an issue.
We can also see that searching for files become much simpler.
As we have a user-defined directory this also provides privacy related to files
stored as no user can enter the other user’s directory without permission.
In a two-level directory structure we cannot group the files which are having
the same name into a single directory for a specific user.
Disadvantages:
In a two-level directory structure a user is not allowed to share files with other
users.
We also find that scalability is not present in a two-level directory structure
as two files of the same type cannot be grouped together in the same user.
Here users cannot create subdirectories only one user file directory can be
defined under one master file directory.
Advantages:
Disadvantages:
Directory Implementation
Directories need to be fast to search, insert, and delete, with a minimum of
wasted disk space.
Allocation Methods
There are three major methods of storing files on disks: contiguous, linked, and indexed.
I Contiguous Allocation
II Linked Allocation
Disk files can be stored as linked lists, with the expense of the storage space
consumed by each link. ( E.g. a block may be 508 bytes instead of 512. )
Linked allocation involves no external fragmentation, does not require pre-
known file sizes, and allows files to grow dynamically at any time.
Unfortunately linked allocation is only efficient for sequential access files, as
random access requires starting at the beginning of the list for each new
location access.
Allocating clusters of blocks reduces the space wasted by pointers, at the
cost of internal fragmentation.
Another big problem with linked allocation is reliability if a pointer is lost or
damaged. Doubly linked lists provide some protection, at the cost of
additional overhead and wasted space.
Linked allocation of disk space
Indexed Allocation combines all of the indexes for accessing each file into a
common block ( for that file ), as opposed to spreading them all over the disk
or storing them in a FAT table.
There are some methods or techniques to implement a free space list. These are
as follows:
1. Bitmap
2. Linked list
3. Grouping
4. Counting
1. Bitmap
This technique is used to implement the free space management. When the free
space is implemented as the bitmap or bit vector then each block of the disk is
represented by a bit. When the block is free its bit is set to 1 and when the block is
allocated the bit is set to 0. The main advantage of the bitmap is it is relatively
simple and efficient in finding the first free block and also the consecutive free
block in the disk. Many computers provide the bit manipulation instruction which is
used by the users.
Advantages
Disadvantages
This is another technique for free space management. In this linked list of all the
free block is maintained. In this, there is a head pointer which points the first free
block of the list which is kept in a special location on the disk. This block contains
the pointer to the next block and the next block contain the pointer of another next
and this process is repeated. By using this disk it is not easy to search the free list.
This technique is not sufficient to traverse the list because we have to read each
disk block that requires I/O time. So traversing in the free list is not a frequent
action.
Advantages
Disadvantages
Searching the free space list will be very time consuming; each block will
have to be read from the disk, which is read very slowly as compared to the
main memory.
Not Efficient for faster access.
In our earlier example, we see that keep block 2 is the first free block which points
to another block which contains the pointer of the 3 blocks and 3 blocks contain
the pointer to the 4 blocks and this contains the pointer to the 5 block then 5 block
contains the pointer to the next block and this process is repeated at the last .
3. Grouping
Counting is another approach for free space management. Generally, some contiguous blocks
are allocated but some are free simultaneously. When the free space is allocated to a process
according to the contiguous allocation algorithm or clustering. So we cannot keep the list of n
free block address but we can keep the address of the first free block and then the numbers
of n free contiguous block which follows the first block. When there is an entry in the free
space list it consists the address of the disk and a count variable. This method of free space
management is similar to the method of allocating blocks. We can store these entries in the B
-tree in place of the linked list. So the operations like lookup, deletion, insertion are efficient.