Module
4
I/O system, Hard disk, Files and Directories, File
Organization:
Hard Disk
Drives
Physical Geometry of a Hard Disk
Drive
1. Platter
Circular magnetic disks.
Multiple platters are stacked
vertically Both sides of each platter
Spindle
Rotates platters at high
speed
(e.g., 5400 RPM, 7200 RPM).
Read/Write
Heads
One head per platter surface.
Moves across the surface to access
data.
Data Organization (Disk Geometry)
Track
A circular ring on a
platter. Data is written
along tracks.
Secto
r
A subdivision of a track.
Smallest physical storage
unit. Typically 512 bytes or 4
KB. Atomic write
Cylinde
r
A cylinder is the collection of
tracks
at the same radius on all
platters.
A Simple Disk Drive
single track
12 sectors(0 through
11.) each of which is 512
bytes
Use a disk head to read
track 6
1. Single-track Latency: The Rotational
Delay
Want to read sector 0
wait for the desired sector to rotate under the
disk head Known as rotational delay
If full rotational delay is R
Delay in Accessing sector 0(assume head is at 6)=
R/2 Delay in accessing 5=R
2. Multiple Tracks: Seek
SeekTime
time is the time taken by the disk arm to move the read/write
head to the required track (cylinder) where the data is stored.
If the head is on track 10 and the required data is on track 150,
the disk arm must move across tracks → this movement time is
seek time.
acceleration + deceleration+ Settling time= Seek time
I/O Time in Hard Disk Drive
total time taken to read or write data from a disk.
I/O Time / TD = Seek Time + Rotational Latency +
Transfer Time
AMAT= Tm+(Pmiss*TD)
TD = I/O Time = Seek Time + Rotational Latency + Transfer
Time
Disk Scheduling
process of ordering disk I/O requests based on their track
(cylinder) numbers to minimize total seek time and improve
performance.
Disk scheduling decides which track to access next to reduce
head movement.
FCFS DISK SCHEDULING
• Requests are processed in the order they arrive in the
disk queue
• Simple but inefficient.
Initial head position = 50 [current track
no] Request queue = 98, 183, 37, 122, 14,
124, 65, 67
Total Seek Time = 48 + 85 + 146 + 85 + 108 + 110 + 59
+2
SSTF Scheduling(Shortest Seek Time
First)
• selects the request closest to the current head
position
Initial head position = 50
Request queue = 98, 183, 37, 122, 14, 124, 65,
67
Total Seek
Time
= 13 + 23 + 51
+ 2 + 31 + 24
+ 2 + 59
= 205
cylinders
Problem
Starvation
if request to the nearest track are coming constantly, other
track will starve
SCAN Scheduling(Elevator)
moves the disk arm in one direction, serving all requests, and
then reverses the direction.
It works like an elevator: It moves one way, serving requests in
order, and when it reaches the end, it reverses and serves
requests in the opposite direction.
Initial head position = 50
Request queue = 98, 183, 37, 122, 14, 124, 65,
67
Disk size (0 - 199)
Direction of movement = Right (increasing
order)
Total Seek Time = 15 + 2 +
31
+ 24 + 2 + 59 + 16 + 162 +
23
= 334 cylinders
C-SCAN Scheduling(Circular
Scan)
moves the disk arm only in one direction (e.g., right), serves
requests, and when it reaches the end, it jumps back to the beginning
without serving requests during the return.
initial head position = 50
Request queue = 98, 183, 37, 122, 14, 124, 65,
67
Disk size (0 - 199)
Direction of movement = Right (increasing
order)
SPTF: Shortest Positioning Time First
selects the disk I/O request that can be accessed in the shortest
total positioning time.
Positioning Time =Seek Time (head movement between
tracks)+ Rotational Latency (waiting for sector to rotate
under head)
I/O
system
System Architecture
CPU->m/y via M/y bus
Other High performance Devices via
PCI Eg: Graphics
Other low performance device disks, mice, and keyboards via SCSI,
SATA, or USB
Not in PCI- High
syllabus Memory performance
Bus
SATA
IDE
PORT
US
Intel’s Z270 Chipset
DMI- DIRECT MEDIA INTERFACE
eSATA- EXTERNAL SERIAL
ADVANCED TECHNOLOGY
ATTACHMENT
PCI- PERIPHERAL COMPONENT
INTERFACE
Programmed I/O
status register – TO SEE THE DEVICE STATUS
command register, to tell the device to perform a certain task
data register to pass data to the device, or get data from the
device
polling- REPEATED STATUS CHECKING
programmed I/O (PIO)- DATA MOVEMENT TO AND FROM CPU-DEVICE
Finally a success or failure
Disadvantage of polling
CPU has to wait for the device to
respond.
Make the processes to wait
Lowering CPU Overhead With Interrupts
When a process need I/O access
1. CPU issues a request
2. Put the calling process to sleep- context switch and let others
work
3. When the device finished its work, trigger hardware
interrupt
4. This interrupt is caught by OS and handled by Interrupt
handler
With
Polling
With
Interrupt
Other Approaches
1. hybrid- use polling first few times, if not ready use
interrupts
2. coalescing- deliver multiple interrupts togather
More Efficient Data Movement With
DMA
Direct Memory Access (DMA)- orchestrate transfers
between devices and main memory without much CPU
intervention.
When data transfer from RAM to Device required
OS would program the
DMA where the data lives
in RAM much data to copy
which device to send
OS is done with the transfer and can proceed with other
work When the DMA is complete- an interrupt is raised
Fitting Into The OS: The Device Driver
specialized software that acts as a translator between an
operating system (OS) and hardware devices, enabling them to
communicate
Files and Directories
Files- simply a linear array of
bytes
you can read or write
has low-level name- i node
number
directory
has a low-level name
it contains a list of (user-readable name, low-level
name) Assume there is a file “foo” with inode=10 in a
directory Then that directory has an entry (“foo”, “10”)
Has sub directories
absolute pathname
Separator -> /
/foo/[Link]
/bar/foo/
[Link].
The File System Interface
Mechanism tocreating, accessing, and deleting
files
Creating Files
system call->open()
int fd = open("foo", O_CREAT|O_WRONLY|O_TRUNC, S_IRUSR|
S_IWUSR);
Param 1-> file name
Param 2-> creates file if doe not
exist Param 3-> Permission Write
only
Param 3-> If file exist, truncate its data->make it to all
file descriptor
int fd = open("foo", O_CREAT|O_WRONLY|O_TRUNC, S_IRUSR|S_IWUSR);
fd-> just an integer
Pointer to the file
Using fd utilize appropriate methods to access
the file
Reading And Writing
Files
Sequential File Access
Data in the file is read or written in order, from beginning to
end.
The file pointer moves automatically to the next position
after each read/write.
To access a specific record, all previous records must be read
first.
Random (Direct) File
Access
Data can be read or written at any position in the file directly.
The file pointer can be moved to any location using special
functions. No need to read previous records.
Databases-Updating a specific record in a file
prompt> echo hello >
foo
prompt> cat
foo hello
prompt>
Removing
files
prompt> strace rm
foo
...
unlink("foo")
Unlink return zero upon
success
Making Directories
prompt> strace mkdir
foo
...
mkdir("foo", 0777) = 0
...
prompt>
Has two entries
. -> itself
.. -> parent directory
Reading Directories
Deleting Directories
rmdir()
If you try to delete a non-empty directory, the call to rmdir()
simply will fail
So it must have only . & ..
entries