You are on page 1of 103

Noida Institute of Engineering and Technology,

Greater Noida

Operating System
KCS401

Unit: 5

I/O Management and Disk


Scheduling
Dr. C S Yadav
Professor and Head CSE
B Tech 4th Sem

Dr C S Yadav KCS401 OS Unit Number:5 1


15/05/2020
Course Objectives
• To learn the fundamentals of Operating Systems.

• To understand what a process is and how processes are


synchronized and scheduled.

• To understand different approaches to memory


management.

• Students should be able to use system calls for managing


processes, memory and the file system.

• To understand the structure and organization of the


file system.
Dr C S Yadav KCS401 OS Unit Number:5
15/05/2020 2
Course Outcomes
At the end of semester, students will be able to

CO1: Understand the structure and functions of OS

CO2: Learn about Processes, Threads and Scheduling


algorithms

CO3: Understand the principles of concurrency and Deadlocks

CO4: Learn various memory management scheme

CO5: Study I/O management and File systems

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 3


CO-PO Mapping

OPERATING SYSTEM(KCS-401)
CODE PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12

KCS401.1 3 3 2 2 1 2 - 2 3 2 2 3

KCS401.2 3 3 3 2 2 3 2 2 3 - 1 3

KCS401.3 3 3 2 2 2 2 2 2 2 3 1 3

KCS401.4 3 2 2 3 1 2 2 - 2 - 2 3

KCS401.5 3 1 2 2 2 2 - - 2 2 2 3

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 4


CO- PSO Mapping

Program Specific Outcomes


Course
Outcomes PSO1 PSO2 PSO3 PSO4

KCS401.1 2 1 2 2
KCS401.2 2 2 1 2
KCS401.3 2 3 3 2
KCS401.4 2 2 1 2
KCS401.5 2 2 2 2

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 5


Prerequisite and Recap

• Basic knowledge of computer fundamentals.

• Basic knowledge of computer organization.

• Memory hierarchy

• Cache Organization

• Interrupt

• Registers

• Associative memory

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 6


Unit-5 Content
• Disk structure
• Disk Scheduling Algorithms
• FCFS
• SSTF
• SCAN
• C-SCAN
• LOOK
• C-LOOK
• Disk Management
• RAID
• File access methods
• Directory structure
• File sharing and protection

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 7


Unit-5 Content
• File allocation methods
• Contiguous allocation
• Linked allocation
• Indexed allocation
• Free space management
• I/O Hardware
• I/O protection

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 8


Unit-5 Objectives
After going through this unit, you should be able to:
• understand the disk scheduling techniques.
• understand the concept of RAID.
• compare and contrast different approaches to file
organisations.
• compare and contrast different file allocation methods.
• know how to implement the file system and its protection
against unauthorised usage.

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 9


Disk structure(CO5)

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 10


Disk structure(CO5)

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 11


Disk structure(CO5)

• Disk drives are addressed as large 1-dimensional arrays of


logical blocks, where the logical block is the smallest unit
of transfer.
• The 1-dimensional array of logical blocks is mapped onto
the sectors of the disk sequentially.
–Sector 0 is the first sector of the first track on the
outermost cylinder.
–Mapping proceeds in order through that track, then the
rest of the tracks in that cylinder, and then through the
rest of the cylinders from outermost to innermost.

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 12


Disk Access Time(CO5)
• seek time: time to position heads on cylinder (a fixed head
disk does not require seek time but is more expensive than
a moving-head disk)

• rotational latency: delay in accessing material once seek


accomplished (time required to wait for data to rotate
around under head)
• Transmission time: time to transfer information once it is
under the head.
• access time = seek time + rotational latency
+read/write transmission time
seek time >> read/write time
15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 13
Disk Scheduling(CO5)

• The operating system is responsible for using hardware


efficiently — for the disk drives, this means having a fast
access time and disk bandwidth.
–Disk bandwidth is the total number of bytes transferred,
divided by the total time between the first request for
service and the completion of the last transfer.
• Accomplish this by minimizing seek time
–Seek time approximates seek distance

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 14


Disk Scheduling(CO5)

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 15


Disk I/O Request(CO5)
Disk I/O request specifies
• whether the operation is input or output
• disk address (block number, which is translated into
drive, cylinder, surface, and sector coordinates)
• memory address to copy to or from
• byte count giving the amount of information to be
transferred.

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 16


