Now the star device of persistence: the hard disk drive. File systems are shaped by how disks behave, so we build a model of one first.
The Crux: How To Store And Access Data On Disk
How do modern hard drives store data? What is the interface, how is data laid out and accessed, and how does disk scheduling improve performance?37.1 The Interface
A disk is simply an array of sectors sector The atomic unit of a hard disk: a 512-byte block. Sectors are numbered 0β¦nβ1, forming the disk's address space. Manufacturers guarantee only that a single-sector write is atomic; a larger write interrupted by power loss can leave a partial 'torn write.' defined in ch. 37 β open in glossary β 512-byte blocks numbered 0 to nβ1 (the driveβs address space). You can read or write any sector; file systems often move 4KB (8 sectors) at a time. But the only atomicity guarantee is that a single-sector write completes fully or not at all β a larger write cut short by power loss can leave a partial torn write. And the βunwritten contractβ: nearby blocks are faster to reach than distant ones, and sequential access is far faster than random.
37.2 Basic Geometry
Data lives on a platter platter A circular hard surface (aluminum coated with a thin magnetic layer) that stores bits persistently, even when the drive is off. A disk has one or more platters, each with two surfaces, all bound to a spindle that a motor spins at a fixed rate (RPM). defined in ch. 37 β open in glossary β a circular surface coated in magnetic material, holding bits even when powered off. Platters bind to a spindle spun by a motor at a fixed rate (7,200β15,000 RPM). Each surface holds thousands of concentric tracks track A concentric circle of sectors on a platter surface. A single surface holds many thousands of tightly packed tracks (hundreds fit within a human hair's width). A read/write head, mounted on a movable disk arm (one head per surface), positions over the desired track. defined in ch. 37 β open in glossary (hundreds fit in a hairβs width); a read/write head on a movable arm (one per surface) positions over the target track.
37.3 A Simple Disk Drive
Servicing a request takes three steps β walk through a real one:
1A single track
A platter is a magnetic surface spun on a spindle at a fixed rate (RPM). Data sits in concentric tracks; here one track of 12 sectors (0β11), each a 512-byte block.
Two costs dominate. The rotational delay rotational delay The time a disk spends waiting for the desired sector to rotate under the head. On average it is about half of a full rotation (R/2). Together with seek time, one of the two dominant costs of a disk I/O. defined in ch. 37 β open in glossary is the wait for the sector to spin under the head (avg β R/2). The seek time seek time The time to move the disk arm so the head is over the target track. It has phases β acceleration, coasting, deceleration, and settling (the settling alone is 0.5β2 ms). Along with rotation, one of the most costly disk operations; the AVERAGE seek is about one-third of a full-stroke seek. defined in ch. 37 β open in glossary is moving the arm to the right track β and itβs not instant: the arm must accelerate, coast, decelerate, and carefully settle (0.5β2 ms) onto the track. Then the transfer completes the I/O.
A few more realities
Real drives add cleverness. Track skew track skew An angular offset in sector numbering between adjacent tracks, arranged so that after switching tracks a sequential read finds the next block just arriving under the head β rather than having just missed it and paying nearly a full rotation. defined in ch. 37 β open in glossary shifts the sector numbering between adjacent tracks so that after a track switch the next sequential block is just arriving β not just missed (which would cost a whole rotation):
Track skew: block 12 (inner) is offset from block 0 (outer) so it arrives just after the head finishes switching tracks.
Two more: a multi-zoned disk multi-zoned disk A disk organized into zones (consecutive sets of tracks) where outer zones pack MORE sectors per track than inner zones β because there is simply more room on the outer, longer tracks. Each zone has a fixed number of sectors per track. defined in ch. 37 β open in glossary packs more sectors on outer tracks (thereβs more room out there), grouping tracks into zones with a fixed sectors-per-track. And every drive has a track buffer track buffer A small memory inside the drive (a disk cache, historically the track buffer, usually 8β16 MB) that holds data read from or written to the platters β e.g. on reading one sector the drive may cache the whole track to answer later same-track requests quickly. defined in ch. 37 β open in glossary β a small (8β16 MB) internal cache; e.g. on a read it may pull in the whole track to answer later same-track requests fast. That cache forces a write policy choice β write-back caching write-back caching A disk-cache write policy (a.k.a. immediate reporting) that acknowledges a write as soon as the data reaches the drive's memory β making the drive appear faster, but risking correctness if a crash occurs before the data hits the platter (dangerous when order matters, e.g. journaling). The safe alternative is write-through, which acks only after the data is actually on disk. defined in ch. 37 β open in glossary vs write-through:
| acknowledges a write⦠| trade-off | |
|---|---|---|
| Write-back (immediate) | as soon as the data is in the drive's memory | appears faster β but risky |
| Write-through | only after the data reaches the platter | safe, but slower |
With this model of where time goes on a disk, we can now put numbers to it.
Check yourself: disk anatomy
1.What is a sector, and what atomicity does the disk guarantee?
2.A disk request's service time is the sum of which three components?
3.What is the rotational delay, and what is it on average?
4.Why isn't a seek instantaneous?
5.What problem does track skew solve?
6.The drive's track buffer forces a write policy choice. What's the trade-off between write-back and write-through?