OS Module V
OS Module V
by:
Dr. Soumya Priyadarsini Panda
Assistant Professor
Dept. of CSE
Silicon Institute of Technology, Bhubaneswar
Secondary Storage Structure
Disk structure
Seek Time: The time necessary to move the disk arm to the desired
cylinder
Rotational latency: The time necessary for the desired sector to rotate
to the disk head
For the disk drives, the focus is on fast access time and large disk
bandwidth.
Both the access time and the bandwidth can be increased by managing
the order in which disk I/O requests are serviced.
If the drive or controller is busy, any new requests for service will be
placed in the queue of pending requests for that drive.
FCFS
SSTF
SCAN
C-SCAN
LOOK
C-LOOK
FCFS
The first-come, first-served (FCFS) is the simplest form of disk
scheduling algorithm.
In FCFS, the requests are addressed in the order they arrive in the disk
queue
This algorithm is intrinsically fair, but it generally does not provide the
fastest service.
Example: A disk queue with requests for I/O to blocks on cylinders: 98, 183,
37, 122, 14, 124, 65, 67
In other words, SSTF chooses the pending request closest to the current
head position.
Example:
The head continuously scans back and forth across the disk.
since the disk arm behaves just like an elevator in a building, first
servicing all the requests going up and then reversing to service
requests the other way.
SCAN Cont…
Example:
Assuming that the disk arm is moving toward 0 and that the initial head
position is again 53, the head will next service 37 and then 14.
At cylinder 0, the arm will reverse and will move toward the other end of
the disk, servicin the requests at 65, 67, 98, 122, 124, and 183
C-SCAN
Circular SCAN (C-SCAN) scheduling is a variant of SCAN designed
to provide a more uniform wait time.
Like SCAN, C-SCAN moves the head from one end of the disk to the
other, servicing requests along the way.
When the head reaches the other end, however, it immediately returns
to the beginning of the disk without servicing any requests on the
return trip.
Example:
LOOK
Both SCAN and C-SCAN move the disk arm across the full width of
the disk.
More commonly, the arm goes only as far as the final request in each
direction.
The versions of SCAN and C-SCAN that follow this pattern are called
LOOK and C-LOOK scheduling, because they look for a request
before continuing to move in a given direction.
C-LOOK
Example:
File System
Background
For most users, the file system is the most visible aspect of an
operating system.
It provides the mechanism for storage and access to both data and
programs of the operating system and all the users of the computer
system.
Files represent programs (both source and object forms) and data.
Files may be free form, such as text files, or may be formatted rigidly
Access methods:
Sequential Access
Direct Access
Other Access Methods
Sequential Access
Information in the file is processed in order, one record after the other.
Each record has its own address on the file with by the help of which it
can be directly accessed for reading or writing.
The records need not be in any sequence within the file and they need
not be in adjacent locations on the storage medium.
Other Access Methods
Other access methods can be built on top of a direct-access method.
The index, like an index in the back of a book, contains pointers to the
various blocks
To find a record in the file, first search the index and then use the
pointer to access the file directly and to find the desired record
File Allocation Methods
Files are allocated disk spaces by operating system.
Contiguous Allocation
Linked Allocation
Indexed Allocation
Contiguous Allocation
In Contiguous Allocation-
Easy to implement.
No external fragmentation
Each file has its own index block which stores the addresses of disk
space occupied by the file.
Single-level directory
Two-level directory
Tree-structured directory
Since all the files are in the same directory, they must have the unique
name.
If two users call their dataset test, then the unique name rule violated.
Cont…
Advantages:
Since it is a single directory, so its implementation is very easy.
If the files are smaller in size, searching will become faster.
The operations like file creation, searching, deletion, updating are very
easy in such a directory structure.
Disadvantages:
There may chance of name collision because two files can not have the
same name.
Searching will become time taking if the directory is large.
It can not group the same type of files together.
Two-level directory
A single level directory often leads to confusion of files names among
different users.
In the two-level directory structure, each user has there own user files
directory (UFD).
The UFDs has similar structures, but each lists only the files of a single
user.
Disadvantages:
A user is not allowed to share files with other users.
Still it is not very scalable, two files of the same type cannot be grouped
together in the same user.
Tree-structured directory
Once we have seen a two-level directory as a tree of height 2, the natural
generalization is to extend the directory structure to a tree of arbitrary
height.
This generalization allows the user to create there own subdirectories and
to organize on their files accordingly.
The tree has a root directory, and every file in the system have a unique
path.
Cont…
Cont…
Advantages:
Very generalize, since full path name can be given.
Very scalable, the probability of name collision is less.
Searching becomes very easy, we can use both absolute path as well as
relative.
Disadvantages:
Every file does not fit into the hierarchical model, files may be saved
into multiple directories.
We can not share files.
It is inefficient, because accessing a file may go under multiple
directories.
Acyclic graph directory
An acyclic graph is a graph with no cycle and allows to share
subdirectories and files.
It is the point to note that shared file is not the same as copy file .
Disadvantages:
We share the files via linking, in case of deletion, it may create problem
If the link is softlink then after deleting the file we left with a dangling
pointer.
In case of hardlink, to delete a file we have to delete all the reference
associated with it.
General graph directory structure
In general graph directory structure, cycles are allowed within a directory
structure where multiple directories can be derived from more than one
parent directory.
Disadvantages:
It is more costly than others.
It needs garbage collection.
Directory Implementation
The selection of an appropriate directory implementation algorithm
may significantly affects the efficiency, performance, and reliability of
the file system.
There are mainly two algorithms which are used for directory
implementation:
Linear List
Hash Table
Linear List
In this algorithm, all the files in a directory are maintained as singly lined
list.
Each file contains the pointers to the data blocks which are assigned to it
and the next file in the directory.
Cont…
Characteristics
When a new file is created, then the entire list is checked whether the new
file name is matching to a existing file name or not.
In case, it doesn't exist, the file can be created at the beginning or at the
end.
This approach suggests to use hash table along with the linked lists.
Cont…
A key-value pair for each file in the directory gets generated and stored
in the hash table.
The key can be determined by applying the hash function on the file
name while the key points to the corresponding file stored in the
directory.
Searching becomes efficient due to the fact that, entire list will not be
searched on every operating.
Only hash table entries are checked using the key and if an entry found
then the corresponding file will be fetched using the value.
Allocation Methods
Contiguous Allocation
Linked Allocation
Indexed Allocation
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.
Cont…
Advantages:
It is simple to implement.
Disadvantages:
The disk will become fragmented.
In linked list allocation, each file is considered as the linked list of disk
blocks.
Each disk block allocated to a file contains a pointer which points to the
next disk block allocated to the same file.
Cont…
Advantages:
There is no external fragmentation with linked allocation.
Any free block can be utilized in order to satisfy the file block requests.
File can continue to grow as long as the free blocks are available.
Directory entry will only contain the starting block address.
Disadvantages:
Random Access is not provided.
Pointers require some space in the disk blocks.
Any of the pointers in the linked list must not be broken otherwise the
file will get corrupted.
Need to traverse each block.
Indexed Allocation
In Indexed Allocation Scheme, all the disk pointers are stored 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.
Disadvantages:
A bad index block could cause the lost of entire file.
Size of a file depends upon the number of pointers, a index block can hold.
Having an index block for a small file is totally wastage.
More pointer overhead
For example, an index block might contain a small header giving the
name of the file and a set of the first 100 disk-block addresses.
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.
The outer level index is used to find the inner level index.
The inner level index is used to find the desired data block.
I/O System:
Polling
Interrupts
DMA