Disk Scheduling(CO5)
• Many requests may be pending at once. Which should be
handled first?
• Head moving strategy developed
• Attempting to manage the overall disk seek time. Latency
is not controllable and transfer time depends on the size of
the transfer request
• Different strategies:
–FCFS
–SSTF
–SCAN
–LOOK

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 17


FCFS Scheduling(CO5)
•Simplest form
•First-come, first-served scheduling
•Requests served in order of arrival
•Advantage: simple queueing
•Disadvantage: does not provide the “best” seek
time

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 18


FCFS(CO5)
Illustration shows total head movement of 640 cylinders

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 19


SSTF(CO5)

•Shortest Seek Time First selects the request with the


minimum seek time from the current head position
•SSTF scheduling is a form of SJF scheduling; may cause
starvation of some requests.
•Illustration shows total head movement of 236 cylinders

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 20


SSTF(CO5)

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 21


SCAN(CO5)

•The disk arm starts at one end of the disk, and moves toward the
other end, servicing requests until it gets to the other end of the
disk, where the head movement is reversed and servicing
continues

•SCAN algorithm sometimes called the elevator algorithm

•Illustration shows total head movement of 208 cylinders

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 22


SCAN(CO5)

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 23


C-SCAN(CO5)

•Provides a more uniform wait time than SCAN


•The head moves from one end of the disk to the other, servicing
requests as it goes
when it reaches the other end, however, it immediately returns
to the beginning of the disk, without servicing any requests on
the return trip
•Treats the cylinders as a circular list that wraps around from the last
cylinder to the first one

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 24


C-SCAN(CO5)

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 25


LOOK & C-LOOK(CO5)
•LOOK a version of SCAN, C-LOOK a version of C-SCAN

•Arm only goes as far as the last request in each direction,


then reverses direction immediately, without first going all
the way to the end of the disk

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 26


C-LOOK(CO5)

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 27


Selecting a Disk-Scheduling Algorithm(CO5)

•SSTF is common and has a natural appeal for low load disks
(quickly go to next request)
•LOOK, C-LOOK, SCAN and C-SCAN perform better for systems
that place a heavy load on the disk (no starvation, more
predictable delays)
•Performance depends on the number and
types of requests
•Requests for disk service can be influenced by the
file-allocation method

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 28


Disk Management(CO5)
•Low-level formatting, or physical formatting — Dividing a disk
into sectors that the disk controller can read and write
•Each sector can hold header information, plus data, plus error
correction code (ECC)
•Usually 512 bytes of data but can be selectable
•To use a disk to hold files, the operating system still needs to
record its own data structures on the disk
•Partition the disk into one or more groups of cylinders, each
treated as a logical disk
•Logical formatting or “making a file system”
•To increase efficiency most file systems group blocks into
clusters
•Disk I/O done in blocks
•File I/O done in clusters of blocks

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 29


Disk Management(CO5)

•Raw disk access for apps that want to do their own block
management, keep OS out of the way (databases for example)
•Boot block initializes system
•The bootstrap is stored in ROM
•Bootstrap loader program stored in boot blocks of boot
partition
•Methods such as sector sparing used to handle bad blocks

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 30


Booting from a Disk in Windows(CO5)

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 31


Swap-Space Management(CO5)
• Swap-space — Virtual memory uses disk space as an
extension of main memory.

• Swap space can be carved out of the normal file system, or,
more commonly, it can be in a separate disk partition.
• 4.3BSD allocates swap space when process starts; holds text
segment (the program) and data segment.
• Kernel uses swap maps to track swap-space use.
• Solaris 2 allocates swap space only when a page is forced out of
physical memory, not when the virtual memory page is first
created.

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 32


RAID Structure(CO5)
•RAID – redundant array of inexpensive/independent disks
•Multiple disk drives provides reliability via redundancy
•Increases the mean time to failure
•Mean time to repair – exposure time when another failure could cause
data loss
•Mean time to data loss based on above factors
•If mirrored disks fail independently, consider disk with 100,000 mean
time to failure and 10 hour mean time to repair
•Mean time to data loss is 100,0002 / (2 ∗ 10) = 500 ∗ 106 hours, or
57,000 years!
•Frequently combined with NVRAM to improve write performance
•RAID is arranged into six different levels
15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 33
RAID(CO5)
•Several improvements in disk-use techniques involve the use of
multiple disks working cooperatively
•Disk striping uses a group of disks as one storage unit
•RAID schemes improve performance and improve the reliability of
the storage system by storing redundant data
•Mirroring or shadowing (RAID 1) keeps duplicate of each disk
•Striped mirrors (RAID 1+0) or mirrored stripes (RAID 0+1)
provides high performance and high reliability
•Block interleaved parity (RAID 4, 5, 6) uses much less
redundancy.

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 34


