0% found this document useful (0 votes)
166 views44 pages

OS IO Management & Disk Scheduling Unit 5

Uploaded by

acethvv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
166 views44 pages

OS IO Management & Disk Scheduling Unit 5

Uploaded by

acethvv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 44

IO Management & Disk

Scheduling
Introduction
• I/O management and disk scheduling are essential components
of a computer's operating system. I/O management controls
the flow of data into and out of a data processing complex. Disk
scheduling handles the organization and access of data on a disk.
I/O management involves:
• Reading from or writing to devices, such as disks, network
interfaces, or user input/output devices
• Controlling the flow of data into and out of a data processing
complex
• Transferring information between computer memory and the
outside world
Contt.
Disk scheduling involves:
• Determining the order in which the read/write head of
the disk moves to access data
• Ensuring that only one I/O request can be served at a
time by the disk controller
• Handling multiple I/O requests that may arrive by
different processes
• Being written as a separate module of the operating
system, allowing it to be replaced with a different
algorithm if necessary
I/O Devices
• I/O (input/output) devices are hardware that allows
humans or other systems to communicate with a
computer. I/O devices transfer data to and from a
computer.

• Examples of I/O devices include:

• Input devices: Keyboards, mice, scanners, and hard


disks
• Output devices: Monitors, printers, and headphones
I/O Subsystems
• The Input/Output (I/O) subsystem is a fundamental component of modern
operating systems. It manages all input/output operations on a
computer. The I/O subsystem provides various services that enable
efficient and secure management of the I/O operations.
• The I/O subsystem consists of:
• The system bus, Disk controllers, Disks, Tape drives, Other I/O devices,
Scheduling, Caching, Spooling, Device reservation, Error handling.
• The I/O subsystem is also responsible for protecting itself from rogue
programs and malicious users.
• The I/O subsystem can increase the system's overall performance,
distribute device access permissions evenly among all processes, and
reduce average wait times, response times, and turnaround times for I/O
to complete.
I/O Buffering
• A buffer is a memory area that stores data being transferred between two devices or between a
device and an application.
• Uses of I/O Buffering :
• Buffering is done to deal effectively with a speed mismatch between the producer and
consumer of the data stream.
• A buffer is produced in main memory to heap up the bytes received from modem.
• After receiving the data in the buffer, the data get transferred to disk from buffer in a single operation.
• This process of data transfer is not instantaneous, therefore the modem needs another buffer in order
to store additional incoming data.
• When the first buffer got filled, then it is requested to transfer the data to disk.
• The modem then starts filling the additional incoming data in the second buffer while the data in the
first buffer getting transferred to disk.
• When both the buffers completed their tasks, then the modem switches back to the first buffer while
the data from the second buffer get transferred to the disk.
• The use of two buffers disintegrates the producer and the consumer of the data, thus minimizes the
time requirements between them.
• Buffering also provides variations for devices that have different data transfer sizes.
Contt.
• Types of various I/O buffering techniques :
• 1. Single buffer :
A buffer is provided by the operating system to the system portion of
the main memory.
• Block oriented device –
• System buffer takes the input.
• After taking the input, the block gets transferred to the user space by
the process and then the process requests for another block.
• Stream oriented device –
• Line- at a time operation is used for scroll made terminals. User
inputs one line at a time, with a carriage return signaling at the end
of a line.
contt
• 2. Double buffer :
• Block oriented –
• There are two buffers in the system.
• One buffer is used by the driver or controller to store data while waiting
for it to be taken by higher level of the hierarchy.
• Other buffer is used to store data from the lower level module.
• Double buffering is also known as buffer swapping.
• Stream oriented –
• Line- at a time I/O, the user process need not be suspended for input or
output, unless process runs ahead of the double buffer.
• Byte- at a time operations, double buffer offers no advantage over a
single buffer of twice the length.
Disk Storage and Disk Scheduling
• A process needs two type of time, CPU time and IO
time. For I/O, it requests the Operating system to access
the disk.
• 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.
Contt..
• Some important terms related to 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 time taken to transfer the data.
Disk Access Time
• Disk access time is given as,
• Disk Access Time = Rotational Latency + Seek Time + Transfer Time
Disk Response Time
• It is the average of time spent by each request waiting for the I/O operation.
Purpose of Disk Scheduling
• 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.
Goal of Disk Scheduling Algorithm
• Fairness
• High throughout
• Minimal traveling head time
Disk Scheduling Algorithms

• 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.
• FCFS scheduling algorithm
• SSTF (shortest seek time first) algorithm
• SCAN scheduling
• C-SCAN scheduling
• LOOK Scheduling
• C-LOOK scheduling
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
Contt..

