Unit5 Complete
Unit5 Complete
• 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.
• 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.
6 August 2023 1
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
6 August 2023 2
A Typical PC Bus Structure(CO5)
6 August 2023 3
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
• –6Some talk to per-device controller with bus controller, microcode, memory, etc
August 2023 4
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
• Memory-mapped I/O
• Device data and command registers mapped to processor address space
• Especially for large address spaces (graphics)
6 August 2023 5
I/0 Buffering(CO5)
6 August 2023 6
Types of Buffering (CO5)
Single Buffer
In Single Buffering, only one buffer is used to transfer the data between two devices. The producer
produces one block of data into the buffer. After that, the consumer consumes the buffer. Only
when the buffer is empty, the processor again produces the data.
6 August 2023 7
Double Buffering (CO5)
In Double Buffering, two schemes or two buffers are used in the place of one. In this buffering, the
producer produces one buffer while the consumer consumes another buffer simultaneously. So,
the producer not needs to wait for filling the buffer. Double buffering is also known as buffer
swapping.
6 August 2023 8
Circular Buffer (CO5)
Circular Buffering
circular Buffering
When more than two buffers are used, the buffers' collection is called a circular buffer. Each
buffer is being one unit in the circular buffer. The data transfer rate will increase using the
circular buffer rather than the double buffering.
6 August 2023 9
I/O port
I/O port (CO5)
• An I/O port usually consists of four different registers. These are (1) status, (2) control,
(3) data-in, and (4) data-out registers.
• The data-in register is read by the host for getting input.
• The data-out register is written by the host for sending output.
• The status register holds bits which can be read by the host.
• The control register is written by the host for starting a command or for changing the
mode of any device.
• The data registers are usually 1 to 4 bytes in size. Some of the controllers have FIFO
chips which hold several bytes of input or output data for expanding the capacity of the
controller beyond the size of the data register.
6 August 2023 10
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
6 August 2023 11
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
6 August 2023 12
Direct Memory Access(CO5)
• Used to avoid programmed I/O (one byte at a time) for large data
movement
6 August 2023 14
Characteristics of I/O Devices(CO5)
• Subtleties of devices handled by device drivers
• Block I/O
• Network sockets
6 August 2023 15
Block and Character Devices(CO5)
• Block devices include disk drives
6 August 2023 17
I/O Protection(CO5)
6 August 2023 18
Disk Storage(CO 5)
Disk storage (also sometimes called drive storage) is a general category of storage mechanisms
where data is recorded by various electronic, magnetic, optical, or mechanical changes to a surface
layer of one or more rotating disks.
A disk drive is a device implementing such a storage mechanism.
6 August 2023 19
Disk structure(CO5)
6 August 2023 20
Disk structure(CO5)
6 August 2023 21
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.
6 August 2023 22
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
6 August 2023 23
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
6 August 2023 24
Disk Scheduling(CO5)
6 August 2023 25
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
6 August 2023 26
FCFS(CO5)
Illustration shows total head movement of 640 cylinders
6 August 2023 27
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
6 August 2023 28
SSTF(CO5)
6 August 2023 29
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
6 August 2023 30
SCAN(CO5)
6 August 2023 31
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
6 August 2023 32
C-SCAN(CO5)
6 August 2023 33
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
6 August 2023 34
C-LOOK(CO5)
6 August 2023 35
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
6 August 2023 36
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
6 August 2023 37
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
6 August 2023 38
Booting from a Disk in Windows(CO5)
6 August 2023 39
Directory Structure(CO5)
• 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.
6 August 2023 40
Directory Structure
Directory Structure(CO5)
6 August 2023 41
Single Level Directory(CO5)
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.
6 August 2023 42
Single Level Directory(CO5)
Characteristics :
If the sizes of the files are very small then the searching becomes faster.
•File creation, searching, deletion is very simple since we have only one directory.
•We cannot have two files with the same name.
•The directory may be very big therefore searching for a file may take so much time.
•Protection cannot be implemented for multiple users.
•There are no ways to group same kind of files.
•Choosing the unique name for every file is a bit complex and limits the number of files in the
system because most of the Operating System limits the number of characters used to
construct the file name.
6 August 2023 43
Two Level Directory(CO5)
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.
6 August 2023 44
CharacteristicsTwo
of two
wo level
Level
Level directory system
Directory(CO5)
Directory(CO5)
Characteristics :
•Each files has a path name as /User-name/directory-name/
•Different users can have the same file name.
•Searching becomes more efficient as only one user's list needs to be traversed.
•The same kind of files cannot be grouped into a single directory for a particular
use
6 August 2023 45
system
Tree structured directory
• In Tree structured directory system, any directory entry can either be a file or sub
directory. Tree structured directory system overcomes the drawbacks of two level
directory system. The similar kind of files can now be grouped in one directory.
• Each user has its own directory and it cannot enter in the other user's directory.
However, the user has the permission to read the root's data but he cannot write or
modify this. Only administrator of the system has the complete access of root
directory.
6 August 2023 46
system
Tree structured directory
6 August 2023 47
File Concept(CO5)
•Contiguous logical address space
•File = collection of related information recorded on
secondary storage
6 August 2023 48
File Concept(CO5)
•Contiguous logical address space
•File = collection of related information recorded on secondary storage
•Types:
•Data
File “interpretation” is up to user/program
•Numeric (text, ASCII; “LINE_MAX” bytes)
•Character (text, ASCII; “LINE_MAX” bytes)
•Binary (executable, readable by computer)
•Program
6 August 2023 49
File Concept(CO5)
File
A file is a named collection of related information that is recorded on secondary storage such as
magnetic disks, magnetic tapes and optical disks. In general, a file is a sequence of bits, bytes, lines
or records whose meaning is defined by the files creator and user.
File Structure
•A File Structure should be according to a required format that the operating system can understand.
•A file has a certain defined structure according to its type. File “interpretation” i
•A text file is a sequence of characters organized into lines. program
•A source file is a sequence of procedures and functions.
•An object file is a sequence of bytes organized into blocks that are understandable by the machine.
•When operating system defines different file structures, it also contains the code to support these
file structure. Unix, MS-DOS support minimum number of file
6 August 2023 50
File Attributes(CO5)
• 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
6 August 2023 51
File Operations(CO5)
• File is an abstract data type
to memory
• Close (Fi) – move the content of entry Fi in memory back to directory structure on disk
6 August 2023 52
File Types – Name, Extension(CO5)
6 August 2023 53
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
6 August 2023 54
Sequential-Access File(CO5)
6 August 2023 55
Simulation of Sequential Access on
Direct-Access File(CO5)
6 August 2023 56
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.
6 August 2023 57
Allocation Methods(CO5)
An allocation method refers to how disk blocks are allocated for files.
•Allocation Methods:
•Contiguous allocation
•Linked allocation
•Indexed allocation
6 August 2023 58
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.
6 August 2023 59
Contiguous allocation(CO5)
6 August 2023 60
Linked Allocation(CO5)
• 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)
6 August 2023 61
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.
6 August 2023 62
Linked Allocation(CO5)
• Use of clusters (a set of blocks which the system deals with as a unit)
6 August 2023 63
Linked Allocation(CO5)
6 August 2023 64
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
6 August 2023 65
Indexed Allocation(CO5)
6 August 2023 66
Indexed Allocation(CO5)
• 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
6 August 2023 67
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)
1 block[i] free
bit[i] = CPUs have instructions
0 block[i] occupied to return offset
within word of first
“1” bit
6 August 2023 68
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)
6 August 2023 69
Linked Free Space List on Disk(CO5)
6 August 2023 70
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
6 August 2023 71
Bit Vector
• In this approach, the free space list is implemented as a bit map vector. It
contains the number of bits where each bit represents each block.
• If the block is empty then the bit is 1 otherwise it is 0. Initially all the blocks
are empty therefore each bit in the bit map vector contains 1.
• LAs the space allocation proceeds, the file system starts allocating blocks to
the files and setting the respective bit to 0.
6 August 2023 72
Linked List
6 August 2023 73
Threats to Protection and Security
• Protection and security requires that computer resources such as CPU, software's, 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.
6 August 2023 74
Threats to Protection and Security
• 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
6 August 2023 75
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/ PasswordEach user has a distinct username and password combination and
they need to enter it correctly before they can access the system.
• User Key/ User CardThe users need to punch a card into the card slot or use they
individual key on a keypad to access the system.
• User Attribute IdentificationDifferent user attribute identifications that can be used are
fingerprint, eye retina etc.
6 August 2023 76
Protection and Security Methods
6 August 2023 77
RAID Structure(CO5)
6 August 2023 78
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.
6 August 2023 79
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
6 August 2023 80
RAID 0: Block Level Striping
No redundancy;
parallel read for large data transfers (larger than block size)
81
RAID 1: Mirroring
No striping
…
Disk 1
Mirror
Mirrored copy
Disk 2
82
RAID 1
• We are just mirroring the disks (copying one disk to another one).
• Reliability provided. If one disk fails, data can be recovered from the other disk.
overhead/data = 1/1
83
RAID 2
b0 b1 b2 b3 c0 c1 c2
b4 b5 b6 b7 c0 c0 c0
…. …. …. ….
d: data bit
c: control bit
86
RAID 3
b b b b p 1 0 1 1 1
example
b b b b p 0 1 0 1 0
overhead/data = 1/4
87
RAID 3: example
b0 b1 b2 b3 p
b4 b5 b6 b7 p
… …. …. … ….
88
RAID 3: example
1 0 1 1 1
0 1 0 1 0
… …. …. … ….
89
RAID 3: example
1 0 1 1 1
0 1 0 1 0
… …. …. … ….
90
RAID 3: example
1 0 11 1 1
0 1 00 1 0
… …. …. … ….
91
RAID 4
Parity
Block 0 Block 1 Block 2 Block 3
Block
Parity
Block 4 Block 5 Block 6 Block 7
Block
Parity
Block 8 Block 9 Block 10 Block 11
Block
….
92
RAID 5
Parity
Block 0 Block 1 Block 2 Block 3
Block
Parity
Block 4 Block 5 Block 6 Block 7
Block
Parity
Block 8 Block 9 Block 10 Block 11
Block
….
93
RAID 6
• Similar to RAID level 5 but uses not only a single parity bit, but multiple ECC bits to guards against multiple
disk failures
• Example: 2-bits ECC code can be used for every 4-bits data.
94
RAID Levels (0 through 6) Summary
95
RAID Levels 0+1 and 1+0
96
RAID (0 + 1) and (1 + 0)(CO5)
6 August 2023 97
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 McGraw
6 August 2023 98
6 August 2023 99