Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Os Unit-5

Download as pdf or txt
Download as pdf or txt
You are on page 1of 47

Operating System

UNIT - 5

Topic 1 – “ Organization of I/O Function or Mode of Transfer”

The method that is used to transfer information between internal storage and external I/O devices
is known as I/O interface. The CPU is interfaced using special communication links by the
peripherals connected to any computer system. These communication links are used to resolve
the differences between CPU and peripheral. There exists special hardware components between
CPU and peripherals to supervise and synchronize all the input and output transfers that are
called interface units.

Mode of Transfer

The binary information that is received from an external device is usually stored in the memory
unit. The information that is transferred from the CPU to the external device is originated from
the memory unit. CPU merely processes the information but the source and target is always the
memory unit. Data transfer between CPU and the I/O devices may be done in different modes.

Data transfer to and from the peripherals may be done in any of the three possible ways

 Programmed I/O.
 Interrupt- initiated I/O.
 Direct memory access( DMA).

Now let’s discuss each mode one by one.

(1) Programmed I/O

It is due to the result of the I/O instructions that are written in the computer program. Each data
item transfer is initiated by an instruction in the program. Usually the transfer is from a CPU
register and memory. In this case it requires constant monitoring by the CPU of the peripheral
devices.

Example of Programmed I/O: In this case, the I/O device does not have direct access to the
memory unit. A transfer from I/O device to memory requires the execution of several
instructions by the CPU, including an input instruction to transfer the data from device to the
CPU and store instruction to transfer the data from CPU to memory. In programmed I/O, the
CPU stays in the program loop until the I/O unit indicates that it is ready for data transfer. This is
a time consuming process since it needlessly keeps the CPU busy. This situation can be avoided
by using an interrupt facility. This is discussed below.
(2) Interrupt- initiated I/O

Since in the above case we saw the CPU is kept busy unnecessarily. This situation can very well
be avoided by using an interrupt driven method for data transfer. By using interrupt facility and
special commands to inform the interface to issue an interrupt request signal whenever data is
available from any device. In the meantime the CPU can proceed for any other program
execution. The interface meanwhile keeps monitoring the device. Whenever it is determined that
the device is ready for data transfer it initiates an interrupt request signal to the computer. Upon
detection of an external interrupt signal the CPU stops momentarily the task that it was already
performing, branches to the service program to process the I/O transfer, and then return to the
task it was originally performing.

Note: Both the methods programmed I/O and Interrupt-driven I/O require the active intervention
of the processor to transfer data between memory and the I/O module, and any data transfer must
transverse a path through the processor. Thus both these forms of I/O suffer from two inherent
drawbacks. The I/O transfer rate is limited by the speed with which the processor can test and
service a device.The processor is tied up in managing an I/O transfer; a number of instructions
must be executed for each I/O transfer.

(3) Direct Memory Access

The data transfer between a fast storage media such as magnetic disk and memory unit is limited
by the speed of the CPU. Thus we can allow the peripherals directly communicate with each
other using the memory buses, removing the intervention of the CPU. This type of data transfer
technique is known as DMA or direct memory access. During DMA the CPU is idle and it has
no control over the memory buses. The DMA controller takes over the buses to manage the
transfer directly between the I/O devices and the memory unit.
Bus Request : It is used by the DMA controller to request the CPU to relinquish the control of
the buses.

Bus Grant : It is activated by the CPU to Inform the external DMA controller that the buses are
in high impedance state and the requesting DMA can take control of the buses. Once the DMA
has taken the control of the buses it transfers the data. This transfer can take place in many ways.

TOPIC 2 - “I/O SYSTEM AND SUBSYSTEM”

I/O devices are very important in the computer systems. They provide users the means of
interacting with the system. So there is a separate I/O system devoted to handling the I/O
devices.
The different Components of the I/O systems are:
I/O Hardware
There are many I/O devices handled by the operating system such as mouse, keyboard, disk
drive etc. There are different device drivers that can be connected to the operating system to
handle a specific device. The device controller is an interface between the device and the device
driver.
A diagram to represent this is:
I/O Application Interface
The user applications can access all the I/O devices using the device drivers, which are
device specific codes. The application layer sees a common interface for all the devices.
This is illustrated using the below image:

Most of the devices are either block I/O and character I/O devices. Block devices are
accessed one block at a time whereas character devices are accessed one character at a time.
I/O Software
The I/O software contains the user level libraries and the kernel modules. The libraries
provide the interface to the user program to perform input and output. The kernel modules
provides the device drivers that interact with the device controllers.
The I/O software should be device independent so that the programs can be used for any I/O
device without specifying it in advance. For example - A program that reads a file should be
able the read the file on a hard disk, floppy disk, CD-ROM etc. without having to change the
programeach time.
Topic 3 - “Hard Disk Storage Concepts and Disk Structure”

Disk Structure

 Disk surface divided into tracks


 A read/write head positioned just above the disk surface
 Information stored by magnetic recording on the track under read/write head
 Fixed head disk
 Moving head disk
 Designed for large amount of storage
 Primary design consideration cost, size, and speed
 Head crash
Hardware for disk system

 Disk drive, Device motor, Read/write head, Associated logic

Disk controller

 Determines the logical interaction with the computer


 Can service more than one drive (overlapped seeks)

Cylinder

 The same numbered tracks on all the disk surfaces


 Each track contains between 8 to 32 sectors

Sector

 Smallest unit of information that can be read from/written into disk


 Range from 32 bytes to 4096 bytes

Data accessed by specifying surface, track, and

sector View the disk as three dimensional array of

sectors

OS treats the disk as one dimensional array of disk

blocks s – Number of sectors per track

t – Number of tracks per surface

Disk address b of surface i, cylinder/track j, sector k

b= k + s*(j+i*t)
Seek time

 Time required by read/write head to move to requested track


 Includes the initial startup time and the time required to traverse the tracks to be crossed
once the access arm is up to speed

Latency or rotational delay

Time required for the requested sector to come under the read/write head
TOTopic 4 - “Disk Scheduling Introduction and Algorithms ”

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.

There are many Disk Scheduling Algorithms but before discussing them let’s have a quick look
at some of the important terms:
 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.
Disk Scheduling Algorithms

1. 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

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.
Number of cylinders moved by the head

= (50-45)+(45-21)+(67-21)+(90-67)+(90-4)+(50-4)+(89-50)+(61-52)+(87-
61)+(87-25)

= 5 + 24 + 46 + 23 + 86 + 46 + 49 + 9 + 26 + 62

= 376

2. SSTF DISK SCHEDULING

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
Example

Consider the following disk request sequence for a disk with 100 tracks 45, 21, 67, 90, 4, 89, 52,
61, 87, 25. Head pointer starting at 50. Find the number of head movements in cylinders using
SSTF scheduling.
Number of cylinders = 5 + 7 + 9 + 6 + 20 + 2 + 1 + 65 + 4 + 17 = 136

3. SCAN DISK SCHEDULING

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.

Advantages:
 High throughput
 Low variance of response time
 Average response time
Disadvantages:
 Long waiting time for requests for locations just visited by disk arm
Example

Consider the following disk request sequence for a disk with 100 tracks

98, 137, 122, 183, 14, 133, 65, 78 Head pointer starting at 54 and moving in left direction.

Find the number of head movements in cylinders using SCAN scheduling.

Number of Cylinders = 40 + 14 + 65 + 13 + 20 + 24 + 11 + 4 + 46 = 237

4. CSCAN Disk Scheduling

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).

Advantages:
 Provides more uniform wait time compared to SCAN
Example

Consider the following disk request sequence for a disk with 100 tracks

98, 137, 122, 183, 14, 133, 65, 78

Head pointer starting at 54 and moving in left direction. Find the number of head movements in
cylinders using C-SCAN scheduling.
No. of cylinders crossed = 40 + 14 + 199 + 16 + 46 + 4 + 11 + 24 + 20 + 13 = 387

5. Look Scheduling

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

Consider the following disk request sequence for a disk with 100 tracks

98, 137, 122, 183, 14, 133, 65, 78

Head pointer starting at 54 and moving in left direction. Find the number of head movements in
cylinders using LOOK scheduling
Number of cylinders crossed = 40 + 51 + 13 + +20 + 24 + 11 + 4 + 46 = 209

6. 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.

Example

Consider the following disk request sequence for a disk with 100 tracks

98, 137, 122, 183, 14, 133, 65, 78

Head pointer starting at 54 and moving in left direction. Find the number of head movements in
cylinders using C LOOK scheduling.
Number of cylinders crossed = 11 + 13 + 20 + 24 + 11 + 4 + 46 + 169 = 298

Topic 5 - RAID (Redundant Arrays of Independent Disks)

RAID, or “Redundant Arrays of Independent Disks” is a technique which makes use of a