Number of cylinders crossed = 40 + 51 + 13 + +20 + 24 + 11


+ 4 + 46 = 209
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.
Contt…

Number of cylinders crossed = 11 + 13 + 20 + 24 + 11 + 4 + 46 + 169 = 298


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
• The scheme does not optimize the seek time.
• 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.
Contt..
Contt..
• 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
SSTF (shortest seek time first)
algorithm
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
• It may cause starvation for some requests.
• Switching direction on the frequent basis slows the working of
algorithm.
• It is not the most optimal algorithm.
Contt.
• 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
SCAN and C-SCAN algorithm
• 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.
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.
Contt...

Number of Cylinders = 40 + 14 + 65 + 13 + 20 + 24 + 11 + 4
+ 46 = 237
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.
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.
Contt..

No. of cylinders crossed = 40 + 14 + 199 + 16 + 46 + 4 + 11 + 24


+ 20 + 13 = 387
File System
• A file can be defined as a data structure which stores
the sequence of records. Files are stored in a file
system, which may exist on a disk or in the main
memory. Files can be simple (plain text) or complex
(specially-formatted).
• The collection of files is known as Directory.
• The collection of directories at the different levels, is
known as File System.
Attributes of the File

• 1.Name
• 2.Identifier
• 3.Type
• 4.Location
• 5.Size
• 6.Protection
• 7.Time and Date
Operations on the File

• Create operation:
• Open operation:
• Write operation:
• Read operation:
• Re-position or Seek operation:
• Delete operation:
• Close operation:
• Rename operation:
File Access Methods
• Let's look at various ways to access files stored in secondary memory.
Sequential Access
• Most of the operating systems access the file sequentially. In other
words, we can say that most of the files need to be accessed
sequentially by the operating system.
• In sequential access, the OS read the file word by word. A
pointer is maintained which initially points to the base address of the
file. If the user wants to read first word of the file then the pointer
provides that word to the user and increases its value by 1 word. This
process continues till the end of the file.
• Modern word systems do provide the concept of direct access
and indexed access but the most used method is sequential
access due to the fact that most of the files such as text files,
audio files, video files, etc need to be sequentially accessed.
Contt..
Direct Access

• The Direct Access is mostly required in the case of


database systems. In most of the cases, we need filtered
information from the database. The sequential access can
be very slow and inefficient in such cases.
• Suppose every block of the storage stores 4 records and we
know that the record we needed is stored in 10th block. In
that case, the sequential access will not be implemented
because it will traverse all the blocks in order to access the
needed record.
• Direct access will give the required result despite of the fact
that the operating system has to perform some complex
tasks such as determining the desired block number.
However, that is generally implemented in database
applications.
Contt..
Indexed Access

• If a file can be sorted on any of the filed then an index


can be assigned to a group of certain records. However,
A particular record can be accessed by its index.
The index is nothing but the address of a record in the
file.

• In index accessing, searching in a large database


became very quick and easy but we need to have
some extra space in the memory to store the
index value.
Directory Structure in OS

• What is a directory?
• Directory can be defined as the listing of the related
files on the disk. The directory may store some or the
entire file attributes.
• To get the benefit of different file systems on the
different operating systems, A hard disk can be divided
into the number of partitions of different sizes. The
partitions are also called volumes or mini disks.
• Each partition must have at least one directory in which,
all the files of the partition can be listed. A directory
entry is maintained for each file in the directory which
stores all the information related to that file.
• A directory can be viewed as a file which contains the
Meta data of the bunch of files.
Cont..
Single Level Directory

• The simplest method is to have one big list of all the


files on the disk. The entire system will contain only one
directory which is supposed to mention all the files
present in the file system. The directory contains one
entry per each file present on the file system.
Two Level Directory

• In two level directory systems, we can create a separate


directory for each user. There is one master directory
which contains separate directories dedicated to each
user. For each user, there is a different directory present
at the second level, containing group of user's file. The
system doesn't let a user to enter in the other user's
directory without permission.
Characteristics of two level directory system

1.Each files has a path name as /User-name/directory-