RAID(CO5)
•RAID within a storage array can still fail if the array fails, so
automatic replication of the data between arrays is
common
•Frequently, a small number of hot-spare disks are left
unallocated, automatically replacing a failed disk and having
data rebuilt onto them

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 35


RAID Levels(CO5)

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 36


RAID (0 + 1) and (1 + 0)(CO5)

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 37


File Concept(CO5)

•Contiguous logical address space


•File = collection of related information recorded on
secondary storage

•Types: File “interpretation” is up to user/program


•Data
•Numeric (text, ASCII; “LINE_MAX” bytes)
•Character (text, ASCII; “LINE_MAX” bytes)
•Binary (executable, readable by computer)
•Program

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 38


File Structure(CO5)
• None - sequence of words, bytes

• Simple record structure

– Lines

– Fixed length

– Variable length

• Complex Structures

– Formatted document

• Who decides:

– Operating system

– Program
15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 39
File Attributes(CO5)

• Name – only information kept in human-readable form


• Identifier – unique tag (number) identifies file within file system

• Type – needed for systems that support different types

• Location – pointer to file location on device

• Size – current file size

• Protection (ACL) – controls who can do reading, writing, executing

• Time, date, and user identification – data for protection, security, and
usage monitoring

• Information about files are kept in the directory structure, which is


maintained on the disk

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 40


File Operations(CO5)
• File is an abstract data type
• Basic operations on files:
– Create
– Write
– Read
– Reposition within file
– Delete
– Truncate
• Open(Fi) – search the directory structure on disk for entry Fi, and
move the content of entry to memory

• Close (Fi) – move the content of entry Fi in memory back to directory


structure on disk
• Opening files: “remember” used files; efficiency; convenience
15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 41
File Types – Name, Extension(CO5)

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 42


Access Methods(CO5)

• Sequential Access
read next
write next
reset
skip forward
• Direct Access
read n
write n
position to n
read next
write next
rewrite n
n = relative block number

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 43


Sequential-Access File(CO5)

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 44


Simulation of Sequential Access on
Direct-Access File(CO5)

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 45


Directory Structure(CO5)
• A collection of nodes containing information about all files

Directory

Files
F1 F2 F4
F3
Fn

Both the directory structure and the files reside on disk


Backups of these two structures are kept on tapes
15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 46
Disk Structure(C05)
• Disk can be subdivided into partitions

• Disks or partitions can be RAID protected against failure

• Disk or partition can be used raw – without a file system, or


formatted with a file system

• Partitions also known as minidisks, slices

• Entity containing file system known as a volume

• Each volume containing file system also tracks that file system’s info
in device directory or volume table of contents

• In addition to general-purpose file systems, there can be many


special-purpose file systems
15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 47
A Typical File-system Organization(CO5)

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 48


Operations Performed on Directory(CO5)

• Search for a file

• Create a file

• Delete a file

• List a directory

• Rename a file

• Traverse the file system

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 49


Directory Structure(CO5)

Directory is Organize to Obtain


•Efficiency – locating a file quickly

•Naming – convenient to users


•Two users can have same name for different files
•The same file can have several different names

•Grouping – logical grouping of files by properties

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 50


Single-Level Directory(CO5)

• A single directory for all users

Naming problem

Grouping problem

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 51


Two-Level Directory(CO5)
• Separate directory for each user

• Path name
• Can have the same file name for different user
• Efficient searching
• No grouping capability

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 52


Tree-Structured Directories(CO5)

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 53


Tree-Structured Directories(CO5)
• Efficient searching

• Grouping Capability

• Current directory (“working directory”)

– cd /spell/mail/prog

– cd ~

– cd .

– cd ..

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 54


Tree-Structured Directories(CO5)

• Absolute or relative path name

• Creating a new file is done in current directory

• Delete a file

rm <file-name>

• Creating a new subdirectory is done in current directory

mkdir <dir-name>
Deleting “mail”  deleting the entire subtree rooted by “mail”
Example: if in current directory /mail

mkdir count

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 55


Acyclic-Graph Directories(CO5)
Have shared subdirectories and files

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 56


General Graph Directory(CO5)

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 57


