Registers, caches and RAM are fast, but they all forget everything when the power goes off, and RAM is expensive per gigabyte. At the bottom of the memory hierarchy we need storage that is non-volatile, huge and cheap. This is secondary storage: the hard disk drive (HDD) and the solid-state drive (SSD). It holds your files, your programs before they run, and the pages that virtual memory has moved out of RAM (see Virtual Memory & TLB (Hardware View)).
In this chapter we look inside both devices: the geometry of a magnetic disk and how to calculate its capacity and access time (a guaranteed GATE topic), how sectors are addressed, how flash memory works and why SSDs need a Flash Translation Layer, and how RAID combines several disks. How the OS orders disk requests (disk scheduling) is covered in the Operating Systems tutorial; here we focus on the hardware.
Where Secondary Storage Fits
| Level | Typical access time | Volatile? |
|---|---|---|
| Registers / L1 cache | Under 1 ns to about 1 ns | Yes |
| Main memory (DRAM) | About 50-100 ns | Yes |
| SSD (NAND flash) | Tens of microseconds | No |
| Hard disk | Several milliseconds | No |
A random hard-disk access is roughly 100,000 times slower than a DRAM access. That single fact explains why page faults are so expensive, why SSDs transformed computing, and why so much effort goes into reading disks sequentially.
Inside a Magnetic Disk
A hard disk stores bits as tiny magnetised regions on spinning metal or glass platters coated with magnetic material.
spindle (rotates at e.g. 7200 RPM)
│
══════════╪══════════ platter 0 ← top surface (head 0)
│ ← bottom surface (head 1)
══════════╪══════════ platter 1 ← top surface (head 2)
│ ← bottom surface (head 3)
│
actuator arm ──► all heads move together, in and out
Top view of one surface:
.-""""""-.
.' .----. '. ring = TRACK
/ / () \ \ pie slice of a track = SECTOR
\ \ / / same track on all surfaces = CYLINDER
'. '----' .'
'-......-'| Term | Meaning |
|---|---|
| Platter | A disk; usually both of its surfaces are used |
| Surface / head | Each recording surface has its own read/write head |
| Track | One concentric circle on a surface |
| Sector | The smallest addressable unit on a track, traditionally 512 bytes; modern drives use 4096-byte physical sectors ("Advanced Format") |
| Cylinder | The set of tracks at the same arm position on all surfaces; reading a whole cylinder needs no arm movement |
All heads are mounted on one arm assembly, so they all sit over the same cylinder. Only one head usually transfers data at a time.
Zoned Bit Recording
Outer tracks are longer than inner tracks. Early disks stored the same number of sectors on every track, wasting the outer tracks. Modern disks use zoned bit recording (ZBR): tracks are grouped into zones, and outer zones hold more sectors per track. Since the disk spins at a constant speed, outer zones also transfer data faster. GATE problems usually ignore this and assume a fixed number of sectors per track.
Disk Capacity
Capacity = surfaces × tracks per surface × sectors per track × bytes per sector
Worked Example 1
A disk has 16 surfaces, 512 tracks per surface, 512 sectors per track and 1 KB per sector. Find its capacity and the number of bits needed to address a sector.
Capacity = 16 × 512 × 512 × 1024 B
= 2^4 × 2^9 × 2^9 × 2^10 = 2^32 B = 4 GiB
Number of sectors = 16 × 512 × 512 = 2^22 = 4,194,304
Sector address = 22 bits
= 9 bits (cylinder/track) + 4 bits (surface) + 9 bits (sector)Disk manufacturers use decimal units (1 GB = 109 bytes), while operating systems often show binary units (1 GiB = 230 bytes). That is why a "1 TB" disk shows up as about 931 GiB.
Disk Access Time
Reading a sector needs three mechanical steps, plus a little electronics:
Seek time: move the arm to the right cylinder. Typically a few milliseconds on average; much less between adjacent tracks.
Rotational latency: wait for the right sector to spin under the head. On average this is half a rotation, because the sector could be anywhere.
Transfer time: the sector passes under the head. Time = (bytes to read) ÷ (transfer rate).
Controller overhead: command processing, sometimes given in questions.
Access time = seek time + rotational latency + transfer time (+ controller overhead)
Time for one rotation = 60 / RPM seconds. Average rotational latency = ½ × rotation time.
Transfer rate = bytes per track × rotations per second.
| Speed (RPM) | One rotation | Average rotational latency |
|---|---|---|
| 5400 | 11.11 ms | 5.56 ms |
| 7200 | 8.33 ms | 4.17 ms |
| 15000 | 4 ms | 2 ms |
Worked Example 2: One Sector
A disk spins at 7200 RPM, has an average seek time of 4 ms, 1000 sectors per track and 512-byte sectors. Controller overhead is 0.2 ms. Find the average time to read one sector and the sustained transfer rate.
Rotation time = 60 / 7200 s = 8.333 ms
Avg rotational delay = 8.333 / 2 = 4.167 ms
Transfer of 1 sector = 8.333 ms / 1000 = 0.00833 ms
Access time = 4 + 4.167 + 0.00833 + 0.2 ≈ 8.375 ms
Transfer rate = 1000 × 512 B × (7200 / 60) rotations/s
= 512,000 × 120 = 61,440,000 B/s = 61.44 MB/sLook at where the time goes: about 8.17 ms is spent moving the arm and waiting for rotation, and only 0.008 ms actually reading data. Only about 0.1% of a random access is spent actually transferring data.
Worked Example 3: Sequential vs Random
Using the same disk, read a 4 MiB file (a) stored contiguously and (b) scattered randomly, one sector at a time. Ignore the controller overhead and track-to-track switching time.
Sectors = 4 × 2^20 / 512 = 8192
(a) Contiguous: one seek + one rotational delay, then stream
= 4 + 4.167 + 8192 × 0.00833 ms
= 4 + 4.167 + 68.27 ≈ 76.4 ms
(b) Random: every sector pays seek + rotational delay
= 8192 × (4 + 4.167 + 0.00833) ms
≈ 66,970 ms ≈ 67 secondsSame disk, same data, almost 900 times slower. This is why file systems try hard to keep files contiguous, why databases favour sequential logs, and why disk-scheduling algorithms try to reduce arm movement.
Addressing Sectors: CHS and LBA
Old systems addressed a sector by its Cylinder, Head, Sector (CHS) coordinates. Modern drives hide their real geometry and expose a simple linear array of blocks numbered 0, 1, 2, ..., called Logical Block Addressing (LBA). The drive's own controller maps each LBA to a physical location, and can quietly remap bad sectors to spare ones.
The standard conversion (sectors are numbered from 1 in CHS, LBAs from 0) is:
LBA = (C × heads per cylinder + H) × sectors per track + (S − 1)
Example: 16 heads, 63 sectors per track. CHS (2, 3, 5) gives LBA = (2 × 16 + 3) × 63 + 4 = 35 × 63 + 4 = 2209.
Going back: C = 2209 div (16 × 63) = 2209 div 1008 = 2, remainder 193; H = 193 div 63 = 3, remainder 4; S = 4 + 1 = 5. The ordering (cylinder outermost, then head, then sector) means consecutive LBAs fill a whole cylinder before the arm has to move.
Solid-State Drives (SSDs)
An SSD has no moving parts. It stores data in NAND flash memory: each cell is a transistor with a floating gate (or a charge-trap layer) that can hold electric charge for years without power. The amount of trapped charge shifts the transistor's threshold voltage, and that voltage encodes the bits.
Bits per Cell
| Type | Bits per cell | Voltage levels | Speed and endurance | Cost per GB |
|---|---|---|---|---|
| SLC | 1 | 2 | Fastest, highest endurance | Highest |
| MLC | 2 | 4 | Fast, good endurance | High |
| TLC | 3 | 8 | Medium; most consumer SSDs | Low |
| QLC | 4 | 16 | Slower writes, lowest endurance | Lowest |
More bits per cell means more voltage levels squeezed into the same range, so the cell must be programmed and read more carefully (slower) and it tolerates fewer program/erase cycles before levels can no longer be told apart. Endurance falls roughly from tens of thousands of cycles for SLC to around a thousand or fewer for QLC, depending on the manufacturing process.
The Three Rules of NAND Flash
Read and program (write) work on pages, typically 4 to 16 KB.
Erase works only on whole blocks, and a block contains many pages (often hundreds of pages, several megabytes).
A page cannot be overwritten in place. It must be erased (as part of its whole block) before it can be programmed again, and each block survives only a limited number of program/erase (P/E) cycles.
Flash block (erase unit)
+--------+--------+--------+--------+-----+--------+
| page 0 | page 1 | page 2 | page 3 | ... | page N | ← program unit = page
+--------+--------+--------+--------+-----+--------+
States of a page: free (erased) → valid (holds live data) → invalid (stale)The mismatch is obvious: the OS wants to overwrite a 4 KB block in place, but flash can only erase in units of megabytes. Rewriting a whole flash block for every small update would be very slow and would wear out the flash quickly.
The Flash Translation Layer (FTL)
The SSD's controller runs firmware called the Flash Translation Layer. It makes flash look like an ordinary disk with overwritable LBAs:
Out-of-place updates and address mapping: a write to LBA x goes to a fresh, already-erased page. The FTL updates its mapping table (LBA → physical page) and marks the old page invalid. This is the same idea as a page table in virtual memory.
Garbage collection (GC): when free pages run low, the FTL picks a block with many invalid pages, copies its remaining valid pages to another block, and erases it.
Wear levelling: spreads writes (and erases) evenly over all blocks so that no block wears out early, including occasionally moving rarely changed ("cold") data.
Bad-block management and ECC: strong error-correcting codes fix bit errors; failing blocks are retired.
Over-provisioning: the drive keeps some capacity hidden from the user as spare space, which makes garbage collection cheaper.
Write Amplification
Write amplification (WA) = data written to the flash ÷ data written by the host. Ideally 1; garbage collection makes it larger.
Example: a block of 64 pages is chosen for garbage collection while 48 of its pages are still valid. The FTL copies the 48 valid pages elsewhere and erases the block, gaining 16 free pages. When the host fills those 16 pages, the flash has actually written 16 + 48 = 64 pages:
WA = (16 host pages + 48 copied pages) / 16 host pages = 64 / 16 = 4Choosing victim blocks with few valid pages, keeping more over-provisioned space, and the TRIM command all lower WA. TRIM lets the OS tell the SSD which LBAs belong to deleted files, so the FTL can mark those pages invalid instead of carefully copying dead data during GC.
SSD Interfaces: SATA vs NVMe
| Aspect | SATA (AHCI) | NVMe over PCIe |
|---|---|---|
| Originally designed for | Hard disks | Flash / non-volatile memory |
| Link | SATA III: 6 Gb/s with 8b/10b encoding ≈ 600 MB/s maximum | PCIe lanes, e.g. PCIe 4.0 ×4 drives reach about 7 GB/s |
| Command queues | 1 queue, up to 32 commands (NCQ) | Up to 65,535 I/O queues, each up to 64K commands (spec maximum) |
| Typical use | 2.5-inch SSDs, HDDs | M.2 and U.2 SSDs |
Many queues let each CPU core submit I/O on its own queue without locking, which suits multi-core processors and the high parallelism inside an SSD (many flash chips working at once). Real controllers implement far fewer queues than the specification maximum, but still many more than AHCI's one.
HDD vs SSD
| Aspect | Hard disk (HDD) | Solid-state drive (SSD) |
|---|---|---|
| Storage medium | Magnetic platters | NAND flash chips |
| Moving parts | Yes (spindle, arm) | None |
| Random access latency | Several milliseconds (seek + rotation) | Tens of microseconds |
| Sequential throughput | Roughly 100-300 MB/s | Up to about 600 MB/s (SATA) or several GB/s (NVMe) |
| Random I/O per second | Around a hundred to a few hundred | Tens of thousands to over a million |
| Overwrite in place | Yes | No (erase before write, FTL needed) |
| Wear-out | Mechanical wear | Limited P/E cycles per block |
| Shock, noise, power | Sensitive, audible, more power | Robust, silent, less power |
| Cost per GB | Lower | Higher |
| Best for | Bulk storage, backups, archives | OS, applications, databases, laptops |
Notice that for an SSD the gap between random and sequential access is far smaller than for an HDD, because there is no seek or rotational delay. Algorithms designed around "avoid seeks" matter much less on flash; "avoid small random writes" matters more.
RAID: Combining Disks
RAID (Redundant Array of Independent Disks) combines several drives to get more speed, more reliability, or both. The key techniques are striping (spreading consecutive blocks across disks so they work in parallel), mirroring (keeping identical copies) and parity (storing the XOR of data blocks so a lost block can be rebuilt).
| Level | Technique | Usable capacity (n disks) | Disk failures tolerated | Notes |
|---|---|---|---|---|
| RAID 0 | Striping only | n | 0 | Fastest, no redundancy |
| RAID 1 | Mirroring | n / 2 (for pairs) | 1 per mirrored pair | Simple, fast reads |
| RAID 5 | Striping + distributed parity | n − 1 | 1 | Each small write updates data and parity |
| RAID 6 | Striping + two independent parities | n − 2 | 2 | Safer for large disks with long rebuilds |
| RAID 10 | Mirrored pairs, then striped | n / 2 | At least 1 (1 per pair) | Good speed and redundancy |
Example: six 4 TB disks give 24 TB in RAID 0, 20 TB in RAID 5, 16 TB in RAID 6 and 12 TB in RAID 10. Why does parity work? If P = D1 ⊕ D2 ⊕ D3 and the disk holding D2 fails, then D2 = D1 ⊕ D3 ⊕ P, because XOR-ing a value twice cancels it.
Common Mistakes
Using a full rotation as the rotational latency. The average is half a rotation, unless the question says otherwise.
Forgetting to convert RPM to rotations per second. 7200 RPM = 120 rotations per second, so one rotation = 8.33 ms.
Counting tracks per surface as cylinders times surfaces. Cylinders = tracks per surface; total tracks = cylinders × surfaces.
Charging seek and rotational delay for every sector of a contiguous file. Contiguous data pays them once (plus small track-switch costs if given).
Mixing GB and GiB. Check whether the question uses powers of 2 or of 10.
Thinking an SSD overwrites data in place. It always writes to a new page and erases old blocks later, in whole blocks.
Treating RAID as a backup. RAID survives disk failures, but not accidental deletion, corruption or ransomware.
GATE and Interview Questions
Q1. A disk rotates at 6000 RPM and has 300 sectors of 512 bytes per track. Find the average rotational latency, the time to transfer one sector and the transfer rate.
6000 RPM = 100 rotations/s, so one rotation = 10 ms and average latency = 5 ms. One sector takes 10 / 300 ≈ 0.0333 ms. Transfer rate = 300 × 512 × 100 = 15,360,000 B/s = 15.36 MB/s.
Q2. A disk has 8 surfaces, 1024 tracks per surface, 256 sectors per track and 512 bytes per sector. Find its capacity and the bits needed for a sector address.
8 × 1024 × 256 × 512 = 23 × 210 × 28 × 29 = 230 B = 1 GiB. Number of sectors = 221, so 21 bits.
Q3. Why is the average rotational latency half a rotation?
When the head arrives on the track, the wanted sector is equally likely to be at any angle. The waiting time is uniformly distributed between 0 and one full rotation, so its average is half a rotation.
Q4. What is write amplification in an SSD and what increases it?
The ratio of bytes physically written to flash to bytes the host asked to write. Garbage collection increases it, because valid pages must be copied before a block is erased. Little free space, small random writes and not using TRIM make it worse.
Q5. Why does an SSD need wear levelling?
Each flash block tolerates only a limited number of program/erase cycles. Without wear levelling, frequently written LBAs would wear out their blocks quickly while other blocks stay almost unused, and the drive would fail early. The FTL spreads writes over all blocks.
Q6. Convert LBA 5000 to CHS for a disk with 16 heads and 63 sectors per track.
Sectors per cylinder = 16 × 63 = 1008. C = 5000 div 1008 = 4, remainder 5000 − 4032 = 968. H = 968 div 63 = 15, remainder 968 − 945 = 23. S = 23 + 1 = 24. So CHS = (4, 15, 24). Check: (4 × 16 + 15) × 63 + 23 = 79 × 63 + 23 = 4977 + 23 = 5000.
Summary
Secondary storage is non-volatile, large and cheap, but far slower than DRAM.
A disk has platters, surfaces, tracks, sectors and cylinders. Capacity = surfaces × tracks × sectors × bytes per sector.
Access time = seek + rotational latency + transfer (+ controller); average rotational latency = ½ × 60 / RPM; transfer rate = bytes per track × rotations per second.
Random access is dominated by mechanical delays; reading 4 MiB contiguously took about 76 ms versus about 67 s scattered.
Modern drives use LBA; LBA = (C × heads + H) × sectors per track + (S − 1).
SSDs use NAND flash: read/program by page, erase by block, no in-place overwrite. The FTL provides mapping, garbage collection, wear levelling and ECC. Write amplification = flash writes ÷ host writes.
NVMe over PCIe replaces the single 32-command AHCI queue with many deep queues and much higher bandwidth.
RAID uses striping, mirroring and parity to trade capacity for speed and fault tolerance.
Next, I/O Organization & Interfaces looks at how the CPU actually talks to devices like these disks.