Input/Output Management
1. What is Input/Output Management?
Input/Output (I/O) management is the part of the operating system responsible for controlling, coordinating, and managing communication between the CPU/memory and I/O devices.
Examples of I/O devices:
Input devices
- Keyboard
- Mouse
- Scanner
- Microphone
- Camera
- Sensors
Output devices
- Monitor
- Printer
- Speaker
- Actuator
Storage I/O devices
- HDD
- SSD
- USB drive
- Memory card
Simple structure:
User ↓ Application ↓ Operating System ↓ I/O Subsystem ↓ Device Controller ↓ Device / Hardware
2. What Does I/O Mean?
Input
Data enters the computer.
Keyboard ↓ Computer
Example:
You type: Hello ↓ Keyboard ↓ Operating System ↓ Application
Output
Data leaves the computer.
Computer ↓ Monitor
Example:
Application ↓ Operating System ↓ Display ↓ Monitor
3. Why Does the OS Need I/O Management?
Different hardware devices work differently.
For example:
Keyboard → slow SSD → fast Printer → very slow Network → variable CPU → extremely fast
If every application had to understand the exact hardware details, programming would become extremely complicated.
The OS provides a common interface.
Application ↓ Standard I/O Interface ↓ Operating System ↓ Device Driver ↓ Hardware
So:
The OS hides hardware-specific details from applications.
4. Main Responsibilities of I/O Management
The OS manages:
I/O Management │ ├── Device communication ├── Device drivers ├── Device allocation ├── I/O scheduling ├── Buffering ├── Caching ├── Spooling ├── Interrupts ├── DMA ├── Error handling ├── Protection └── Synchronization
5. I/O Hardware Components
A basic I/O system contains:
CPU │ ↓ I/O Controller │ ↓ Device
Let's understand the components.
6. I/O Device
An I/O device is hardware used to communicate with the computer or transfer data.
Examples:
Input: Keyboard Mouse Camera Output: Monitor Printer Speaker Storage: SSD HDD USB Communication: Wi-Fi Ethernet Bluetooth
7. Device Controller
A device controller is hardware that controls a particular device or group of devices and provides an interface between the device and the CPU/system bus.
Conceptually:
CPU ↓ Controller ↓ Device
For example:
CPU ↓ USB Controller ↓ USB Device
The controller may contain:
- control registers
- status registers
- data registers
- internal buffers
- device-specific logic
8. Device Registers
A controller commonly exposes registers used by software.
Data register
Contains data being transferred.
Data Register ↓ Data
Status register
Contains device state.
For example:
READY BUSY ERROR DONE
Control/command register
Used to tell the device/controller what operation to perform.
Example:
READ WRITE START STOP
Simplified:
Controller ├── Data Register ├── Status Register └── Control Register
9. Device Driver
A device driver is software that allows the operating system to communicate with a specific hardware device or device class.
Architecture:
Application ↓ Operating System ↓ Device Driver ↓ Device Controller ↓ Hardware
The driver translates generic OS requests into device-specific operations.
10. Example of a Device Driver
Suppose you print a document.
Word Processor ↓ OS printing subsystem ↓ Printer Driver ↓ Printer Controller ↓ Printer
The application doesn't need to know the printer's internal hardware commands.
11. Device-Independent I/O
Operating systems try to provide a device-independent interface.
For example, an application may perform a generic:
read() write()
operation.
The OS and driver handle the hardware-specific details.
This means:
Application ↓ Generic I/O API ↓ OS ↓ Specific Driver ↓ Specific Hardware
12. I/O System Call
Applications normally don't directly control hardware.
They request OS services.
Examples in Unix/Linux include:
open() read() write() close() ioctl()
Example:
Application ↓ read() ↓ System Call ↓ Kernel ↓ Driver ↓ Device
13. I/O Operations
The major operations are:
Open
Prepare a device/file for access.
open()
Read
Get data from a device.
read()
Write
Send data to a device.
write()
Close
Release the resource.
close()
14. I/O Management Architecture
A simplified Linux-like model:
┌───────────────────────┐ │ Application │ └───────────┬───────────┘ ↓ ┌───────────────────────┐ │ System Calls │ └───────────┬───────────┘ ↓ ┌───────────────────────┐ │ Kernel I/O │ │ Subsystem │ └───────────┬───────────┘ ↓ ┌───────────────────────┐ │ Device Driver │ └───────────┬───────────┘ ↓ ┌───────────────────────┐ │ Device Controller │ └───────────┬───────────┘ ↓ ┌───────────────────────┐ │ Device │ └───────────────────────┘
15. I/O Techniques
There are several ways the CPU can communicate with I/O devices.
The major techniques are:
I/O Techniques │ ├── Programmed I/O / Polling ├── Interrupt-Driven I/O └── DMA
16. Programmed I/O
In programmed I/O, the CPU repeatedly checks the device status.
This is commonly called polling.
Example:
CPU ↓ Is device ready? ↓ No ↓ Check again ↓ No ↓ Check again ↓ Yes ↓ Transfer data
17. Polling Example
Suppose the CPU wants data from a keyboard.
CPU: "Is data available?" Keyboard: "No" CPU: "Is data available?" Keyboard: "No" CPU: "Is data available?" Keyboard: "Yes!" CPU: "Read data."
The CPU spends time checking.
18. Advantages of Polling
- Simple
- Easy to implement
- Predictable for some simple systems
19. Disadvantages of Polling
- Wastes CPU time
- Repeated checking
- Inefficient for slow devices
- CPU cannot do useful work while continuously polling
Memory trick:
Polling = CPU keeps asking.
20. Interrupt-Driven I/O
Instead of the CPU continuously checking the device, the device can notify the CPU when attention is needed.
CPU │ │ Continue other work ↓ Device │ │ Operation complete ↓ Interrupt │ ↓ CPU
21. Example of Interrupt
Suppose a keyboard receives a key press.
Instead of:
CPU → Is key pressed? CPU → Is key pressed? CPU → Is key pressed?
the keyboard/controller can generate:
Keyboard ↓ Interrupt ↓ CPU ↓ Interrupt Handler ↓ Read key
22. Interrupt Service Routine
When an interrupt occurs, the OS executes an Interrupt Service Routine (ISR) or interrupt handler.
Simplified flow:
Device ↓ Interrupt ↓ CPU ↓ Save current execution state ↓ Run interrupt handler ↓ Handle I/O event ↓ Restore execution ↓ Continue previous work
23. Advantages of Interrupt-Driven I/O
- CPU doesn't continuously poll
- Better CPU utilization
- Good for asynchronous events
- Efficient for many devices
24. Disadvantages
- Interrupt handling has overhead
- Too many interrupts can overload the CPU
- More complex than polling
Memory trick:
Interrupt = Device calls CPU.
25. DMA — Direct Memory Access
DMA allows a device/controller to transfer data directly between the device and main memory with minimal CPU involvement.
Without DMA:
Device ↓ CPU ↓ RAM
With DMA:
Device ↓ DMA Controller ↓ RAM
The CPU mainly sets up the transfer and handles completion/errors.
26. DMA Example
Suppose a network card receives a large packet stream.
Without DMA:
Network ↓ CPU ↓ RAM
The CPU would have to handle much of the data movement.
With DMA:
Network ↓ Network Controller ↓ DMA ↓ RAM
The CPU can do other work while the transfer occurs.
27. DMA Working
Typical sequence:
1. CPU configures DMA ↓ 2. CPU specifies: - source - destination - amount of data ↓ 3. DMA performs transfer ↓ 4. Transfer completes ↓ 5. DMA/device interrupts CPU ↓ 6. OS handles completion
28. Advantages of DMA
- Reduces CPU involvement
- Efficient for large data transfers
- Improves overall system performance
- Useful for disks, network interfaces, audio/video, etc.
29. Disadvantages of DMA
- More hardware complexity
- DMA and CPU may compete for memory/bus access
- Requires careful coordination and protection
Memory trick:
DMA = Device ↔ RAM directly
30. Polling vs Interrupt vs DMA
| Feature | Polling | Interrupt | DMA |
|---|---|---|---|
| CPU constantly checks? | Yes | No | No |
| CPU data movement involvement | High | Moderate | Low |
| Efficiency | Low for slow devices | Good | Excellent for large transfers |
| Complexity | Low | Medium | Higher |
| Best use | Simple/control tasks | Events/small transfers | Large data transfers |
31. Buffering
Buffering means temporarily storing data in memory while it is being transferred between components operating at different speeds.
Example:
Fast Producer ↓ Buffer ↓ Slow Consumer
32. Why Buffering Is Needed
Suppose:
CPU → Very Fast Printer → Slow
If the CPU had to wait for the printer after every small piece of data, performance would be poor.
Instead:
CPU ↓ Buffer ↓ Printer
The CPU can continue working while the printer consumes the buffered data.
33. Types of Buffering
Single Buffer
Device → [Buffer] → Application
One buffer is used.
Double Buffering
Two buffers are used.
Buffer A → being processed Buffer B → being filled
Then they switch.
Time 1: A → Process B → Fill Time 2: A → Fill B → Process
This improves continuous data processing.
34. Caching
Caching stores frequently/recently used data for faster access.
Example:
Application ↓ Cache ↓ Device
If data is already in cache:
Request ↓ Cache Hit ↓ Fast response
Otherwise:
Request ↓ Cache Miss ↓ Device
35. Buffering vs Caching
| Buffering | Caching |
|---|---|
| Temporary transfer area | Stores reusable data |
| Handles speed mismatch | Improves repeated access |
| Focuses on data movement | Focuses on faster access |
| Example: printer buffer | Example: disk cache |
Memory trick:
Buffer = smooth transfer
Cache = fast reuse
36. Spooling
Spooling = Simultaneous Peripheral Operations On-Line
Spooling stores jobs in a queue, usually on storage, so a slow device can process them one at a time.
The classic example is printing.
Suppose three users print:
User A → Print Job A User B → Print Job B User C → Print Job C
Instead of all trying to control the printer simultaneously:
Print Queue ┌───────────┐ │ Job A │ │ Job B │ │ Job C │ └─────┬─────┘ ↓ Printer
The printer processes them sequentially.
37. Why Spooling?
Printers are slow compared with CPUs.
Without spooling:
Application ↓ Printer ↓ Wait...
With spooling:
Application ↓ Spool/Queue ↓ Continue working Spooler ↓ Printer
38. Buffering vs Spooling
| Buffering | Spooling |
|---|---|
| Usually memory-based temporary storage | Often uses disk/storage as a queue |
| Handles transfer speed mismatch | Queues jobs for a shared slow device |
| Smaller data chunks often involved | Often complete jobs |
| Example: I/O buffer | Example: print queue |
39. Synchronous I/O
In synchronous I/O, the application waits for the I/O operation to complete before continuing that operation.
Example:
Application ↓ read() ↓ WAIT ↓ Data available ↓ Continue
40. Asynchronous I/O
In asynchronous I/O, the application can continue doing other work while the I/O operation proceeds.
Application ↓ Start I/O ↓ Continue other work ↓ I/O completes ↓ Notification/completion
41. Synchronous vs Asynchronous I/O
| Feature | Synchronous | Asynchronous |
|---|---|---|
| Application waits? | Usually yes for completion | No |
| Simplicity | Easier | More complex |
| Parallel I/O/work | Lower | Higher |
| Responsiveness | Can be lower | Often better |
| Example | Blocking read | Async network/file I/O |
42. Blocking vs Non-Blocking I/O
These terms are related but not exactly identical to synchronous/asynchronous I/O.
Blocking
A call may wait until the requested operation can proceed.
read() ↓ WAIT ↓ Data
Non-blocking
The call returns without waiting for the operation to become ready.
read() ↓ Not ready ↓ Return immediately
The application can then perform other work or check later.
43. I/O Scheduling
When multiple I/O requests are waiting, the OS may schedule them.
For example:
Requests: Disk A Disk B Network USB Printer
The OS determines:
Which request? When? In what order?
For HDDs, disk scheduling algorithms such as:
FCFS SSTF SCAN C-SCAN LOOK C-LOOK
can reduce head movement.
44. Device Allocation
If multiple processes need the same device, the OS must coordinate access.
Example:
Process P1 ──┐ Process P2 ──┼── Printer Process P3 ──┘
The OS can ensure:
P1 → Printer P2 → Printer P3 → Printer
through appropriate queuing and synchronization.
45. Error Handling
I/O devices can fail.
Examples:
Disk error Printer out of paper USB disconnected Network failure Device timeout
The OS/driver can:
- detect errors
- report errors
- retry operations
- reset devices
- mark failures
- notify applications
Example:
Application ↓ I/O request ↓ Device ↓ ERROR ↓ Driver/OS ↓ Error handling ↓ Application notified
46. I/O Protection
Applications should not be allowed to directly control hardware arbitrarily.
Otherwise a malicious or buggy program could:
Directly access disk Directly access device registers Interfere with other processes Corrupt system data
Therefore:
User Application ↓ System Call ↓ Kernel ↓ Driver ↓ Hardware
This provides controlled access.
47. Memory-Mapped I/O
In memory-mapped I/O, device registers are mapped into the processor's address space.
Conceptually:
Address Space 0x0000 ───────── RAM ... 0xF000 ───────── Device Registers
The CPU can access device registers using normal memory-access instructions, subject to the architecture and protection rules.
48. Port-Mapped I/O
Some architectures provide a separate I/O address space.
Conceptually:
CPU ├── Memory Address Space │ └── I/O Address Space
The CPU uses special instructions to access I/O ports.
Memory-mapped I/O is common in modern general-purpose systems, while port-mapped I/O has historically been important on x86.
49. I/O Request Flow
Let's see what happens when an application reads data from a device.
Application ↓ read() ↓ System Call ↓ Kernel I/O subsystem ↓ Device Driver ↓ Device Controller ↓ Device
Then data returns:
Device ↓ Controller ↓ DMA / CPU transfer ↓ Kernel ↓ Application
If the device uses interrupts:
Device ↓ Interrupt ↓ CPU ↓ Interrupt Handler ↓ I/O completion
50. Example: Reading a File From SSD
Suppose:
Application: "Read notes.txt"
Flow:
Application ↓ read() ↓ Kernel ↓ Filesystem ↓ Block layer ↓ SSD driver ↓ SSD controller ↓ NAND flash
Data returns:
NAND ↓ SSD controller ↓ DMA → RAM ↓ Kernel ↓ Application
51. Example: Printing
Application ↓ Print request ↓ OS ↓ Print subsystem ↓ Printer driver ↓ Spooler ↓ Print queue ↓ Printer
This example demonstrates:
- device driver
- spooling
- buffering
- I/O management
- device allocation
52. Example: Keyboard
Key Press ↓ Keyboard controller ↓ Interrupt ↓ CPU ↓ Keyboard driver ↓ OS ↓ Application
This demonstrates:
- interrupt-driven I/O
- device driver
- OS I/O subsystem
53. Example: Large File Transfer
Suppose an SSD needs to transfer 500 MB.
Using DMA:
SSD ↓ Controller ↓ DMA ↓ RAM
The CPU:
1. Configures DMA 2. Continues other work 3. Receives completion interrupt
This is much more efficient than having the CPU manually move every piece of data.
54. Important I/O Concepts Together
I/O Management │ ┌─────────────────┼─────────────────┐ ↓ ↓ ↓ Device Driver Controller │ │ │ └─────────────────┼─────────────────┘ ↓ I/O Methods │ ┌──────────────────┼──────────────────┐ ↓ ↓ ↓ Polling Interrupt DMA │ │ │ └──────────────────┼──────────────────┘ ↓ Data Management │ ┌──────────────────┼──────────────────┐ ↓ ↓ ↓ Buffering Caching Spooling
55. Polling vs Interrupt vs DMA — Very Important
Polling
CPU → Check device CPU → Check device CPU → Check device
CPU keeps asking.
Interrupt
Device → Interrupt → CPU
Device tells CPU.
DMA
Device ↔ RAM ↑ DMA
Data moves with minimal CPU involvement.
🧠 Memory trick
Polling = CPU asks
Interrupt = Device tells
DMA = Device transfers
56. Buffering vs Caching vs Spooling
Another important exam question:
Buffering → Temporary data during transfer Caching → Keep frequently/recently used data for faster reuse Spooling → Queue complete jobs for a shared slow device
Think:
Buffer = Flow
Cache = Speed
Spool = Queue
57. I/O Management vs Device Management
They are related but not exactly the same.
I/O Management
Concerned with:
Data transfer I/O operations Buffering Caching Spooling Scheduling Interrupts DMA
Device Management
Concerned more broadly with:
Device detection Drivers Device allocation Device configuration Device status Device access
The next topic, device management, will focus more specifically on managing the devices themselves.
🧠 Exam Revision
Definition
I/O management is an operating-system function that manages communication and data transfer between the CPU/memory and input/output devices while providing efficient, controlled, and device-independent access to hardware.
Main components
Application ↓ System Call ↓ I/O Subsystem ↓ Device Driver ↓ Controller ↓ Device
Three major I/O techniques
| Technique | Main idea |
|---|---|
| Polling | CPU repeatedly checks device |
| Interrupt | Device notifies CPU |
| DMA | Device transfers data to/from memory with minimal CPU involvement |
Data management
| Technique | Purpose |
|---|---|
| Buffering | Handle speed mismatch |
| Caching | Faster reuse |
| Spooling | Queue jobs for slow/shared devices |
I/O modes
Synchronous → Wait for operation Asynchronous → Continue while operation runs
🧠 One-line memory trick
I/O Management = Control devices → Transfer data → Handle interrupts → Use DMA → Buffer/Cache/Spool → Handle errors.