General Graph Directory(CO5)

 How do we guarantee no cycles?

◦ Allow only links to files, not subdirectories

◦ Every time a new link is added use a cycle detection algorithm


to determine whether it is OK

◦ Ignore links for activities such as recursive search/delete/etc.

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 58


File Sharing(CO5)

• Sharing of files on multi-user systems is desirable

• Sharing may be done through a protection scheme

• On distributed systems, files may be shared across a network

• Network File System (NFS) is a common distributed file-sharing


method

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 59


File Sharing – Multiple Users(CO5)

• User IDs identify users, allowing permissions and


protections to be per-user

• Group IDs allow users to be in groups, permitting group


access rights

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 60


Protection(CO5)

• File owner/creator should be able to control:


– what can be done
– by whom
• Types of access
– Read
– Write
– Execute
– Append
– Delete
– List

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 61


Access Lists and Groups(CO5)

• Mode of access: read, write, execute

• Three classes of users


RWX
a) owner access 7  111
RWX
b) group access 6  110
RWX
c) public access 1  001

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 62


File-System Structure(CO5)
• File structure
– Logical storage unit
– Collection of related information
• File system resides on secondary storage (disks)
– Provided user interface to storage, mapping logical to physical
– Provides efficient and convenient access to disk by allowing data
to be stored, located retrieved easily
• File control block (FCB) – storage structure consisting of
information about a file (“i-node”)

• File system organized into layers

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 63


Layered File System(CO5)

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 64


Directory Implementation(CO5)
• Linear list of file names with pointer to the data blocks

– Simple to program

– Time-consuming to execute
• Linear search time
• Could keep ordered alphabetically via linked list or use B+
tree
• Hash Table – linear list with hash data structure

– Decreases directory search time

– Collisions – situations where two file names hash to the same


location

– Fixed size entries or use chained-overflow method


15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 65
Allocation Methods(CO5)
An allocation method refers to how disk blocks are allocated for
files.
•Allocation Methods:
•Contiguous allocation
•Linked allocation
•Indexed allocation

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 66


Contiguous allocation(CO5)
Contiguous allocation :
•each file occupies set of contiguous blocks
•Provides efficient direct access.
•Simple – only starting location (block #) and length (number of
blocks) are required
•Both sequential and direct access can be supported
•First fit and best fit are the most common used strategies.
•External fragmentation can be a problem
•Best performance in most cases
•Problems include finding space for file, knowing file size, external
fragmentation, need for compaction off-line (downtime) or on-line

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 67


Contiguous allocation(CO5)

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 68


Linked Allocation(CO5)
• Each file is a linked list of fixed-size disk blocks.

• Blocks may be scattered anywhere on the disk.

• Allocate blocks as needed as the file grows, wherever they are

available on the disk

• The directory contains a pointer to the first and last blocks of the

file

• Each block contains a pointer to the next block (not


accessible by users)

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 69


Linked Allocation(CO5)
• Simple – only need to keep the starting address of each file.

• No external fragmentation. Any free block can be used to

satisfy a request for more space.

• Creating a file is easy, declared of size zero (null pointer to


the first block) then grow easily as long as free blocks are
available
• No efficient direct access.

• Effective for sequential access


• Pointers saved in the blocks consume some space

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 70


Linked Allocation(CO5)
• Use of clusters (a set of blocks which the system deals with as a
unit)
• Decreases overhead of pointers (4 blocks = 1 cluster

needs 1 ptr)
• Increases throughput (fewer head seeks).

• Increases internal fragmentation.

• Reliability: if a pointer is lost, blocks (clusters) can’t be

traversed

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 71


Linked Allocation(CO5)

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 72


Indexed Allocation(CO5)
• Each file has its own index block, which is an array of disk-

block addresses

• The directory contains the address of the index block, from

which the ith block can be accessed directly

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 73


Indexed Allocation(CO5)

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 74


Indexed Allocation(CO5)
• More efficient direct access than linked allocation.

• No external fragmentation. Any free block can be used to satisfy a

request for more space.

• Suffers from a wasted space due to the use of index block. (pointer

overhead is larger)

• How large the index block should be? What if a file is too large
for one index block?
• Linked scheme: use one block. To allow larger files, link
several index blocks
• Multilevel index: use a first-level index block to point to a
second-level index blocks
• Combined scheme: used in UNIX.
15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 75
Free-Space Management(CO5)
• File system maintains free-space list to track available
blocks/clusters
– (Using term “block” for simplicity)
• Bit vector or bit map (n blocks)

