OS - Unit 5 Complete
OS - Unit 5 Complete
Unit 5
• I/O Management and Disk Scheduling:
• I/O devices and I/O subsystems,
• I/O buffering,
• Disk storage and disk scheduling,
• RAID.
• File System:
• File concept,
• File organization and access mechanism,
• File directories, and File sharing,
• File system implementation issues,
• File system protection and security.
I/O Devices
• There are three Categories:
• Human readable: Devices used to
communicate with the user
• Printers and terminals,
Video display, Keyboard,
Mouse etc.
• Machine readable : Used to communicate
with electronic equipment
• Disk drives, USB keys,
USB keys, Sensors,
Controllers, Actuators
• Communications : Used to communicate
with remote devices
• Digital line drivers,
Modems
• I/O devices differ from each in a number
of respects–
• Data Rate
• Application
• Complexity of Control
• Unit of Transfer
• Data Representation
• Error Conditions
Techniques for performing I/O
Sync. And Async
• Programmed I/O
• Process is busy-waiting for the operation to complete
• Processes must wait for I/O to complete before proceeding
• To avoid deadlock certain pages must remain in main
memory during I/O
• It may be more efficient to perform input transfers in
advance of requests being made and to perform output
transfers some time after the request is made.
• Interrupt-driven I/O
• I/O command is issued
• Processor continues executing instructions
• I/O module sends an interrupt when done
• Processor does not spend time waiting for an I/O operation
to be performed
Techniques for performing I/O
• Direct Memory Access (DMA)
• DMA controls exchange of data
between main memory and
the I/O device
• Processor interrupted only
after entire block has been
transferred
• Blocks of data are moved into
memory without involving the
processor
• Processor involved at
beginning and end only
I/O Buffering
• Reasons for buffering
• Processes must wait for I/O to complete before proceeding
• Process cannot be entirely swapped out–corresponding pages must remain in main memory
during I/O
• Risk of single process deadlock– process swapped out before I/O operation starts
• Block-oriented
• Information is stored in fixed sized blocks
• Transfers are made a block at a time
• Used for disks and tapes
• User process can process one block of data while next block is read in Swapping can occur
since input is taking place in system memory, not user memory
• Operating system keeps track of assignment of system buffers to user processes
• Stream-oriented
• Transfer information as a stream of bytes
• Used for terminals, printers, communication ports, mouse and other pointing devices, and
most other devices that are not secondary storage.
• Used a line-at-a-time, e.g. line printer (or byte at- a-time, e.g., form-mode terminals)
• Output to the terminal is one line at a time
I/O Buffering
OS assigns a buffer in MM for an I/O request
Single Buffer
• Input transfers made to buffer
• Block moved to user space when needed
• Another block is moved into the buffer
(read ahead)
• Double Buffer
• Use two system buffers instead of one
• A process can transfer data to or from one
buffer while the operating system empties
or fills the other buffer
• Circular Buffer
• More than two buffers are used
• Each individual buffer is one unit in a
circular buffer
• Used when I/O operation must keep up
with process
Disk Structure
• 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.
• Average I/O time = average access time + (amount to transfer / transfer rate) +
controller overhead.
Disk Scheduling
• 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.
FCFS
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:
Every request gets a fair chance
No indefinite postponement
Disadvantages:
Does not try to optimize seek time
May not provide the best possible service
Shortest Seek Time First
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:
• Average Response Time decreases
• Throughput increases
Disadvantages:
• Overhead to calculate seek time in advance
• Can cause Starvation for a request if it has higher seek time as
compared to incoming requests
• High variance of response time as SSTF favours only some
requests
SCAN
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.
Suppose the requests to be addressed are-
82,170,43,140,24,16,190. And the Read/Write arm is at 50, and
it is also given that the disk arm should move “towards the
larger value”.
Therefore, the seek time is calculated as =(199-50)+(199-16)
=332
Advantages:
• High throughput
• Low variance of response time
• Average response time
Disadvantages:
• Long waiting time for requests for locations just visited by
disk arm
C-SCAN
C-SCAN: 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).
Seek time is calculated as =(199-50)+(199-0)+(43-0) =391
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.
LOOK
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.
Suppose the requests to be addressed are-
82,170,43,140,24,16,190. And the Read/Write arm is at 50, and it
is also given that the disk arm should move “towards the larger
value”.
So, the seek time is calculated as:
=(190-50)+(190-16) =314
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.
C-LOOK
C-LOOK: 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.
Suppose the requests to be addressed are-82,170,43,140,24,16,190.
And the Read/Write arm is at 50, and it is also given that the disk arm
should move “towards the larger value”
So, the seek time is calculated as = (190-50)+(190-16)+(43-16) =341
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.
GATE Question 1
• Suppose a disk has 201 cylinders, numbered from 0 to 200. At some time the
disk arm is at cylinder 100, and there is a queue of disk access requests for
cylinders 30, 85, 90, 100, 105, 110, 135 and 145. If Shortest-Seek Time First
(SSTF) is being used for scheduling the disk access, the request for cylinder 90 is
serviced after servicing ____________ number of requests.
RAID 03 (0+3, also known as RAID 53 or RAID 5+3) : This level uses striping similar to RAID 0 for RAID 3's virtual disk
blocks. This offers higher performance than RAID 3 but at a higher cost.
RAID 50 (5+0): This configuration combines RAID 5 distributed parity with RAID 0 striping to improve RAID 5
performance without reducing data protection.
File System
• File system is the part of the operating system which is responsible for file management. It provides a
mechanism to store the data and access to the file contents including data and programs. Some
Operating systems treats everything as a file for example Ubuntu.
• The name of the file is divided into two parts as shown below:
• Name
• Extension (separated by a period .)
• The File system takes care of the following issues
1. File Structure : We have seen various data structures in which the file can be stored. The task of
the file system is to maintain an optimal file structure.
2. Recovering Free space : Whenever a file gets deleted from the hard disk, there is a free space
created in the disk. There can be many such spaces which need to be recovered in order to
reallocate them to other files.
3. Disk space assignment to the files :The major concern about the file is deciding where to store
the files on the hard disk. There are various disks scheduling algorithm which will be covered later
in this tutorial.
4. Tracking data location : A File may or may not be stored within only one block. It can be stored in
the non contiguous blocks on the disk. We need to keep track of all the blocks on which the part
of the files reside.
File System Structure
• File System provide efficient access to the disk by allowing data to be stored,
located and retrieved in a convenient way. A file System must be able to store
the file, locate the file and retrieve the file.
• Most of the Operating Systems use layering approach for every task including
file systems. Every layer of the file system is responsible for some activities.
• The image shown ,elaborates how the file system is divided in different layers,
and also the functionality of each layer.
• When an application program asks for a file, the first request is directed to the
logical file system. The logical file system contains the Meta data of the file and
directory structure. If the application program doesn't have the required
permissions of the file then this layer will throw an error. Logical file systems
also verify the path to the file.
• Generally, files are divided into various logical blocks. Files are to be stored in
the hard disk and to be retrieved from the hard disk. Hard disk is divided into
various tracks and sectors. Therefore, in order to store and retrieve the files, the
logical blocks need to be mapped to physical blocks. This mapping is done by
File organization module. It is also responsible for free space management.
• Once File organization module decided which physical block the application
program needs, it passes this information to basic file system. The basic file
system is responsible for issuing the commands to I/O control in order to fetch
those blocks.
• I/O controls contain the codes by using which it can access hard disk. These
codes are known as device drivers. I/O controls are also responsible for handling
interrupts.
Attributes of the File
1. Name : Every file carries a name by which the file is recognized in the file system.
One directory cannot have two files with the same name.
2. Identifier : Along with the name, Each File has its own extension which identifies
the type of the file. For example, a text file has the extension .txt, A video file can
have the extension .mp4.
3. Type : In a File System, the Files are classified in different types such as video files,
audio files, text files, executable files, etc.
4. Location : In the File System, there are several locations on which, the files can be
stored. Each file carries its location as its attribute.
5. Size : The Size of the File is one of its most important attribute. By size of the file,
we mean the number of bytes acquired by the file in the memory.
6. Protection : The Admin of the computer may want the different protections for
the different files. Therefore each file carries its own set of permissions to the
different group of Users.
7. Time and Date : Every file carries a time stamp which contains the time and date
on which the file is last modified.
Operations on the File
1.Create operation : This operation is used to create a file in the file system. It is the most widely used operation performed on the file system. To
create a new file of a particular type the associated application program calls the file system. This file system allocates space to the file. As the file
system knows the format of directory structure, so entry of this new file is made into the appropriate directory.
2. Open operation: This operation is the common operation performed on the file. Once the file is created, it must be opened before performing
the file processing operations. When the user wants to open a file, it provides a file name to open the particular file in the file system. It tells the
operating system to invoke the open system call and passes the file name to the file system.
3. Write operation: This operation is used to write the information into a file. A system call write is issued that specifies the name of the file and
the length of the data has to be written to the file. Whenever the file length is increased by specified value and the file pointer is repositioned
after the last byte written.
4. Read operation: This operation reads the contents from a file. A Read pointer is maintained by the OS, pointing to the position up to which the
data has been read.
5. Re-position or Seek operation: The seek system call re-positions the file pointers from the current position to a specific place in the file i.e.
forward or backward depending upon the user's requirement. This operation is generally performed with those file management systems that
support direct access files.
6. Delete operation : Deleting the file will not only delete all the data stored inside the file it is also used so that disk space occupied by it is freed.
In order to delete the specified file the directory is searched. When the directory entry is located, all the associated file space and the directory
entry is released.
7. Truncate operation : Truncating is simply deleting the file except deleting attributes. The file is not completely deleted although the
information stored inside the file gets replaced.
8. Close operation : When the processing of the file is complete, it should be closed so that all the changes made permanent and all the resources
occupied should be released. On closing it deallocates all the internal descriptors that were created when the file was opened.
9. Append operation: This operation adds data to the end of the file.
10. Rename operation : This operation is used to rename the existing file.
File system protection and security
• The mechanism of the protection provide the facility of the controlled access by just limiting the types
of access to the file. Access can be given or not given to any user depends on several factors, one of
which is the type of access required. Several different types of operations can be controlled:
• Read –Reading from a file.
• Write –Writing or rewriting the file.
• Execute –Loading the file and after loading the execution process starts.
• Append –Writing the new information to the already existing file, editing must be end at the end of
the existing file.
• Delete –Deleting the file which is of no use and using its space for the another data.
• List –List the name and attributes of the file.
• Access Control : There are different methods used by different users to access any file. The general way
of protection is to associate identity-dependent access with all the files and directories an list called
access-control list (ACL) which specify the names of the users and the types of access associate with
each of the user. The main problem with the access list is their length. If we want to allow everyone to
read a file, we must list all the users with the read access. To condense the length of the access-control
list, many systems recognize three classification of users in connection with each file:
• Owner –Owner is the user who has created the file.
• Group –A group is a set of members who has similar needs and they are sharing the same file.
• Universe –In the system, all other users are under the category called universe.
File Access Methods
• Sequential Access : In sequential access, the OS read the file
word by word. A pointer is maintained which initially points
to the base address of the file. If the user wants to read first
word of the file then the pointer provides that word to the
user and increases its value by 1 word. This process
continues till the end of the file.
Modern word systems do provide the
concept of direct access and indexed access but the most
used method is sequential access due to the fact that most
of the files such as text files, audio files, video files, etc need
to be sequentially accessed.
• Direct Access : The Direct Access is mostly required in the case of database systems. In most
of the cases, we need filtered information from the database. The sequential access can be
very slow and inefficient in such cases.
Direct access will give the required result despite of the fact that the
operating system has to perform some complex tasks such as determining the desired block
number. However, that is generally implemented in database applications.
• Indexed Access : If a file can be sorted on any of the filed then an index can be assigned to a
group of certain records. However, A particular record can be accessed by its index. The index
is nothing but the address of a record in the file.
In index accessing, searching in a large database became very quick and easy
but we need to have some extra space in the memory to store the index value.
Directory Structure and File Allocation Table
• Directory can be defined as the listing of the related files on the disk. The
directory may store some or the entire file attributes. To get the benefit of
different file systems on the different operating systems, A hard disk can be
divided into the number of partitions of different sizes. The partitions are
also called volumes or mini disks. Each partition must have at least one
directory in which, all the files of the partition can be listed. A directory
entry is maintained for each file in the directory which stores all the
information related to that file.
• File Allocation Table : 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. File allocation table needs to be
cached in order to reduce the number of head seeks. Now the head doesn't
need to traverse all the disk blocks in order to access one successive block.
• Directory Implementation :
• Linear List : It maintains a linear list of filenames with pointers to the
data blocks. It is time-consuming also. To create a new file, we must
first search the directory to be sure that no existing file has the same
name then we add a file at end of the directory. To delete a file, we
search the directory for the named file and release the space. To reuse
the directory entry either we can mark the entry as unused or we can
attach it to a list of free directories.
• Hash Table : The hash table takes a value computed from the file name
and returns a pointer to the file. It decreases the directory search time.
The insertion and deletion process of files is easy. The major difficulty
is hash tables are its generally fixed size and hash tables are dependent
on hash function on that size.
Ways to Implement Directory
File system implementation
• We can implement file system by using two types data structures :
1. On-disk Structures : Generally they contain information about total number of disk blocks, free disk
blocks, location of them and etc. Below given are different on-disk structures :
• Boot Control Block –It is usually the first block of volume and it contains information needed to boot
an operating system. In UNIX it is called boot block and in NTFS it is called as partition boot sector.
• Volume Control Block –It has information about a particular partition ex:- free block count, block size
and block pointers etc. In UNIX it is called super block and in NTFS it is stored in master file table.
• Directory Structure –They store file names and associated inode numbers. In UNIX, includes file
names and associated file names and in NTFS, it is stored in master file table.
• Per-File FCB –It contains details about files and it has a unique identifier number to allow association
with directory entry. In NTFS it is stored in master file table.
2. In-Memory Structure : They are maintained in main-memory and these are helpful for file system
management for caching. Several in-memory structures given below :
• Mount Table – It contains information about each mounted volume.
• Directory-Structure cache – This cache holds the directory information of recently accessed
directories.
• System wide open-file table – It contains the copy of FCB of each open file.
• Per-process open-file table – It contains information opened by that particular process and it maps
with appropriate system wide open-file.
File System Implementation Issues