combination of multiple disks instead of using a single disk for increased performance, data
redundancy or both.
The term was coined by David Patterson, Garth A. Gibson, and Randy Katz at the University of
California, Berkeley in 1987.

Why data redundancy?

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.
Key evaluation points for a RAID System

 Reliability: How many disk faults can the system tolerate?

 Availability: What fraction of the total session time is a system in uptime mode, i.e. how
available is the system for actual use?
 Performance: How good is the response time? How high is the throughput (rate of
processing work)? Note that performance contains a lot of parameters and not just the two.

 Capacity: Given a set of N disks each with B blocks, how much useful capacity is available
to the user?

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 in the existing code.
Different RAID levels

RAID-0 (Striping)
 Blocks are “striped” across disks

 In the figure, blocks “0,1,2,3” form a stripe.


 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: 0There 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.

RAID 2

 This uses bit level striping. i.e Instead of striping the blocks across the disks, it stripes the bits
across the disks.
 In the above diagram b1, b2, b3 are bits. E1, E2, E3 are error correction codes.
 You need two groups of disks. One group of disks are used to write the data, another group isused to
write the error correction codes.
 This uses Hamming error correction code (ECC), and stores this information in the
redundancy disks.

 When data is written to the disks, it calculates the ECC code for the data on the fly, and stripes
the data bits to the data-disks, and writes the ECC code to the redundancy disks.
 When data is read from the disks, it also reads the corresponding ECC code from the
redundancy disks, and checks whether the data is consistent. If required, it makes
appropriate corrections on the fly.
 This uses lot of disks and can be configured in different disk configuration. Some valid
configurations are 1) 10 disks for data and 4 disks for ECC 2) 4 disks for data and 3 disks forECC
 This is not used anymore. This is expensive and implementing it in a RAID controller is
complex, and ECC is redundant now-a-days, as the hard disk themselves can do this
RAID 3

 This uses byte level striping. i.e Instead of striping the blocks across the disks, it stripes thebytes
across the disks.
 In the above diagram B1, B2, B3 are bytes. p1, p2, p3 are parities.
 Uses multiple data disks, and a dedicated disk to store parity.

 The disks have to spin in sync to get to the data.


 Sequential read and write will have good performance.
 Random read and write will have worst performance.
 This is not commonly used.
RAID-4 (Block-Level Striping with Dedicated Parity)

 Instead of duplicating data, this adopts a parity-based approach

 In the figure, we can observe one column (disk) dedicated to parity.


 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 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 andthe 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
morethan 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.

RAID-5 (Block-Level Striping with Distributed Parity)


 This is a slight modification of the RAID-4 system where the only difference is that theparity
rotates among the drives

 In the figure, 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.
RAID -6

 Just like RAID 5, this does block level striping. However, it uses dual parity.
 In the above diagram A, B, C are blocks. p1, p2, p3 are parities.
 This creates two parity blocks for each data block.
 Can handle two disk failure
 This RAID configuration is complex to implement in a RAID controller, as it has to calculate
two parity data for each data block.
OS UNIT 5 PART 2

File System Concepts

Topic 1 - Overview of File

Computers can store information on various storage media such as, magnetic disks, magnetic tapes,
optical disks. The physical storage is converted into a logical storage unit by operating system. The
logical storage unit is called FILE.

A file is a collection of similar records. A record is a collection of related fields that can be treated as a
unit by some application program. A field is some basic element of data. Any individual field contains a
single value. A data base is collection of related data.

FILE ATTRIBUTES :

1. Name : A file is named for the convenience of the user and is referred by its name. A name is
usually a string of characters.

2. Identifier : This unique tag, usually a number ,identifies the file within the file system.

3. Type : Files are of so many types. The type depends on the extension of the file.

Example:

.exe Executable file


.obj Object file
.src Source file

4. Location : This information is a pointer to a device and to the location of the file on that device.

5. Size : The current size of the file (in bytes, words,blocks).

6. Protection : Access control information determines who can do reading, writing, executing and so
on.
7. Time, Date, User identification : This information may be kept for creation, last modification,last
use.

FILE OPERATIONS

1. Creating a file : Two steps are needed to create a file. They are:

. Check whether the space is available ornot.

.If the space is available then made an entry for the new file in the directory. The entry includes name
of the file, path of the file,etc…

2. Writing a file : To write a file, we have to know 2 things. One is name of the file and second is the
information or data to be written on the file, the system searches the entired given location for the
file. If the file is found, the system must keep a write pointer to the location in the file where the next
write is to take place.