Block number calculation


0 1 2 n-1
(number of bits per word) *
… (number of 0-value words) +
offset of first 1 bit


1  block[i] free
bit[i] = CPUs have instructions to
0  block[i] occupied return offset within
word of first “1” bit

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 76


Free-Space Management(CO5)
• Bit map requires extra space
– Example:
block size = 4KB = 212 bytes
disk size = 240 bytes (1 terabyte)
n = 240/212 = 228 bits (or 256 MB)
if clusters of 4 blocks -> 64MB of memory
• Easy to get contiguous files

• Linked list (free list)


– Cannot get contiguous space easily
– No waste of space
– No need to traverse the entire list (if # free blocks recorded)

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 77


Linked Free Space List on Disk(CO5)

• Linked list (free list)


• Cannot get contiguous
space easily
• No waste of space
• No need to traverse the
entire list (if # free
blocks recorded)

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 78


Free-Space Management(CO5)
• 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)

• 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

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 79


I/O Systems(CO5)

• I/O management is a major component of operating


system design and operation
• Important aspect of computer operation
• I/O devices vary greatly
• Various methods to control them
• Performance management
• New types of devices frequent
• Ports, busses, device controllers connect to various devices

• Device drivers encapsulate device details

• Present uniform device-access interface to I/O subsystem

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 80


I/O Hardware(CO5)
• Incredible variety of I/O devices
• Storage
• Transmission
• Human-interface

• Common concepts – signals from I/O devices interface with computer


• Port – connection point for device
• Bus - daisy chain or shared direct access
• PCI bus common in PCs and servers, PCI Express (PCIe)
• expansion bus connects relatively slow devices
• Controller (host adapter) – electronics that operate port, bus, device
• Sometimes integrated
• Sometimes separate circuit board (host adapter)
• Contains processor, microcode, private memory, bus controller, etc
• – Some talk to per-device controller with bus controller,
microcode, memory, etc
15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 81
A Typical PC Bus Structure(CO5)

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 82


I/O Hardware (CO5)
• I/O instructions control devices

• Devices usually have registers where device driver places commands,


addresses, and data to write, or read data from registers after
command execution
• Data-in register, data-out register, status register, control register
• Typically 1-4 bytes, or FIFO buffer
• Devices have addresses, used by

• Direct I/O instructions

• Memory-mapped I/O
• Device data and command registers mapped to processor
address space
• Especially for large address spaces (graphics)
15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 83
Polling(CO5)
• For each byte of I/O
1. Read busy bit from status register until 0
2. Host sets read or write bit and if write copies data into data-out
register
3. Host sets command-ready bit
4. Controller sets busy bit, executes transfer
5. Controller clears busy bit, error bit, command-ready bit when
transfer done
• Step 1 is busy-wait cycle to wait for I/O from device
• Reasonable if device is fast
• But inefficient if device slow
• CPU switches to other tasks?
• But if miss a cycle data overwritten / lost

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 84


Interrupts(CO5)
• Polling can happen in 3 instruction cycles
• Read status, logical-and to extract status bit, branch if not zero
• How to be more efficient if non-zero infrequently?
• CPU Interrupt-request line triggered by I/O device
• Checked by processor after each instruction
• Interrupt handler receives interrupts
• Maskable to ignore or delay some interrupts
• Interrupt vector to dispatch interrupt to correct handler
• Context switch at start and end
• Based on priority
• Some nonmaskable
• Interrupt chaining if more than one device at same
interrupt number

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 85


Direct Memory Access(CO5)
• Used to avoid programmed I/O (one byte at a time) for large data
movement

• Requires DMA controller

• Bypasses CPU to transfer data directly between I/O device and


memory

• OS writes DMA command block into memory


• Source and destination addresses
• Read or write mode
• Count of bytes
• Writes location of command block to DMA controller
• Bus mastering of DMA controller – grabs bus from CPU
• Cycle stealing from CPU but still much more efficient
• When done, interrupts to signal completion
15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 86
Characteristics of I/O Devices(CO5)

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 87


Characteristics of I/O Devices(CO5)
• Subtleties of devices handled by device drivers

• Broadly I/O devices can be grouped by the OS into

• Block I/O

• Character I/O (Stream)

• Memory-mapped file access

• Network sockets

• For direct manipulation of I/O device specific characteristics,


