Module Review
Key Takeaways
- Hardware Interface: CPUs use MMIO (Memory Mapped I/O) to map device registers into physical RAM address space, bypassing the cache. Legacy x86 uses Port I/O.
- Efficiency: Polling burns 100% CPU. Interrupts allow the CPU to sleep while waiting. DMA (Direct Memory Access) offloads data copying from the CPU entirely.
- Disk Scheduling: Algorithms like SCAN/C-SCAN minimize Seek Time (moving the arm) for HDDs. SSDs use simple queues (NVMe) due to parallelism and zero seek cost.
- Buffering: Smoothes out speed mismatches between producers (CPU) and consumers (Devices). Zero Copy techniques (
sendfile,mmap) avoid wasteful CPU-level copies. -
RAID: Combines disks for Speed (Striping/RAID 0), Safety (Mirroring/RAID 1), or Efficiency (Parity/RAID 5).
Module Review: I/O Device Management
[!NOTE] This module explores the core principles of Module Review: I/O Device Management, deriving solutions from first principles and hardware constraints to build world-class, production-ready expertise.
1. Flashcards
What is the difference between Polling and Interrupts?
Polling constantly checks a status flag (burning CPU). Interrupts let the hardware signal the CPU when it's done (freeing CPU for other tasks).
What is DMA?
Direct Memory Access. A specialized controller that can copy data between a device and RAM without CPU intervention (other than setup).
Why is MMIO marked as 'Uncacheable'?
If MMIO writes were cached in L1/L2, they wouldn't reach the device immediately. Reading a status register from Cache would return stale data.
What is the 'Write Hole' in RAID 5?
If power fails during a write, the Data block might be updated but the Parity block isn't (or vice versa), leading to data corruption on rebuild.
How does 'Zero Copy' work?
It avoids copying data from Kernel Space to User Space and back. Instead, it instructs the kernel to copy directly from Disk Buffer to Network Buffer.
Which RAID level provides the best read/write performance but NO redundancy?
RAID 0 (Striping).
2. Cheat Sheet
| Concept | Definition | Pro | Con |
|---|---|---|---|
| MMIO | Maps registers to RAM addresses | fast, efficient | consumes address space |
| Port I/O | Separate address space (0-65535) | simple, isolated | slower, x86 specific |
| DMA | Device writes to RAM directly | Zero CPU usage for copy | complex setup |
| RAID 0 | Striping (A, B) | Max Speed | 0 Redundancy |
| RAID 1 | Mirroring (A, A) | Max Safety | 50% Capacity |
| RAID 5 | Parity (A, B, P) | Efficient Space | Slow Writes |
| SCAN | Elevator Algorithm | Good average seek | Middle tracks favored |
| C-SCAN | Circular Elevator | Uniform wait time | Slightly more seeks |
3. Quick Revision (Interview Prep)
- Interrupt Handling: Hardware asserts IRQ → CPU pauses → Context Switch → IDT Lookup → ISR Execution → EOI → Resume.
- Top Half vs Bottom Half: Interrupts must be fast. Top half does the minimum (Ack). Bottom half does the heavy lifting (Data processing) later.
- NVMe Queues: Modern SSDs have 64K queues with 64K commands each, mapped to CPU cores for lock-free IO.
- Parity Math:
P = A ^ B. If B is lost,B = A ^ P. - Spooling: Using disk as a huge buffer for a slow device (Printers).