name/
2.Different users can have the same file name.
3.Searching becomes more efficient as only one user's
list needs to be traversed.
4.The same kind of files cannot be grouped into a single
directory for a particular user.
• Every Operating System maintains a variable
as PWD which contains the present directory name
(present user name) so that the searching can be done
appropriately.
File System Implementation in Operating System
• A file is a collection of related information. The file system resides on secondary storage
and provides efficient and convenient access to the disk by allowing data to be stored,
located, and retrieved.
• File System Structure: The file system structure refers to how the files and directories are
organized and stored on the physical storage device. This includes the layout of file
systems data structures such as the directory structure, file allocation table, and inodes.
• File Allocation: The file allocation mechanism determines how files are allocated on the
storage device. This can include allocation techniques such as contiguous allocation, linked
allocation, indexed allocation, or a combination of these techniques.
• Data Retrieval: The file system implementation determines how the data is read from and
written to the physical storage device. This includes strategies such as buffering and
caching to optimize file I/O performance.
• Security and Permissions: The file system implementation includes features for managing
file security and permissions. This includes access control lists (ACLs), file permissions, and
ownership management.
• Recovery and Fault Tolerance: The file system implementation includes features for
recovering from system failures and maintaining data integrity. This includes techniques
such as journaling and file system snapshots.
Contt..
File system Implementation Issues
• Management of disc space: To prevent space wastage and to guarantee that files can always be
stored in contiguous blocks, file systems must manage disc space effectively. Free space
management, fragmentation prevention, and garbage collection are methods for managing disc
space.

• Checking for consistency and repairing errors: The consistency and error-free operation of files
and directories must be guaranteed by file systems. Journaling, checksumming, and redundancy
are methods for consistency checking and error recovery. File systems may need to perform
recovery operations if errors happen in order to restore lost or damaged data.

• Locking files and managing concurrency: To prevent conflicts and guarantee data integrity, file
systems must control how many processes or users can access a file at once. File locking,
semaphore, and other concurrency-controlling methods are available.

• Performance optimization: File systems need to optimize performance by reducing file access
times, increasing throughput, and minimizing system overhead. Caching, buffering, prefetching,
and parallel processing are methods for improving performance.
Key Steps Involved In File System Implementation
• File system implementation is a crucial component of an operating system, as it provides an interface
between the user and the physical storage device. Here are the key steps involved in file system
implementation:
• Partitioning the storage device: The first step in file system implementation is to partition the physical
storage device into one or more logical partitions. Each partition is formatted with a specific file system that
defines the way files and directories are organized and stored.
• File system structures: File system structures are the data structures used by the operating system to
manage files and directories. Some of the key file system structures include the superblock, i-node table,
directory structure, and file allocation table.
• Allocation of storage space: The file system must allocate storage space for each file and directory on the
storage device. There are several methods for allocating storage space, including contiguous, linked, and
indexed allocation.
• File operations: The file system provides a set of operations that can be performed on files and directories,
including create, delete, read, write, open, close, and seek. These operations are implemented using the file
system structures and the storage allocation methods.
• File system security: The file system must provide security mechanisms to protect files and directories from
unauthorized access or modification. This can be done by setting file permissions, access control lists, or
encryption.
• File system maintenance: The file system must be maintained to ensure efficient and reliable operation.
This includes tasks such as disk defragmentation, disk checking, and backup and recovery.
Protection and Security in Operating
System
• Protection and security requires that computer resources such as CPU, softwares, memory etc.
are protected. This extends to the operating system as well as the data in the system. This can
be done by ensuring integrity, confidentiality and availability in the operating system. The
system must be protect against unauthorized access, viruses, worms etc.
Threats to Protection and Security
• A threat is a program that is malicious in nature and leads to harmful effects for the system. Some of the common threats that occur in
a system are:
Virus

• Viruses are generally small snippets of code embedded in a system. They are very dangerous and can corrupt files, destroy data,
crash systems etc. They can also spread further by replicating themselves as required.
Trojan Horse

• A trojan horse can secretly access the login details of a system. Then a malicious user can use these to enter the system as a
harmless being and wreak havoc.
Trap Door

• A trap door is a security breach that may be present in a system without the knowledge of the users. It can be exploited to
harm the data or files in a system by malicious people.
Worm
• A worm can destroy a system by using its resources to extreme levels. It can generate multiple copies which claim all the
resources and don't allow any other processes to access them. A worm can shut down a whole network in this way.
Denial of Service
• These type of attacks do not allow the legitimate users to access a system. It overwhelms the system with requests so it is
overwhelmed and cannot work properly for other user.
Protection and Security Methods

• The different methods that may provide protect and


security for different computer systems are −
Authentication
• This deals with identifying each user in the system and
making sure they are who they claim to be. The
operating system makes sure that all the users are
authenticated before they access the system. The
different ways to make sure that the users are authentic
are:
• Username/ Password
• User Key/ User Card
• User Attribute Identification
• One Time Password

You might also like