usually an escape / back door

• Unix ioctl()call to send arbitrary bits to a device control


register and data to device data register
15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 88
Block and Character Devices(CO5)
• Block devices include disk drives

• Commands include read, write, seek

• Raw I/O, direct I/O, or file-system access

• Memory-mapped file access possible


• File mapped to virtual memory and clusters brought via
demand paging
• DMA

• Character devices include keyboards, mice, serial ports

• Commands include get(), put()

• Libraries layered on top allow line editing


15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 89
Network Devices(CO5)

• Subtleties of devices handled by device drivers

• Broadly I/O devices can be grouped by the OS into


• Block I/O
• Character I/O (Stream)
• Memory-mapped file access
• Network sockets
• For direct manipulation of I/O device specific
characteristics, usually an escape / back door

• Unix ioctl()call to send arbitrary bits to a device


control register and data to device data register

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 90


I/O Protection(CO5)

• User process may accidentally or purposefully attempt


to disrupt normal operation via illegal I/O instructions

• All I/O instructions defined to be privileged

• I/O must be performed via system calls

• Memory-mapped and I/O port memory locations


must be protected too

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 91


Faculty Video Links, Youtube & NPTEL Video Links
and Online Courses Details

Youtube/other Video Links

• https://www.youtube.com/watch?v=aKmuGwHj3Cw
• https://www.youtube.com/playlist?list=PLmXKhU9FNesSF
vj6gASuWmQd23Ul5omtD
• https://www.youtube.com/watch?v=Fizc0nXRm2g
• https://www.youtube.com/watch?v=RgYU5r9A5TU
• https://nptel.ac.in/courses/106108101

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 92


Daily Quiz
1. In the ______ algorithm, the disk arm starts at one end of the
disk and moves toward the other end, servicing requests till the
other end of the disk. At the other end, the direction is reversed
and servicing continues.
A. LOOK
B. SCAN
C. C-SCAN
D. C-LOOK
2. In the sequential access method, information in the file is
processed ____________
A. one disk after the other, record access doesnt matter
B. one record after the other
C. one text document after the other
D. none of the mentioned

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 93


. Discuss the file access mechanisms

Weekly Assignment
• Explain Seek Time and Rotational Latency

• Discuss the file access mechanisms

• Explain Seek Time and Rotational Latency

• Name the file allocation methods

• Write the full form of RAID

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 94


Old Question Papers

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 95


Old Question Papers

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 96


Old Question Papers

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 97


Old Question Papers

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 98


Expected Questions for University Exam

1. What are the different file organizations? Discuss access


mechanisms in detail.

2. Discuss FCFS, CSCAN, LOOK and CLOOK disk scheduling


algorithms with example.

3. Explain different levels of RAID file structure.

4. Discuss various File allocation methods.

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 99


Expected Questions for University Exam
5. Suppose the moving head disk with 300 cylinders is currently
serving a request at track 47 and has just finished a request track
63. If the queue of request is kept in FIFO
order58,37,148,90,97,193,225,24. Explain are total head
movements for the following Diskscheduling algorithm?
i. FCFS ii. SSTF iii. C-SCAN iv. C LOOK

6. Differentiate between Blocking and Non blocking I/O

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 100


Summary
In this module, we have studied the following:
• Disk structure
• Disk Scheduling Algorithms
• FCFS
• SSTF
• SCAN
• C-SCAN
• LOOK
• C-LOOK
• Disk Management
• RAID
• File access methods
• Directory structure
• File sharing and protection

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 101


Summary
• File allocation methods
• Contiguous allocation
• Linked allocation
• Indexed allocation
• Free space management
• I/O Hardware
• I/O protection

15/05/2020 Dr C S Yadav KCS401 OS Unit Number:5 102


References
Books :
1. Silberschatz, Galvin and Gagne, “Operating Systems Concepts”,
Wiley
2. SibsankarHalder and Alex A Aravind, “Operating Systems”, Pearson
Education
3. Harvey M Dietel, “ An Introduction to Operating System”, Pearson
Education
4. D M Dhamdhere, “Operating Systems : A Concept basedApproach”,
McGraw Hill.
5. Charles Crowley, “Operating Systems: A Design-Oriented
Approach”, Tata McGraw Hill Education”.
6. Stuart E. Madnick & John J. Donovan, “ Operating Systems”, Tata
15/05/2020 McGraw Dr C S Yadav KCS401 OS Unit Number:5 103

You might also like