ECE344 Fall 2026 (Sec 1) Lec 22 - Disks
Overview
Jon Eyolfson explains how operating systems move disk blocks through caches, device drivers, shared request queues, DMA, and interrupts, including how xv6 uses paravirtualized virtio devices. He then compares NAND SSD constraints and RAID layouts, showing how RAID 0, 1, 5, 6, and 10 trade capacity and performance against tolerance for disk failures.
Key takeaways
- A disk read that misses the buffer cache becomes an asynchronous device request: the process sleeps, the device transfers data with DMA, and an interrupt wakes the process on completion.
- The check-before-sleep sequence for disk completion must be protected by a lock, or an interrupt can arrive before the process is registered as waiting and cause a lost wakeup.
- NAND SSDs erase whole blocks but write pages, so overwriting data requires garbage collection; TRIM lets the operating system identify pages the SSD can reclaim.
- RAID 5 can reconstruct one failed disk using distributed XOR parity, but a second failure before rebuild can lose data; RAID 6 adds a second parity value to tolerate two failures.
- RAID 10 stripes across mirrored pairs, combining parallel access with straightforward mirror rebuilds, but it cannot survive the loss of both drives in the same pair.
Chapters
- Linux exposes hardware under /dev, with character devices such as terminals and block devices such as disks.
- Block devices provide random access by numbered blocks, while disks physically read and write whole sectors, commonly 512 bytes or 4 KB.
- The kernel groups sectors into its own block sizes; changing one byte can require reading and rewriting an entire block.
- The lsblk command lists block devices, and /sys/block exposes details such as sector size.
- A buffer cache keeps recently used disk blocks in memory so cache hits avoid slow disk access.
- Device drivers communicate with hardware through mapped registers and shared-memory request and completion queues, often organized as circular buffers.
- With direct memory access (DMA), the device transfers data to or from RAM while the CPU runs other work; the kernel must provide suitable physical addresses.
- When a request completes, the device interrupts the kernel, which wakes the waiting process; checking completion and going to sleep must use one lock to prevent a lost wakeup.
- In xv6, KVM runs the guest kernel, so the guest's apparent disk hardware is provided by the hypervisor rather than a physical device.
- Trapping and emulating every hardware-register access would be expensive, so xv6 uses paravirtualization.
- The virtio driver places requests in shared memory and notifies the hypervisor, which accesses a host-side disk file and interrupts the guest when the operation finishes.
- NAND SSDs read and write pages, typically around 4 KB, but erase larger blocks containing roughly 128 or 256 pages.
- A page cannot be overwritten until its block is erased, so updating data can require writing it elsewhere and marking the old page obsolete.
- Typical access figures given are about 10 microseconds to read a page, 100 microseconds to write one, and 1 millisecond to erase a block.
- The operating system can send TRIM information about unused pages, allowing the SSD to reclaim them and prepare erased blocks in the background.
- RAID 0 stripes data across disks, potentially scaling throughput with the number of disks, but any disk failure can destroy the array's data.
- RAID 1 mirrors data across disks, allowing the array to survive failures as long as one copy remains.
- Mirroring consumes duplicate capacity; reads can be distributed across copies, while writes must update each mirror.
- RAID 0 favors speed over reliability, while RAID 1 favors redundancy over usable capacity.
- RAID 4 stripes data across disks and stores XOR parity on a dedicated disk, allowing reconstruction after any one disk fails.
- With four 2 TB disks in RAID 4, 6 TB is available for data and 2 TB for parity.
- The dedicated parity disk becomes a write bottleneck because every changed data stripe requires a parity update.
- RAID 5 distributes parity across the disks to avoid concentrating parity writes on a single drive.
- RAID 5 tolerates one failed disk, but a second failure before rebuilding can cause data loss; Eyolfson recounts losing two drives in his thesis array.
- Replacing a failed RAID 5 disk promptly matters because rebuilding places heavy read demands on the remaining drives.
- RAID 6 stores two distinct parity values, allowing recovery from any two disk failures.
- RAID 6 uses the capacity of two disks for parity and has more complex, slower writes than single-parity RAID 5.
- RAID 0+1 mirrors two striped arrays, but a disk failure can disable one whole stripe set when the layers operate independently.
- RAID 10 stripes across mirrored pairs, so it can survive one failure in each pair and simplifies recovery by copying from the surviving mirror.
- RAID 10's failure tolerance depends on which drives fail; losing both drives in one mirrored pair loses data.
- Rebuilding a mirror copies data directly from its surviving partner, unlike parity RAID, which must reconstruct data from other disks.
- Disk drivers and devices exchange requests through shared-memory queues, often using DMA and completion interrupts.
- SSD TRIM support helps identify unused pages so the drive can reclaim space and maintain performance.
- RAID layouts combine multiple disks to trade usable capacity, throughput, and protection against drive failures.
Transcript excerpt
2:39 Oops. >> All righty. We are on our last topic now. So, at the beginning, we had three major concepts, virtualization, which we've well, we haven't quite beat to death, but we've used a lot. And second one was concurrency, and the third one was persistence. So, we get to start talking about persistence today and start talking about disks. So, going back to test one, a process blocking and read uses no CPU. Test one, remember I asked that to you? Yeah, the kernel puts it to sleep, runs something else. It isn't runnable, so the scheduler would completely skip over
3:27 it. So, how does exactly does the kernel know that data is there and wake it up right away? So, today we get to talk about how the kernel actually talks to the disk at a high level, and then what's inside the disk and how to use a lot of them. So, a disk is something called a block device. So, lecture two, everything I told you everything gets represented as a file. So, on Linux at least and also Mac OS, there's this dash dev, and you can there's a whole bunch of names. If If NVMe zero whatever on my machine, that's my whole disk represented as one file. So devices are all files in this dash dev and come in two kinds. There's a character device, which is a stream of
4:15 bytes in order. So your terminal is an example of a terminal or as a character device or dev null that just produces a whole bunch of zero bytes. And then a block device stores fixed size blocks. So just what's the fixed size blocks? How big are they? Depends on the device, but they operate in blocks. Each block gets assigned a number.
This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.
In this course
Related notes
Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, Jon Eyolfson.