Questions
Multiple choice and short answer
Answer each question before expanding. These span all seven lessons of Unit 11.
Question 1
Describe the four components of a typical I/O system: bus, controller, device, and port.
Show answer
The bus (PCI Express, USB, SATA, NVMe) is the communication path that connects the CPU, memory, and device controllers. The controller is the electronic component that operates a device — it interprets commands from the CPU, manages the device's internal state, and signals completion via an interrupt. The device is the physical hardware (disk, keyboard, network interface). A port is a set of registers on the controller that the CPU can read and write to issue commands, read status, and transfer small amounts of data. Ports are either memory-mapped (they appear at fixed physical addresses in the memory space) or I/O-mapped (accessed through a separate I/O address space, as with x86's in and out instructions).
Question 2
Compare polling and interrupt-driven I/O. When is each appropriate?
Show answer
Polling: the CPU repeatedly checks the device's status register until the device is ready. Simple, no interrupt overhead, but wastes CPU cycles when the device is slow. Interrupt-driven I/O: the device raises an interrupt when it needs attention; the CPU runs the device's handler. Frees the CPU for other work, but has interrupt-handling overhead (saving and restoring registers, cache effects, possible scheduling delay). Polling is better when the device is very fast (comparable to the CPU's instruction time), so the interrupt overhead would exceed the cost of just polling — modern network cards and NVMe SSDs use a hybrid approach (poll for a short while, then fall back to interrupts). Interrupt-driven I/O is better for slow devices (keyboard, disk) and for high-latency operations, where the CPU can do useful work while the device is busy.
Question 3
What is DMA, and why is it essential for high-bandwidth devices?
Show answer
DMA (direct memory access) allows a device to transfer data to or from main memory without CPU involvement per byte. The CPU programs the DMA controller with the source, destination, and length; the DMA controller performs the transfer in the background and raises an interrupt when done. It is essential for high-bandwidth devices because at modern data rates (multiple GB/s) the CPU cannot execute a load-store loop for every byte — it would spend all its time on the transfer. DMA reduces the CPU's role to programming the transfer and handling the completion interrupt, freeing the CPU for computation while the transfer proceeds.
Question 4
What is interrupt coalescing, and why is it used?
Show answer
Interrupt coalescing is a technique in which the device controller delays raising an interrupt until several events have accumulated or a timer expires. Without coalescing, a high-rate device (such as a 10 Gb/s network card or a fast NVMe SSD) would generate hundreds of thousands of interrupts per second, and the CPU would spend all its time in interrupt handlers. Coalescing reduces the interrupt rate by batching events, so the CPU handles several events per interrupt. The cost is additional latency: a coalesced interrupt is raised later than an immediate one, which increases the response time for each event. The coalescing parameters (number of events, timer interval) are tuned to balance throughput against latency.
Question 5
What is a device driver, and what role do major and minor numbers play in Linux?
Show answer
A device driver is the kernel module that knows how to communicate with a particular device. It translates the generic operations of the kernel's I/O subsystem (read, write, ioctl, open, close) into the device-specific commands the controller understands. In Linux, character and block devices are identified by a major number and a minor number. The major number selects the driver — it tells the kernel which driver's file_operations structure to use. The minor number selects the specific device the driver manages — for example, one disk controller may manage several disks, and the driver uses the minor number to know which one is being accessed.
Question 6
A disk has 200 cylinders and the request queue is 98, 183, 37, 122, 14, 124, 65, 67, starting at cylinder 53 with the head moving towards higher numbers. Compute the total head movement under FCFS, SSTF, and LOOK.
Show answer
FCFS: serve in order. 53→98→183→37→122→14→124→65→67. Distances: 45 + 85 + 146 + 85 + 108 + 110 + 59 + 2 = 640 cylinders.
SSTF: always serve the closest request. Starting at 53, the closest is 65 (12). Then 67 (2). Then 37 (30). Then 14 (23). Then 98 (84). Then 122 (24). Then 124 (2). Then 183 (59). Total: 12 + 2 + 30 + 23 + 84 + 24 + 2 + 59 = 236 cylinders.
LOOK: the head moves up from 53, serving all higher requests in order, then reverses at the last request (not the last cylinder). Upward: 53→65→67→98→122→124→183 = 130 cylinders. Then reverse and serve the lower requests in decreasing order: 183→37→14 = 169 cylinders. Total: 130 + 169 = 299 cylinders.
Question 7
What is the difference between SCAN and C-SCAN?
Show answer
SCAN (elevator): the head moves in one direction, serving requests as they are encountered, then reverses direction and serves requests in the other direction. The full sweep is to the end of the disk, even if no requests are pending there. C-SCAN (circular SCAN): the head moves in one direction only, serving requests; when it reaches the end of the disk, it returns to the start without serving any requests, and begins the next sweep. The advantage of C-SCAN is more uniform wait times: every request waits at most one full sweep of the disk, whereas in SCAN a request near the middle of the disk may be served either quickly or slowly depending on the direction of the current sweep. The disadvantage is that the return trip is wasted head movement. LOOK and C-LOOK are variants that reverse at the last pending request rather than at the physical end of the disk.
Question 8
Which disk-scheduling algorithm minimises average response time in the short term, and what is its major disadvantage?
Show answer
SSTF (Shortest Seek Time First) minimises head movement in the short term by always serving the request closest to the current head position. Its major disadvantage is starvation: a request far from the head may be repeatedly postponed by a steady stream of requests near the head. A workload with a persistent cluster of requests near the head and occasional requests far away will cause the far requests to wait indefinitely. Most real schedulers use SCAN or C-SCAN (or a deadline-based variant such as Linux's mq-deadline) precisely because they bound the maximum wait time.
Question 9
A RAID 5 array is built from 5 disks of 4 TB each. What is the usable capacity? How many disk failures can it tolerate?
Show answer
RAID 5 uses one disk's worth of parity distributed across all disks, so the usable capacity is (5 − 1) × 4 TB = 16 TB. It tolerates one disk failure. After a failure, the array continues to operate in a degraded state (reads are reconstructed from parity), and the failed disk can be replaced; the array then rebuilds the missing data from parity and the surviving disks. If a second disk fails during the rebuild, the array is lost.
Question 10
What is the "small-write penalty" of RAID 5? Why does it occur?
Show answer
The small-write penalty is the extra I/O cost of a small random write to a RAID 5 array. A logical write of one block requires updating both the data block and the corresponding parity block. Because parity is computed as the XOR of all data blocks in the stripe, updating it requires reading the old data and the old parity, computing the new parity, and writing the new data and the new parity. That is two reads and two writes (or, if the entire stripe is being written, one write to the data and one to the parity). For a workload of small random writes, this fourfold I/O amplification can dominate performance. RAID 6 has an even higher penalty because it maintains two parity blocks. The penalty is why RAID 5 is a poor choice for write-intensive workloads (databases, virtual-machine storage) and why newer RAID levels (RAID 10, RAID-Z) are preferred for those workloads.
Question 11
Compare RAID 0, 1, 5, and 6. For each, give the usable capacity for N disks of size S, the number of failures tolerated, and the primary workload for which it is suited.
Show answer
- RAID 0 (striping): capacity N × S; tolerates 0 failures. Best for workloads that need maximum performance and can tolerate data loss (scratch space, temporary files).
- RAID 1 (mirroring): capacity N/2 × S; tolerates N/2 failures (with a pair of disks, 1 failure; with three-way mirrors, 2). Best for high-reliability workloads with moderate capacity needs (boot volumes, small databases).
- RAID 5 (striping with distributed parity): capacity (N − 1) × S; tolerates 1 failure. Best for read-heavy workloads with large files and sequential access (file servers, media archives).
- RAID 6 (striping with dual parity): capacity (N − 2) × S; tolerates 2 failures. Best for large arrays of high-capacity disks, where the rebuild time is long and the risk of a second failure during rebuild is non-trivial.
Question 12
Why is RAID 10 often preferred over RAID 5 for write-intensive workloads?
Show answer
RAID 10 (a stripe of mirrors) has no parity, so a write simply goes to both members of the relevant mirror pair — no read-modify-write, no parity computation. The write cost is 2× (write to both mirrors), whereas RAID 5 has a 4× cost for small writes (read old data, read old parity, write new data, write new parity). For write-intensive workloads, RAID 10 therefore delivers higher throughput and lower latency. RAID 10 also recovers faster from a disk failure: the failed disk's mirror is simply copied to a spare, with no parity reconstruction. The trade-off is capacity: RAID 10 uses half the disks for mirrors, so it provides only 50% usable capacity, while RAID 5 provides (N−1)/N. For workloads where capacity matters more than write performance, RAID 5 is preferred; for workloads where write performance matters, RAID 10 is the standard choice.
Question 13
Explain the architecture of an SSD. What is the flash translation layer (FTL)?
Show answer
An SSD stores data in NAND flash cells, organised into pages (the unit of read and write, typically 4 KB) and erase blocks (the unit of erase, typically hundreds of KB to a few MB). A page can be written once; to rewrite it, the entire erase block containing it must first be erased. The flash translation layer (FTL) is the firmware layer that hides this constraint from the host. It maps logical block addresses (LBAs) to physical flash pages and maintains the mapping in a table. When a logical block is rewritten, the FTL writes the new data to a fresh page (from a pool of spare pages) and updates the mapping to point at the new page; the old page is marked invalid. The host sees only a fast, overwrite-in-place block device.
Question 14
What is garbage collection in an SSD, and why does it cause the "write cliff"?
Show answer
Garbage collection (GC) is the process by which the FTL reclaims space from erase blocks that contain invalid pages. The FTL selects a block with many invalid pages, copies its remaining valid pages to a fresh block, and erases the original block, returning it to the free pool. GC consumes write bandwidth, so it competes with foreground writes. The write cliff occurs when the drive's free-page pool is exhausted: every new write triggers a GC cycle, so the drive's effective write throughput drops sharply. A drive with plenty of free space (over-provisioning) has more room to schedule GC during idle periods, so the cliff is pushed out. TRIM tells the drive which blocks are no longer in use, allowing the FTL to mark them invalid and GC more efficiently; without TRIM, the drive does not know that a file has been deleted and continues to preserve its pages.
Question 15
What is wear levelling, and why is it necessary for SSDs?
Show answer
Wear levelling is the technique of distributing writes evenly across all erase blocks of a flash device, so that no block is erased many more times than the others. It is necessary because flash cells have a limited number of program-erase cycles (typically 1,000–100,000, depending on the cell type: SLC, MLC, TLC, QLC), and a block that is written more often than others will fail sooner. Wear levelling is implemented by the FTL, which tracks the erase count of each block and prefers blocks with low counts. Dynamic wear levelling distributes writes to new data; static wear levelling also relocates data that has not changed, so that blocks holding read-only data eventually give up their pages to wear-levelling. The combination of spare capacity, over-provisioning, and wear levelling is what allows a modern SSD to survive years of write-heavy use.
Question 16
A hard disk has a 7200 RPM rotational speed, an average seek time of 9 ms, and a transfer rate of 150 MB/s. What is the average time to read a 4 KB block?
Show answer
Average rotational latency = (60 / 7200) / 2 = 8.33 / 2 = 4.17 ms.
Average seek time = 9 ms.
Transfer time = 4 KB / 150 MB/s = 4096 / (150 × 106) ≈ 0.027 ms.
Controller overhead (typical) ≈ 0.1 ms.
Total ≈ 9 + 4.17 + 0.027 + 0.1 ≈ 13.3 ms.
The seek time and rotational latency together account for 99% of the time; the actual data transfer is negligible. This is why disk scheduling (which reduces seek time) matters so much, and why SSDs — with no seek time and no rotational latency — are orders of magnitude faster for small random reads.
Question 17
What is the difference between a block device and a character device in Linux?
Show answer
A block device transfers data in fixed-size blocks and supports random access: the driver can seek to an arbitrary block and read or write it. Disks, SSDs, and RAID arrays are block devices. The kernel's block layer provides caching, read-ahead, and I/O scheduling for block devices. A character device transfers data as a stream of characters (bytes) and typically does not support seeking. Terminals, serial ports, keyboards, and many pseudo-devices are character devices. The distinction is not absolute — some devices expose both interfaces — but it captures the difference in the access pattern: block devices are for storage, character devices are for streams.
Question 18
What is the difference between a "top half" and a "bottom half" of interrupt handling in Linux?
Show answer
The top half is the interrupt handler itself, which runs immediately when the interrupt is delivered. It must be fast and must not sleep (because it runs in interrupt context), so it does only the minimum: acknowledge the interrupt, save any necessary data, and schedule the bottom half (a softirq, tasklet, or workqueue) to do the rest of the work. The bottom half runs later, in a less restricted context (softirq context or process context for workqueues), and can do more work — including, for workqueues, sleeping if necessary. This split keeps interrupt latency low (the top half returns quickly) while still allowing complex work to be done. Network and storage drivers use this pattern extensively.
Question 19
A storage system has a measured 4 KB random-read IOPS of 80,000 and a 4 KB random-write IOPS of 20,000. What does this asymmetry suggest about the underlying device?
Show answer
The asymmetry (reads four times faster than writes) suggests the device is an SSD. On an SSD, reads are fast because the FTL maps the LBA to a physical page and reads it directly. Writes are slower for two reasons: (a) the FTL must write to a fresh page and update the mapping, and (b) garbage collection competes with foreground writes. On a hard disk, the asymmetry between reads and writes is much smaller (both are dominated by seek and rotational latency), so a 4:1 read-to-write ratio strongly suggests flash storage. The ratio can also be affected by the write workload: if the drive is nearly full, the write IOPS will be much lower because GC has less free space to work with.
Question 20
What is the difference between a hard disk's "seek time" and "rotational latency"?
Show answer
Seek time is the time required to move the disk's read/write head to the correct track (cylinder). It depends on the distance the head must travel and the head's acceleration and deceleration; typical values are 3–10 ms. Rotational latency is the additional time required for the desired sector to rotate under the head once the head is on the correct track. It depends on the disk's rotational speed: at 7200 RPM, a full rotation takes 8.33 ms, so the average rotational latency is 4.17 ms. Together they dominate the cost of a disk I/O (the actual data transfer is negligible for small blocks), which is why disk-scheduling algorithms try to minimise head movement and why sequential access is much faster than random access on a hard disk.
Question 21
What is the role of the device controller's status register, and how does the driver use it?
Show answer
The status register tells the driver the current state of the device: whether it is busy, whether it is ready to accept a command, whether an error has occurred, and (for some devices) which specific error. The driver reads the status register before issuing a command (to confirm the device is ready), after the command completes (to check for errors), and in the interrupt handler (to determine why the interrupt was raised). Some devices have separate registers for status and control; others multiplex them. The driver must be careful about the order of reads and writes to the register, because the device may change its state in response to a command.
Question 22
What is the advantage of a "deadline" I/O scheduler over a pure SCAN scheduler?
Show answer
A pure SCAN scheduler optimises total head movement but does not bound the wait time of any particular request: a read request that is far from the head's current position may wait for many sweeps if write requests continue to arrive. A deadline scheduler (such as Linux's mq-deadline) maintains separate read and write queues and associates a deadline with each request. It serves requests in SCAN order by default, but if a request's deadline is about to expire, it is served immediately, out of order. This bounds the maximum latency for any request while still achieving most of SCAN's throughput. Deadline scheduling is important for workloads where read latency is critical (databases, interactive applications) but write throughput also matters (logging, batch jobs).
Question 23
Why does the size of an I/O request affect throughput on both hard disks and SSDs?
Show answer
On a hard disk, a larger request amortises the fixed cost of seek and rotational latency over more data. A 4 KB request that takes 13 ms delivers 0.3 MB/s; a 1 MB request that takes 15 ms delivers 66 MB/s. The seek and rotation are paid once, and the transfer rate of the disk (150 MB/s) becomes the limit. On an SSD, a larger request uses fewer of the FTL's per-request overheads (mapping lookups, command processing) and, for writes, aligns with the page and erase-block granularity of the flash. Small random writes may not align with a page boundary, requiring a read-modify-write of the containing erase block; a large sequential write fills entire pages and blocks and is written at the drive's full bandwidth. This is why both storage types benefit from large, sequential I/O, and why applications that must perform small random I/O use caching and batching to convert the pattern into larger requests.
Question 24
In one or two sentences, state the central design goal of the I/O subsystem and how the kernel's block layer, scheduler, driver, and device divide the responsibility.
Show answer
The central goal is to provide a uniform, high-performance interface to heterogeneous storage devices while achieving fairness and low latency under contention. The block layer provides caching, read-ahead, and the request queue; the I/O scheduler reorders requests to optimise throughput and bound latency; the device driver translates the generic requests into the device's command set; and the device executes the commands with its own internal parallelism, caching, and error recovery. The kernel's role is to coordinate these layers so that each application sees a fast, reliable, and fair abstraction of storage.