I/O Management in OS DMA, Device Drivers, Scheduling
I/O Hardware
I/O devices communicate with the CPU through:
Ports: Connection points for I/O devices (USB, serial, parallel)
Buses: Shared communication pathways (PCI, USB, SATA, PCIe)
Device Controllers: Hardware components that manage specific devices. They have registers (data, status, control) that the CPU reads/writes.
I/O Techniques
Technique
Description
CPU Usage
Use Case
Programmed I/O (Polling)
CPU continuously checks device status (busy-waiting). CPU is fully occupied during I/O.
100% (wasteful)
Simple embedded systems
Interrupt-Driven I/O
CPU initiates I/O and continues other work. Device interrupts CPU when done.
Low (during I/O)
Most modern systems
DMA (Direct Memory Access)
DMA controller transfers data directly between device and memory without CPU involvement. CPU only involved at start and end.
Very Low
High-speed devices (disk, network)
Device Drivers
A device driver is software that provides a standard interface between the OS and a specific hardware device. It translates generic OS I/O requests into device-specific commands.
Disk scheduling determines the order in which disk I/O requests are serviced to minimize seek time (time for disk head to move to the correct track).
Example: Disk head at position 53. Requests: 98, 183, 37, 122, 14, 124, 65, 67
FCFS: Service in order of arrival. Simple but not optimal. Total movement: 640 cylinders.
SSTF (Shortest Seek Time First): Service the request closest to current head position. Reduces seek time but may cause starvation. Total movement: 236 cylinders.
SCAN (Elevator): Head moves in one direction, servicing requests, then reverses. Like an elevator. Total movement: 208 cylinders.
C-SCAN (Circular SCAN): Head moves in one direction only. When it reaches the end, it jumps back to the beginning without servicing. More uniform wait times.
LOOK: Like SCAN but head only goes as far as the last request in each direction (doesn't go to disk end).
Spooling and Buffering
Buffering: Temporary storage of data in memory while it's being transferred between devices or between a device and an application. Smooths out speed differences between producer and consumer.
Spooling (Simultaneous Peripheral Operations On-Line): Using disk as a buffer for I/O operations. Classic example: print spooling - print jobs are stored on disk and sent to the printer one at a time. Allows multiple processes to "print" simultaneously.
Asynchronous I/O Needs Completion and Backpressure Rules
Interrupts and DMA reduce CPU work for device transfers, but software still needs buffers, queues, completion notification, and error handling. Asynchronous submission separates request creation from completion, so the buffer and request state must remain valid until the completion is observed.
Bound outstanding operations so a fast producer cannot exhaust memory or device queues. Measure queue depth, service time, throughput, latency percentiles, and timeout behavior. Cancellation may race with completion; design one owner to finalize resources exactly once.
I/O OS state trace
I/O OS state trace
Event 1: a process requests a resource related to I/O
Event 2: the kernel checks permissions, availability, and current state
Event 3: the scheduler or manager decides whether to run, wait, block, or fail
Event 4: the process observes the result and continues or handles the error
I/O small simulation
I/O small simulation
Input: P1, P2, P3
Resource/state: limited
Rule: apply the I/O policy step by step
Output: show which process runs, waits, completes, or is denied
Always write the before-state and after-state for each step.
Before you move on
I/O Management in OS DMA, Device Drivers, Scheduling Mastery Check
4 checks
Trace one read request through the API, driver, controller, interrupt, and completed buffer.
A device driver is software that provides a standard interface between the OS and a specific hardware device.
It translates generic OS I/O requests into device-specific commands.