Os Unit 4
Os Unit 4
Divices
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.
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:
1. Mount Table –
It contains information about each mounted volume.
2. Directory-Structure cache –
This cache holds the directory information of recently accessed directories.
The VFS serves as an abstraction layer that gives applications access to different types of file
systems and local and network storage devices. For that reason, a VFS may also be known as
a virtual file system switch. It also manages the data storage and retrieval between the operating
system and the storage sub-system. The VFS maintains a cache of directory lookups to enable
easy location of frequently accessed directories.
Directory Implementation
There is the number of algorithms by using which, the directories can be implemented. However,
the selection of an appropriate directory implementation algorithm may significantly affect the
performance of the system.
The directory implementation algorithms are classified according to the data structure they are
using. There are mainly two algorithms which are used in these days.
1. 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.
Characteristics
1. 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. Therefore, searching for a unique name is a big concern
because traversing the whole list takes time.
2. The list needs to be traversed in case of every operation (creation, deletion, updating, etc)
on the files therefore the systems become inefficient.
2. Hash Table
To overcome the drawbacks of singly linked list implementation of directories, there is an
alternative approach that is hash table. This approach suggests to use hash table along with the
linked lists.
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.
Now, searching becomes efficient due to the fact that now, 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.
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
Linked List allocation solves all problems of contiguous 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.
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.
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.
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.
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
Free Space Management
A file system is responsible to allocate the free blocks to the file therefore it has to keep track of
all the free blocks present in the disk. There are mainly two approaches by using which, the free
blocks in the disk are managed.
1. Bit Vector
In this approach, the free space list is implemented as a bit map vector. It contains the number of
bits where each bit represents each block.
If the block is empty then the bit is 1 otherwise it is 0. Initially all the blocks are empty therefore
each bit in the bit map vector contains 1.
LAs the space allocation proceeds, the file system starts allocating blocks to the files and setting
the respective bit to 0.
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.
Linked List
It is another approach for free space management. This approach suggests linking together all the
free blocks and keeping a pointer in the cache which points to the first free block.
Therefore, all the free blocks on the disks will be linked together with a pointer. Whenever a
block gets allocated, its previous free block will be linked to its next free block.
Disk structure:
The disk is divided into tracks. Each track is further divided into sectors. The point to be
noted here is that outer tracks are bigger in size than the inner tracks but they contain the same
number of sectors and have equal storage capacity.
Read-Write(R-W) head moves over the rotating hard disk. It is this Read-Write head that
performs all the read and writes operations on the disk and hence, the position of the R-W head
is a major concern. To perform a read or write operation on a memory location, we need to
place the R-W head over that position. Some important terms must be noted here:
1. Seek time – The time taken by the R-W head to reach the desired track from its current
position.
2. Rotational latency – Time is taken by the sector to come under the R-W head.
3. Data transfer time – Time is taken to transfer the required amount of data. It depends
upon the rotational speed.
4. Average Access time – seek time + Average Rotational latency + data transfer time +
controller time.
FCFS Scheduling Algorithm
It is the simplest Disk Scheduling algorithm. It services the IO requests in the order in which
they arrive. There is no starvation in this algorithm, every request is serviced.
Disadvantages
o The scheme does not optimize the seek time.
o The request may come from different processes therefore there is the possibility of
inappropriate movement of the head.
Example
Consider the following disk request sequence for a disk with 100 tracks 45, 21, 67, 90, 4, 50, 89,
52, 61, 87, 25
Head pointer starting at 50 and moving in left direction. Find the number of head movements in
cylinders using FCFS scheduling.
Solution
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.
Example:
1. 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”.
CSCAN: 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.
Example:
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”.
Disk Management
The operating system is responsible for various operations of disk management. Modern
operating systems are constantly growing their range of services and add-ons, and all operating
systems implement four essential operating system administration functions. These functions are
as follows:
1. Process Management
2. Memory Management
3. File and Disk Management
4. I/O System Management
Most systems include secondary storage devices (magnetic disks). It is a low-cost, non-volatile
storage method for data and programs. The user data and programs are stored on different
storage devices known as files. The OS is responsible for allocating space to files on secondary
storage devices as required.
Disk Formatting
A new magnetic disk is mainly a blank slate. It is platters of the magnetic recording material.
Before a disk may hold data, it must be partitioned into sectors that may be read and written by
the disk controller. It is known as physical formatting and low-level formatting.
Low-level formatting creates a unique data structure for every sector on the drive. A data
structure for a sector is made up of a header, a data region, and a trailer. The disk controller uses
the header and trailer to store information like an error-correcting code (ECC) and a sector
number.
Boot Block
When a system is turned on or restarted, it must execute an initial program. The start program of
the system is called the bootstrap program. It starts the OS after initializing all components of the
system. The bootstrap program works by looking for the OS kernel on disk, loading it into
memory, and jumping to an initial address to start the OS execution.
Bad Blocks
Disks are prone to failure due to their moving parts and tight tolerances. When a disk drive fails,
it must be replaced and the contents transferred to the replacement disk using backup media. For
some time, one or more sectors become faulty. Most disks also come from the company with bad
blocks. These blocks are handled in various ways, depending on the use of disk and controller.
Swap-Space Management
A computer has a sufficient amount of physical memory, but we need more, so we swap some
memory on disk most of the time. Swap space is a space on a hard disk that is a substitute for
physical memory. It is used as virtual memory, which contains process memory images.
This interchange of data between virtual memory and real memory is called swapping and space
on disk as swap space. Swap space helps the computer's operating system pretend that it has
more RAM than it actually has. It is also called a swap file.
Virtual memory is a combination of RAM and disk space that running processes can use. Swap
space is the portion of virtual memory on the hard disk, used when RAM is full.
Tertiary-Storage Structure:
Tertiary Storage Devices
Low cost is the defining characteristic of tertiary storage. • Generally, tertiary storage is built
using removable media • Common examples of removable media are floppy disks and CD-
ROMs; other types are available.
Removable Disks:
Floppy disk — thin flexible disk coated with magnetic material, enclosed in a protective plastic
case. – Most floppies hold about 1 MB; similar technology is used for removable disks that hold
more than 1 GB. – Removable magnetic disks can be nearly as fast as hard disks, but they are at
a greater risk of damage from exposure.
A magneto-optic disk records data on a rigid platter coated with magnetic material. – Laser heat
is used to amplify a large, weak magnetic field to record a bit. – Laser light is also used to read
data (Kerr effect). – The magneto-optic head flies much farther from the disk surface than a
magnetic disk head, and the magnetic material is covered with a protective layer of plastic or
glass; resistant to head crashes. • Optical disks do not use magnetism; they employ special
materials that are altered by laser light.
Tapes:
Compared to a disk, a tape is less expensive and holds more data, but random access is much
slower. • Tape is an economical medium for purposes that do not require fast random access,
e.g., backup copies of disk data, holding huge volumes of data. • Large tape installations
typically use robotic tape changers that move tapes between tape drives and storage slots in a
tape library.
Data redundancy, although taking up extra space, adds to disk reliability. This means, in case
of disk failure, if the same data is also backed up onto another disk, we can retrieve the data
and go on with the operation. On the other hand, if the data is spread across just multiple disks
without the RAID technique, the loss of a single disk can affect the entire data.
RAID-0 (Stripping)
Blocks are “stripped” across disks.
2. Partial failure. A failure occurred in the midst of transfer, so only some of the sectors were
written with the new data, and the sector being written during the failure may have been
corrupted.
3. Total failure. The failure occurred before the disk write started, so the previous data values on
the disk remain intact.
We can extend this procedure easily to allow the use of an arbitrarily large number of copies of
each block of stable storage.
The data in stable storage are guaranteed to be safe unless a failure destroys all the copies.
Because waiting for disk writes to complete (synchronous I/O) is time consuming, many storage
arrays.