Complete Unit of Java
Complete Unit of Java
Ques 2 Explain the structure and management of file directories, including hierarchical and flat
directory structures? (2023-24) ----Hierarchal is same as tree and flat is same as single
Ques 3 Explain the term RAID and its characteristics. Also, explain various RAID levels with their
advantages and disadvantages. (2022-23)
Ques 4 Suppose the following disk request sequence (track numbers) for a disk with 100 tracks is
given: 45, 20, 90, 10, 50, 60, 80, 25, 70. Assume that the initial position of the R/W head is on track 49.
Calculate the net head movement using: (i) SSTF (ii) SCAN (iii) CSCAN (iv) LOOK (2022-23)
Ques 5. A hard disk having 2000 cylinders, numbered from 0 to 1999. the drive is currently serving
the request at cylinder 143,and the previous request was at cylinder 125.The status of the queue is as
follows 86, 1470, 913, 1774,948,1509,1022,1750,130 What is the total distance (in cylinders) that the
disk arm moves to satisfy the entire pending request for each of the following diskscheduling
algorithms? (i) SSTF (ii) FCFS (2021-22) (2018-19)
Ques 6 Explain in detail about disk storage and disk scheduling. (2021-22)
Ques 8 Explain about file concept. Define in detail about file organization and access mechanism.
(2022-23)
1. FCFS
2. SSTF
3. SCAN
4. LOOK
5. CSCAN
6. CLOOK
Ques 10 Explain FCFS, SSTF, SCAN, CSCAN, LOOK, CLOOK scheduling with e.g.
1. File concept:
A file is a collection of related information that is stored on secondary storage. Information stored
in files must be persistent i.e. not affected by power failures & system reboots. Files represent both
programs as well as data.
Part of the OS dealing with the files is known as file system. The File system takes care of the
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.
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.
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. o 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.
Creating files: Two steps are necessary to create a file. First, space must be found for the
file in the file system. Secondly, an entry must be made in the directory for the new file.
Creation of the file is the most important operation on the file. Different types of files are
created by different methods for example text editors are used to create a text file, word
processors are used to create a word file and Image editors are used to create the image
files.
Reading a file: Data & read from the file at the current position. The system must keep a
read pointer to know the location in the file from where the next read is to take place. Once
the read has been taken place, the read pointer is updated. Every file is opened in three
different modes: Read, Write and append. A Read pointer is maintained by the OS, pointing
to the position up to which, the data has been read.
Writing a file: Data are written to the file at the current position. The system must keep a
write pointer to know the location in the file where the next write is to take place. The write
pointer must be updated whenever a write occurs.
Repositioning within a file (seek): The directory is searched for the appropriate entry & the
current file position is set to a given value. After repositioning data can be read from or
written into that position. So, Repositioning is simply moving the file pointers forward or
backward depending upon the user's requirement. It is also called as seeking.
Deleting a file: To delete a file, we search the directory for the required file.
After deletion, the space is released so that it can be reused by other files. Deleting the file
will not only delete all the data stored inside the file, It also deletes all the attributes of the
file. The space which is allocated to the file will now become available and can be allocated
to the other files.
Truncating a file: Truncating is simply deleting the file except deleting attributes. The file is
not completely deleted although the information stored inside the file gets replaced.
3. File types: The file name is spilt into 2 parts, Name & extension. Usually these two parts are
separated by a period. The user & the OS can know the type of the file from the extension itself.
Listed below are some file types along with their extension:
File Type Extension
Executable exe, bin, com
File
Object File obj, o (compiled)
Source Code C, C++, Java, .pas(Pascal) file
Batch File bat, sh (commands to command interpreter)
Text File txt, doc (textual data documents)
Archieve File arc, zip, rar (related files grouped together into file compressed for storage)
byte
Record sequence: In this structure, a file is a sequence of fixed length records. Here the
read operation returns one records & the write operation overwrites or append
Record
Tree: In this organization, a file consists of a tree of records of varying lengths. Each record
consists of a key field. The tree is stored on the key field to allow first searching for a
particular key.
Access methods: Basically, access method is divided into 2 types:
Sequential access: It is the simplest access method. Information in the file is processed in
order i.e. one record after another. A process can read all the data in a file in order starting
from beginning but can‘t skip & read arbitrarily from any location. Sequential files can be
rewound. It is convenient when storage medium was magnetic tape rather than disk.
Direct access: A file is made up of fixed length-logical records that allow programs to read &
write records rapidly in no particular order. This method can be used when disk are used for
storing files. This method is used in many applications e.g. database systems.
Ex: If an airline customer wants to reserve a seat on a particular flight, the reservation program
must be able to access the record for that flight directly without reading the records before it.
In a direct access file, there is no restriction in the order of reading or writing. For example,
we can read block 14, then read block 50 & then write block 7 etc. Direct access files are very
useful for immediate access to large amount of information.
2. Directory concept
Directory structure: The file system of computers can be extensive. Some systems store thousands
of file on disk. To manage all these data, we need to organize them. The organization is done in 2
steps. The file system is broken into partitions. Each partition contains information about file within
it.
Directory can be defined as the listing of the related files on the disk. The directory may store some
or the entire file attributes.
A directory can be viewed as a file which contains the Meta data of the bunch of files.
Operation on a directory:
Search for a file: We need to be able to search a directory for a particular file.
Create a file: New files are created & added to the directory.
Delete a file: When a file is no longer needed, we may remove it from the directory.
List a directory: We should be able to list the files of the directory.
Rename a file: The name of a file is changed when the contents of the file changes.
Traverse the file system: It is useful to be able to access every directory & every file within
a directory.
Structure of a directory: The most common schemes for defining the structure of the directory
are:
1. Single level directory: It is the simplest directory structure. All files are present in the same
directory. So it is easy to manage & understand.
Limitation: A single level directory is difficult to manage when the no. of files increases or when
there is more than one user. Since all files are in same directory, they must have unique names.
So, there is confusion of file names between different users.
Advantages
2. Two level directories: The solution to the name collision problem in single level directory is
to create a separate directory for each user. In a two level directory structure, each user has its
own user file directory. When a user logs in, then master file directory is searched. It is indexed
by user name & each entry points to the UFD of that user.
Limitation: It solves name collision problem. But it isolates one user from another. It is an
advantage when users are completely independent. But it is a disadvantage when the users
need to access each other‘s files & co-operate among themselves on a particular task.
3. Tree structured directories: It is the most common directory structure. A two level directory
is a two level tree. So, the generalization is to extend the directory structure to a tree of arbitrary
height. It allows users to create their own subdirectories & organize their files. Every file in
the system has a unique path name. It is the path from the root through all the sub-directories
to a specified file. Each user has a current directory. It contains most of the files that are of
current interest to the user. Path names can be of two types: An absolute path name begins
from the root directory & follows the path down to the specified files. A relative path name
defines the path from the current directory.
EX: If the current directory is root/spell/mail, then the relative path name is prt/first & the
absolute path name is root/ spell/ mail/ prt/ first. Here users can access the files of other users
also by specifying their path names.
Advantage: Searching is more efficient in this directory structure.
A tree structured directory system may consist of various levels therefore there is a set of permissions
assigned to each file and directory.
The permissions are R W X which are regarding reading, writing and the execution of the files or
directory. The permissions are assigned to three types of users: owner, group and others.
There is a identification bit which differentiate between directory and file. For a directory, it is d and
for a file, it is dot (.)
In general graph directory structure, cycles are allowed within a directory structure where
multiple directories can be derived from more than one parent directory.
Protection
When information is kept in a computer system, a major concern is its protection from physical
damage (reliability) as well as improper access.
Types of access: In case of systems that don‘t permit access to the files of other users. Protection
is not needed. So, one extreme is to provide protection by prohibiting access. The other extreme
is to provide free access with no protection. Both these approaches are too extreme for general
use. So, we need controlled access. It is provided by limiting the types of file access. Access is
permitted depending on several factors. One major factor is type of access requested. The
different types of operations that can be controlled are:
Read
Write
Execute
Append
Delete
List
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.
We have mainly discussed 3 methods of allocating disk space which are widely used.
1. 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.
d. If the file is ‘n‘ blocks long and starts at location ‘b‘, then it occupies blocks b, b+1, b+2,-
--,b+ n-1.
e. The directory for each file indicates the address of the starting block and the length of the
area allocated for each file.
f. Contiguous allocation supports both sequential and direct access. For sequential access, the
file system remembers the disk address of the last block referenced and reads the next block
when necessary.
g. For direct access to block i of a file that starts at block b we can immediately access block
b+i
Problems: One difficulty with contiguous allocation is finding space for a new file. It
also suffers from the problem of external fragmentation. As files are deleted and
allocated, the free disk space is broken into small pieces. A major problem in contiguous
allocation is how much space is needed for a file. When a file is created, the total amount
of space it will need must be found and allocated. Even if the total amount of space
needed for a file is known in advances, pre-allocation is inefficient. Because a file that
grows very slowly must be allocated enough space for its final size even though most of
that space is left unused for a long period time. Therefore, the file has a large amount of
internal fragmentation.
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.
a. Linked allocation solves all problems of contiguous allocation.
b. In linked allocation, each file is linked list of disk blocks, which are scattered throughout
the disk.
c. The directory contains a pointer to the first and last blocks of the file.
d. Each block contains a pointer to the next block.
e. These pointers are not accessible to the user. To create a new file, we simply create a new
entry in the directory.
f. For writing to the file, a free block is found by the free space management system and this
new block is written to & linked to the end of the file.
g. To read a file, we read blocks by following the pointers from block to block.
h. There is no external fragmentation with linked allocation & any free block can be used to
satisfy a request.
i. Also there is no need to declare the size of a file when that file is created. A file can continue
to grow as long as there are free blocks.
th
Limitations: It can be used effectively only for sequential access files. To find the i
block of the file, we must start at the beginning of that file and follow the pointers until
we get the ith block. So it is inefficient to support direct access files. Due to the presence
of pointers each file requires slightly more space than before. Another problem is
reliability. Since the files are linked together by pointers scattered throughout the disk.
What would happen if a pointer were lost or damaged?
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.
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.
a. Indexed allocation solves the problem of linked allocation by bringing all the pointers
together to one location known as the index block.
b. Each file has its own index block which is an array of disk block addresses. The ith entry in
the index block points to the ith block of the file.
c. The directory contains the address of the index block. The read the ith block, we use the
pointer in the ith index block entry and read the desired block.
d. To write into the ith block, a free block is obtained from the free space manager and its
Limitations: The pointer overhead of index block is greater than the pointer overhead
of linked allocation. So here more space is wasted than linked allocation. In indexed
allocation, an entire index block must be allocated, even if most of the pointers are nil.
4.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.
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 average of time spent by each request waiting for the IO operation.
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.
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.
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 (Take from notebook)
Shortest seek time first (SSTF) algorithm selects the disk I/O request which requires the least disk
arm movement from its current position regardless of the direction. It reduces the total seek time as
compared to FCFS.
It allows the head to move to the closest track in the service queue.
Disadvantages o It may cause starvation for some requests. o Switching direction on the frequent
basis slows the working of algorithm. o It is not the most optimal algorithm. Example (Take
from notebook)
SCAN Algorithm
It is also called as Elevator Algorithm. In this algorithm, the disk arm moves into a particular
direction till the end, satisfying all the requests coming in its path,and then it turns backand moves
in the reverse direction satisfying requests coming in its path.
It works in the way an elevator works, elevator moves in a direction completely till the last floor of
that direction and then turns back.
C-SCAN algorithm
In C-SCAN algorithm, the arm of the disk moves in a particular direction servicing requests until
it reaches the last cylinder, then it jumps to the last cylinder of the opposite direction without
servicing any request then it turns back and start moving in that direction servicing the remaining
requests.
It is like SCAN scheduling Algorithm to some extant except the difference that, in this scheduling
algorithm, the arm of the disk stops moving inwards (or outwards) when no more request in that
direction exists. This algorithm tries to overcome the overhead of SCAN algorithm which forces
disk arm to move in one direction till the end regardless of knowing if any request exists in the
direction or not.
Example (Take from notebook)
C Look Scheduling
C Look Algorithm is similar to C-SCAN algorithm to some extent. In this algorithm, the arm of
the disk moves outwards servicing requests until it reaches the highest request cylinder, then it
jumps to the lowest request cylinder without servicing any request then it again start moving
outwards servicing the remaining requests.
It is different from C SCAN algorithm in the sense that, C SCAN force the disk arm to move till
the last cylinder regardless of knowing whether any request is to be serviced on that cylinder or
not.
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.
• Rotational Latencv: 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 = 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.
DISK SCHEDULING ALGORITHMS
Advantages:
Every request gets a fair chance
No indefinite postponement, i.e. no starvation.
Disadvantages:
Does not try to optimize seek time
May not provide the best possible service
Advantages:
• Average Response Time decreases
Throughput increases
Tries to give an optimum result in majority of the eases
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
In SCAN algorithm the disk arm moves into a particulardirectionand 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.
Advantages:
High throughput
Low variance of response time
Average response time
Disadvantages:
Long waiting time for requests for locations just visited by disk arm
QI. A disk contains 200 tracks (0-199). Request queue contains track numbers 82, 170, 43,
140, 24, 16, 190 respectively. Current position of R/W Head is 50. Assume the R/W head is
moving towards higher value. Calculate total number of track movement by R/W head (total
seek time) using SCAN disk scheduling algorithm.
Q2. A disk contains 200 tracks (0-199). Request queue contains track numbers 55, 58, 39, 18,
90, 160, 150, 38, 184 respectively. Current position of RAV Head is 100. Assume the R W head
is moving towards higher value. Calculate total number of track movement by RAV head (total
seek time) using SCAN disk scheduling algorithm.
Q3. A disk contains 200 tracks (0-199). Request queue contains track numbers 23, 89, 132, 42,
187 respectively. Current position of R/W Head is 100. Assume the R/W head is moving
towards 0. Calculate total number of track movement by WW head (total seek time) using
SCAN disk scheduling algorithm.
Advantages:
• Provides more uniform wait time compared to SCAN
QI. A disk contains 200 tracks (0-199). Request queue contains track
numbers 82, 170, 43,
140, 24, 16, 190 respectively. Current position of R/'W Head is 50. Assume the
R/W head is
moving towards higher value. Calculate total number of track movement by R/W
head (total
seek time) using CSCAN disk scheduhng algorithm.
Q2. A disk contains 200 tracks (0-199). Request queue contains track numbers 55, 58, 39, 18,
90, 160, 150, 38, 184 respectively. Current position of WW Head is 100. Assume the WW head
is moving towards higher value. Calculate total number of track movement by WW head (total
seek time) using CSCAN disk scheduling algorithm
Q3. A disk contains 200 tracks (0-199). Request queue contains track numbers 23, 89, 132, 42,
187 respectively. Current position of R/W Head is 100. Assume the R/W head is moving
towards O. Calculate total number of track movement by WW head (total seek time) using
CSCAN disk scheduling algorithm.
60, cačaa.-tL
50 2 łqą
ag-50) ł- ł.
(Qh- IG) -16)
•ęąnned withCamScanner
sso . 56, 150
100
55 q 0100 '50
—(Ico•-S5) (58-55)+ -I B) - q o)
( 160-150) 4 -BB)
200 •
Ob KJ 100.
100
(132-cq)+ qa)+
with CamScanner
CSTF (
0 50 、
0
3
100 •
u-e-u_,
5 100
32 +
q wvu,
100 •
uL.L
00-99) t 032 -Ba) +
(loo—cq)
200 u-2AE
oh 50.
50
C62-50)
(29-16)
332
55 58 150
C55-39)
Studocu
Șs;ąmed with CamScanner
(い式Ⅸこ& 、
・しk れ0 . 5) 气) 、
ちもも 十
, い。
) +の +い” 2つャ- 。
)キい3~ のキいい一
00 十、
、
宅キ、 読し
.宀 with CamScanne「
A Roo (o-łqq). 6
66,
100. Î\Lu.cwxe
C.oLQÂÂ.b&.L
55 50 90 IGO tqq
050 - 100)
aqq-Ńq)
(58-56)
100)
(40-0)
WithCamScanner
LOOK Cac
190
o} 50. d.b.a.
o 16 43 50 180
090-6a)f 6+0-190) ±
190-IG)
WithCamScanner
0 0 3 55ら 0 ー00 馬
9日 9
い00ー
、0のキ 0ーの + いも
いし u - 0) をいq ←日0) ャ国 0 - 5のヤ5 に
の
い5-32f ヤ 3り斗
銀い こ
し
S}- に山 い↓ 、 。
気 良。気 山 (。- 国の。% 止 平 。叱
03 气ー 00
、
キ年ャ協
し
00に
。
民區にし~ 込。 。
し乙 。
-い・% 当气
。
こ毳こ、、炊0し、
、 し
一0 , 3,店。
、 0 し 000 、
aq. 円 0 〉 と
0
0 ー0 ー
キ0 0一9
円
颪
し はい
し
の
い。ー
5。 ) + C峭- )
) +いq04 し
十十2 ユ
40 十一
ー
200 10-łqq).
100.
23 ț00
¯ëcoL PJJc
CŁq-q2)łCQ-Q3)
55
UNIT 05
I/O Management
VO DEVICES (1/0 'IARDWARE)
I/O Devices
One of the imponant jobs of an Operating System is to manage various I/O devices including
mouse, keyboards, touch pad, disk drives, display adapters, USB dcviccs, Bit-mapped scrcen,
LED, Analog-to-digital converter, On/off switch, network connections, audio I/O, printers etc.
An I/O system is required to take an application I/O request and send it to the physical device,
then take whatever response comes back from the device and send it to the application.
I/O devices can be divided into two categories —
Block devices —A block device is one with which the driver communicates by sending
entire blocks of data. For example, Ilard disks, USB cameras, Disk-On-Key etc.
• Character devices —A character device is one with which the driver communicates
by sending and receiving single characters (bytes, octets). For example, serial ports,
parallel ports, sounds cards etc.
I/O devices can also be divided into three categories —
• Human Readable Devices
o Suitable for communicating with the computer user
o Ex: printers, terminals, video display, keyboard, mouse etc.
Machine Readable Devices
o Suitable for communicating with electronic equipment
o Ex: disk drivers, USB keys, sensors, controllers etc.
Communication Devices
o Suitable for:communicating with remote devices.
o Ex: modem, digital line drivers etc.
All these devices differ significantly from one another with regard to:
Data rate
Control complexity
• Transfer unit and direction
Data representation
Error handling
Device Controllers
The Device Controller works like an interface between a device and a device driver.
I/O units (Keyboard, mouse, printer, etc.) typically consist of a mechanical
component and an electronic component where electronic component is called the
deuce controller.
There is always a device controller and a device driver for each device to communicate
with the Operating Systems.
A device controller may bc able to handle multiple devices
As an interfaceits main task is to convert serial bit stream to block of bytes, perform
error correction as necessary,
Any device connected to the computer is connected by a plug and socket, and the socket
is connectedto a devicecontroller.
Following is a model for connecting the CPU, memory, controllers, and I/O devices
where CPU and device controllersall use a commonbus for communication.
Keyboard
Controlkr Cmtrolkr
• SynchronousI/O
In this schemeCPU executionwaits while I/O proceeds.
o Also called as Blocking I/O
• Asynchronous I/O
c I/O proceeds concurrently with CPU execution.
Also called as Non-BlockingI/O
Communication to I/O Devices
The CPU must have a way to pass information to and from an I/O deuce. There are three
approaches available to commumcate Withthe CPU and Deuce.
• This uses CPU instructions that are specifically made for controlling I/O devices.
• These instructions typically allow data to be sent to an I/O device or read from an I/O
device.
I/O Comrunds
I/O Device
While using memory mapped 10, OS allocates buffer in memory and informs I/O
device to use that buffer to send data to the CPU.
I/O device operates with CPU, interrupts CPU when finished.
The advantage to this method is that every instruction which can access memory can
be used to manipulate an I/O device.
Memory mapped 10 is used for most high-speed I/O devices like disks,
communication interfaces.
3. Direct Memory Access (DMA)
Slow devices like keyboards will generate an interrupt to the main CPU aner each byte
is transferred.
If a fast device such as a disk generated an interrupt for each byte, the operating system
would spend most of its time handling these interrupts.
So a typical computer uses direct memory access (DMA) hardware to reduce this
overhead.
Direct Memory Access (DMA) means CPU grants I/O module authority to read
from or write to memory without involvement.
DMA module itself controls exchange of data between main memory and the I/O
device.
CPU is only involved at the beginning and end of the transfer and interrupted only
after entire block has been transferred.
Direct Memory Access needs a special hardware called DMA controller (DMAC)
that manages the data transfers and arbitrates access to the system bus.
The controllers are programmed with source and destination pointers (where to
read/write the data), counters to track the number of transferred bytes, and settings,
which includes I/O and memory types, interrupts and states for the CPU cycles.
Data Bus
4. Polling I/O
• A computer must have a way of detecting the arrival of any type of input.
• Polling can be used for this purpose.
• This techniques allow the processor to deal with events that can happen at any time and
that are not related to the process it is currently running.
Polling is the simplest way for an I/O device to communicate with the processor.
The process ofperiodically checking status of the device to see if it is time for the next
I/O operation, is called polling.
The I/O device simply puts the information in a Status register, and the processor must
come and get the information.
• Most of the time, devices will not require attention and when one does it will have to
wait until it is next interrogated by the polling program.
This is an inefficient method and much of the processors time is wasted on unnecessary
polls.
Compare this method to a teacher continually asking every student in a class, one after
another, if they need help. Obviously the more efficient method would be for a student
to inform the teacher whenever they require assistance.
5. Interrupt I/O
A computer must have a way of detecting the arrival of any type of input.
• Interrupt can be used for this purpose.
at any time and
This techniques allow the processor to deal with events that can happen
that are not related to the process it is currently running.
method.
An alternative scheme for dealing with VO is the interrupt-driven
that requires attention.
An interrupt is a signal to the microprocessor from a device
it needs CPU's attention
A device controller puts an interrupt signal on the bus when
when CPU receives an interrupt.
interrupt handler using the interrupt
It saves its current state and invokes the appropriate
vector (addresses of OS routines to handle various events).
continues with its original
When the interrupting device has been dealt with, the CPU
task as if it had never been interrupted.
Interrupt.
Q. Differentiate between DMA, Polling, and
OQ7m.hønHn enmi
hv m•nei
1/0 SUBSYSTEMS
The combination of I/O devices, device drivers, and the I/O subsystem comprises the
overall I/O system in an embedded environment.
I/O subsystem is the most complex (messiest) part of the OS.
• To hide the device-specific information from the kernel as well as from the application
developer
• To provide a uniform access method to the peripheral I/O devices of the system
110Subsystem
Device Drivers
InterruptHandlers
parallel
hv mane' m•hønhl
To cope with various impcdancc mismatches bctwccn devices (speed, transfer size),
OS may buffer data in memory.
Various buffering strategies:
l. Single buffering: OS assigns a system buffer to the user request
2. Double buffering: process consumes from one buffer while system fills the
next
3. Circular buffering: most useful for burst 10
Without a buffer, the OS directly access the device when it needs
1/0 Device In
(a) No buffering
1. Single Buffering
In Move
I/O Device
2. Double Buffering
In Move
I/O Device
In Move
I/O Device
tm—neif
Unit-5
(I/O Management and Disk Scheduling)
RAID
(Redundant Arrays of
Independent/Inexpensive Disks)
RAID is a technique that makes use of a combination of multiple disks instead of
using a single disk for increased performance, data redundancy, or both.
RAID is very transparent to the underlying system. This means, to the host
system, it appears as a single big disk presenting itself as a linear array of blocks.
This allows older technologies to be replaced by RAID without making too many
changes to the existing code.
Different RAID Levels
1. RAID-0 (Stripping)
2. RAID-1 (Mirroring)
3. RAID-2 (Bit-Level Stripping with Dedicated Parity)- Obsolete, no need to
discuss.
4. RAID-3 (Byte-Level Stripping with Dedicated Parity)
5. RAID-4 (Block-Level Stripping with Dedicated Parity)
6. RAID-5 (Block-Level Stripping with Distributed Parity)
7. RAID-6 (Block-Level Stripping with two Parity Bits)
1. RAID-0 (Stripping)
Instead of placing just one block into a disk at a time, we can work with two
(or more) blocks placed into a disk before moving on to the next one.
Evaluation
Reliability:0
There is no duplication of data. Hence, a block once lost cannot be recovered.
Capacity:N*B
The entire space is being used to store data. Since there is no duplication, N
disks each having B blocks are fully utilized.
Advantages
1. It is easy to implement.
2. It utilizes the storage capacity in a better way.
Disadvantages
1. A single drive loss can result in the complete failure of the system.
2. Not a good choice for a critical system.
2. RAID-1 (Mirroring)
More than one copy of each block is stored in a separate disk. Thus, every
block has two (or more) copies, lying on different disks.
The below figure shows a RAID-1 system with mirroring level 2.
RAID 0 was unable to tolerate any disk failure. But RAID 1 is capable of
reliability.
Evaluation
Assume a RAID system with mirroring level 2.
Reliability:1toN/2
1 disk failure can be handled for certain because blocks of that disk would have
duplicates on some other disk. If we are lucky enough and disks 0 and 2 fail,
then again this can be handled as the blocks of these disks have duplicates on
disks 1 and 3. So, in the best case, N/2 disk failures can be handled.
Capacity:N*B/2
Only half the space is being used to store data. The other half is just a mirror
of the already stored data.
Advantages
1. It covers complete redundancy.
2. It can increase data security and speed.
Disadvantages
1. It is highly expensive.
2. Storage capacity is less.
Here in the below figure, Disk 3 contains the Parity bits for Disk 0, Disk 1, and
Disk 2. If data loss occurs, we can construct it with Disk 3.
Advantages
1. Data can be transferred in bulk.
2. Data can be accessed in parallel.
Disadvantages
1. It requires an additional drive for parity.
2. In the case of small-size files, it performs slowly.
Parity is calculated using a simple XOR function. If the data bits are 0,0,0,1
the parity bit is XOR(0,0,0,1) = 1. If the data bits are 0,1,1,0 the parity bit is
XOR(0,1,1,0) = 0. A simple approach is that an even number of ones results in
parity 0, and an odd number of ones results in parity 1.
Assume that in the above figure, C3 is lost due to some disk failure. Then, we
can recompute the data bit stored in C3 by looking at the values of all the other
columns and the parity bit. This allows us to recover lost data.
Evaluation
Reliability: 1
RAID-4 allows recovery of at most 1 disk failure (because of the way parity
works). If more than one disk fails, there is no way to recover the data.
Capacity:(N-1)*B
One disk in the system is reserved for storing the parity. Hence, (N-1) disks
are made available for data storage, each disk having B blocks.
Advantages
1. It helps in reconstructing the data if at most one data is lost.
Disadvantages
1. It can’t help in reconstructing when more than one data is lost.
This is a slight modification of the RAID-4 system where the only difference
is that the parity rotates among the drives.
In the figure below, we can notice how the parity bit “rotates”.
This was introduced to make the random write performance better.
Evaluation
Reliability:1
RAID-5 allows recovery of at most 1 disk failure (because of the way parity
works). If more than one disk fails, there is no way to recover the data. This is
identical to RAID-4.
Capacity:(N-1)*B
Overall, space equivalent to one disk is utilized in storing the parity. Hence,
(N-1) disks are made available for data storage, each disk having B blocks.
Advantages
1. Data can be reconstructed using parity bits.
2. It makes the performance better.
Disadvantages
1. Its technology is complex and extra space is required.
2. If both discs get damaged, data will be lost forever.
Raid-6 helps when there is more than one disk failure. A pair of independent
parities are generated and stored on multiple disks at this level. Ideally, you
need four disk drives for this level.
There are also hybrid RAIDs, which make use of more than one RAID level
nested one after the other, to fulfill specific requirements.
Advantages
1. Very high data Accessibility.
2. Fast read data transactions.
Disadvantages
1. Due to double parity, it has slow write data transactions.
2. Extra space is required.
Advantages of RAID
1. Increased data reliability: RAID provides redundancy, which means that if
one disk fails, the data can be recovered from the remaining disks in the array.
This makes RAID a reliable storage solution for critical data.
2. Improved performance: RAID can improve performance by spreading data
across multiple disks. This allows multiple read/write operations to co-occur,
which can speed up data access.
3. Scalability: RAID can be scaled by adding more disks to the array. This means
that storage capacity can be increased without having to replace the entire
storage system.
4. Cost-effective: Some RAID configurations, such as RAID 0, can be
implemented with low-cost hardware. This makes RAID a cost-effective
solution for small businesses or home users.
Disadvantages of RAID
1. Cost: Some RAID configurations, such as RAID 5 or RAID 6, can be
expensive to implement. This is because they require additional hardware or
software to provide redundancy.
2. Performance limitations: Some RAID configurations, such as RAID 1 or
RAID 5, can have performance limitations. For example, RAID 1 can only
read data as fast as a single drive, while RAID 5 can have slower write speeds
due to the parity calculations required.
3. Complexity: RAID can be complex to set up and maintain. This is especially
true for more advanced configurations, such as RAID 5 or RAID 6.
4. Increased risk of data loss: While RAID provides redundancy, it is not a
substitute for proper backups. If multiple drives fail simultaneously, data loss
can still occur.