3. Reading a file : To read a file, first of all we search the directories for the file, if the file is found,
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.

4. Repositioning within a file : The directory is searched for the appropriate entry and the current file
position pointer is repositioned to a given value. This operation is also called file seek.

5. Deleting a file : To delete a file, first of all search the directory for named file, then released the
file space and erase the directory entry.

6. Truncating a file : To truncate a file, remove the file contents only but, the attributes are as itis.

FILE TYPES: The name of the file split into 2 parts. One is name and second is Extension. The file
type is depending on extension of the file.
FILE STRUCTURE

File types also can be used to indicate the internal structure of the file. The operating system requires
that an executable file have a specific structure so that it can determine where in memory to load the
file and what the location of the first instruction is.
If OS supports multiple file structures, the resulting size of Operating System is large. If the OS
defines 5 different file structures, it needs to contain the code to support these file structures. All OS
must support at least one structure that of an executable file so that the system is able to load and run
programs.
INTERNAL FILE STRUCTURE

In UNIX OS, defines all files to be simply stream of bytes. Each byte is individually addressable by
its offset from the beginning or end of the file. In this case, the logical record size is 1 byte.
The file system automatically packs and unpacks bytes into physical disk blocks, say 512 bytes per
block.

The logical record size, physical block size, packing determines how many logical records are in each
physical block. The packing can be done by the user’s application program or OS. A file may be
considered a sequence of blocks. If each block were 512 bytes, a file of 1949 bytes would be
allocated 4 blocks (2048 bytes). The last 99 bytes

would be wasted. It is called internal fragmentation all file systems suffer from internal
fragmentation, the larger the block size, the greater the internal fragmentation.

Topic 2 - FILE ACCESS METHODS

Files stores information, this information must be accessed and read into computer memory. There
are so many ways that the information in the file can be accessed.

1. Sequential file access:

Information in the file is processed in order i.e. one record after the other.
Magnetic tapes are supporting this type of file accessing.

Eg : A file consisting of 100 records, the current position of read/write head is 45th record, suppose
we want to read the 75th record then, it access sequentially from 45, 46, 47 …….. 74, 75. So the
read/write head traverse all the records between 45 to 75.
2. Direct access:
Direct access is also called relative access. Here records can read/write randomly without any order.
The direct access method is based on a disk model of a file, because disks allow random access to
any file block.

Eg : A disk containing of 256 blocks, the position of read/write head is at 95th block. The block is to
be read or write is 250th block. Then we can access the 250th block directly without any restrictions.

Eg : CD consists of 10 songs, at present we are listening song 3, If we want to listen song 10, we can
shift to 10.

3. Indexed Sequential File access

The main disadvantage in the sequential file is, it takes more time to access a Record .Records are
organized in sequence based on a key field.

Eg :

A file consisting of 60000 records,the master index divide the total records into 6 blocks, each block
consisiting of a pointer to secondary index.The secondary index divide the 10,000 records into 10
indexes.Each index consisting of a pointer to its orginal location. Each record in the index file
consisting of 2 field, A key field and a pointer field.
Topic 3 - DIRECTORY STRUCTURE

Sometimes the file system consisting of millions of files,at that situation it is very hard to manage the
files. To manage these files grouped these files and load one group into one partition.
Each partition is called a directory .a directory structure provides a mechanism for organizing many
files in the file system.

OPERATION ON THE DIRECTORIES :

1. Search for a file : Search a directory structure for requiredfile.

2. createafile : New files need to be created, added to thedirectory.

3. Deleteafile : When a file is no longer needed,we want to remove it fromthe

directory.

4. List adirectory : We can know the list of files in thedirectory.

5. Renameafile : When ever we need to change the name of the file,wecanchange

thename.

6. Traverse the file system : We need to access every directory and every file with in a directory
structure we can traverse the file system
Topic 4 - Directory Levels
TOPIC 5 – File System Structure
Grouping
Modify linked list to store address of next n-1 free blocks in first free block, plus a pointer to next
block that contains free-block-pointers (like this one).
An advantage of this approach is that the addresses of a group of free disk blocks can be found
easily
Counting
Because space is frequently contiguously used and freed, with contiguous- allocation
allocation, extents, or clustering.
Keep address of first free block and count of following free blocks. Free space list then has entries
containing addresses and counts.
Directory Implementation
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.

You might also like