Skip to main content

Lesson 23 of 26 · 12 min read

Flash-based SSDs and end-to-end data integrity

Understand Flash erase-before-program rules, log-structured FTLs, garbage collection, write amplification, wear leveling, and checksums that catch silent data faults.

Four SSD and integrity topics: Erase blocks, Log FTL + GC, Write amplification, and Block checksums.
SSD FTLs remap out-of-place flash pages while end-to-end checksums catch silent bit rot, misdirected writes, and lost writes.
Course syllabus · lesson 23 of 26
In this lesson

Spinning drives are slowly giving way to solid-state drives (Flash SSDs) — chips storing charges in silicon transistors with zero moving arms or rotating platters. Yet SSDs impose bizarre physical rules: you cannot overwrite a 4 KiB flash page in place without erasing its containing block. The controller usually programs a different page and postpones that erase. Meanwhile, whether data sits on platters or NAND cells, drives suffer partial silent failures that simple RAID mirroring misses.

The crux of the problem is two-fold: how an SSD's internal Flash Translation Layer (FTL) exposes a clean normal block interface on top of erase-before-write silicon, and how checksums detect latent sector errors, bit rot, misdirected writes, and lost writes.

NAND flash page/block erase asymmetry mapped by a Log-Structured FTL (LBA -> PPN) with garbage collection and write amplification, paired with CRC/Fletcher block checksums guarding against bit rot, misdirected writes, and lost writes.
Open full-size diagram
Modern SSDs run an internal log-structured mapping inside firmware; reliable file systems layer end-to-end checksums on top.

Follow an SSD overwrite and integrity check

Logical block LBA 7, FTL map 7 → 4, Flash page 4 old data, Flash page 9 freeLogical blockLBA 7FTL map7 → 4Flash page 4old dataFlash page 9free

Step 1 of 3

Read the old mapping

The flash translation layer maps host block 7 to physical flash page 4.

Part 1: Inside Flash-based SSDs (SLC, MLC, TLC, and FTLs)

NAND groups physical pages inside larger erase blocks. Use a teaching geometry of 4 KiB pages and 256 KiB erase blocks, or exactly 64 pages per erase block. These units are independent of the host OS page size. The following operation latencies illustrate the asymmetry and vary with the device:

  1. Read (~10–50 us): Fast and non-destructive across any random page!
  2. Erase (~1–3 ms): Slow, high-voltage pulse resetting an entire erase block (64 pages in this model) to all 1s (ERASED), wearing down the oxide layer slightly every cycle (wear-out, finite P/E cycles).
  3. Program (~100–300 us): Flips selected 1s to 0s inside an already-erased page (VALID). You cannot flip 0 back to 1 without erasing the whole parent block!

To look like a standard hard drive to Linux or Windows, the SSD controller executes a Log-Structured Flash Translation Layer (FTL):

  • Out-of-place updates: When the host overwrites logical block LBA 100, the FTL writes the new data into the next erased physical flash page (PPN 45), updates its internal RAM mapping table (LBA 100 -> PPN 45), and marks the old flash page (PPN 12) INVALID (dead)!
  • Garbage Collection & Write Amplification: Once dead pages pile up, a background cleaner copies still-live pages from a partially dead block into a fresh block and erases the old block. Copying live pages adds extra physical flash writes beyond what the host asked for — measured by write amplification (flash_bytes_written / host_bytes_written). Keeping extra hidden over-provisioned space (7–28%) and letting the OS send TRIM commands when deleting files keeps write amplification low!
  • Wear leveling: Even files never modified by the OS (static cold blocks) get gently migrated periodically so all erase blocks wear out evenly rather than killing one hot block early.

The map is part of what must survive

A single-level cell (SLC) encodes one bit using two threshold-voltage ranges. In the common naming scheme, two-bit MLC uses four ranges, and TLC uses eight. Higher density puts more ranges into the same voltage span, leaving less margin between them. Program, read, retention, and endurance characteristics depend on the NAND design and the controller's error correction. The simplified erased-one and programmed-zero model describes why erasure is coarse. Real multi-bit cells encode bits through these voltage levels.

A page-mapped FTL answers reads with a forward map indexed by logical page. It also needs a way to identify which logical page a physical record once held, for example through a tag in spare bytes next to the payload. To decide if the tagged page is live, the cleaner compares its physical address with the current forward-map entry. A tag by itself cannot distinguish an obsolete copy from the latest one.

At 4 KiB mapping granularity, a 1 TiB logical SSD has 2^40 / 2^12 = 2^28 entries. Even a compact four-byte entry needs 1 GiB of memory for a full resident map. Extra fields, wider addresses, and metadata caches can change that budget. Designs can cache parts of a page map or use coarser mappings to shrink it. A coarse mapping makes individual page updates harder to represent, so some designs combine block mappings with page-level logs.

When a write moves a logical page, the controller must preserve enough persistent mapping information to find the new version after power loss. The new page must be complete before recovery selects it. Conversely, the old page must remain recoverable until the new selection is durable. One implementation could persist mapping deltas and periodically compact them into a checkpoint. It would reconstruct the map on boot from the checkpoint and valid later updates. The same dependency applies when garbage collection relocates a live page: make the new copy reachable before erasing the victim.

Part 2: Data integrity and silent storage failures

Early RAID assumed drives are fail-stop (either 100% working or totally dead). Real production storage studies reveal subtler failure modes:

  • Latent Sector Errors (LSEs): Single bad sectors detected by the drive's internal ECC only when finally read (handled via RAID parity rebuild + periodic background disk scrubbing!).
  • Silent Corruption (Bit rot): Firmware or bus glitches flip bytes without triggering any hardware read error.
  • Misdirected Writes: The drive writes the correct bytes to the wrong disk or wrong sector!
  • Lost Writes: The controller tells the OS "write succeeded!" while quietly dropping the write from volatile cache — leaving old stale bytes at the right address!

Defending against corruption: Checksums & parent verification

Filesystems such as ZFS and Btrfs can attach checksums to data and metadata. Consider a scheme that protects each 4 KiB payload block with a CRC, a Fletcher checksum, or a cryptographic hash. The layout determines which kinds of failure the reader can distinguish.

  • Storing a block's checksum alongside (disk_id, block_addr) inside its block helps detect bit corruption and misdirected writes. The reader must compare the stored identity with the address it expected to read.
  • Yet a lost write leaves both old block and old self-checksum intact! How do ZFS and high-assurance systems catch even lost writes? Store each child block's checksum inside its parent pointer (inode / indirect block). A redundant copy provides a way to repair the block when it passes verification against the expected checksum.
Code exampleTrace
SSD Overwrite Step:
  Host Write(LBA=100, V2) -> FTL allocates next erased page PPN=45
  FTL updates map: LBA 100 -> PPN 45, marks old PPN 12 INVALID
  Later GC: copies live pages out of dirty block -> erases whole block

Compute a check value and ask what it proves

For a two-byte Fletcher-style check, start with accumulators s1 = 0 and s2 = 0. For each byte, add its value to s1 modulo 255, then add the updated s1 to s2 modulo 255. Bytes 1, 2, 3 produce intermediate pairs (1, 1), (3, 4), and (6, 10). Swapping the first two bytes gives (2, 2), (3, 5), and (6, 11). An ordinary sum stays at 6, but the cumulative sum distinguishes these two orders.

A CRC treats the bits as polynomial coefficients and divides by a fixed generator using XOR for subtraction. For a small example, append three zeros to data bits 1011 and divide 1011000 by 1101. The remainder is 100. Transmit or store 1011100 so that redividing the complete word yields zero. This toy generator illustrates the arithmetic. Real choices such as CRC-32C use wider generators selected for error-detection properties. Any finite check value can collide. An eight-byte checksum per 4 KiB payload is about 8 / 4096 = 0.195% of payload size before accounting for how checksums are packed, cached, and updated.

Now compare three read outcomes for logical block 4. If the returned data changes but its checksum stays the same, recomputation usually exposes the corruption. If block 4's complete record is mistakenly written to block 9, its self-checksum can still pass when someone reads block 9. Comparing the recorded identity with the requested address detects that mismatch. Block 4 itself might also retain a valid old version, which an address check alone accepts. If a lost update leaves that old version in place, the independently durable parent must carry the new expected checksum or generation before the reader can diagnose staleness. If the parent also stayed old, a consistent old tree may look valid and the durability failure needs other evidence.

Scrub while redundancy is intact

A scrub reads stored blocks proactively and verifies the expected checksums. With two replicas, suppose replica A returns an uncorrectable read error and replica B returns bytes that match the parent checksum. The storage system can serve B and rewrite A using the validated copy. If both replicas return bytes but differ, verification tells the system which one matches the expected version. Merely observing a disagreement would leave the choice ambiguous. If neither validates, detection has succeeded and repair needs another recoverable copy.

Scrubbing matters for parity arrays too. An unreadable sector can go unnoticed while the array is healthy and the sector remains untouched. During a one-disk rebuild every surviving chunk in the affected stripe may be needed to reconstruct the missing data. An unreadable survivor then becomes a second unknown in a stripe with only one parity equation. Proactive scrubbing finds some latent errors before the rebuild has used up that redundancy. The scrub itself consumes bandwidth, so its schedule affects both detection delay and foreground load.

Worked trace: trace an SSD overwrite + lost-write catch

Use two four-page erase blocks. Block 0 spans physical pages 0 through 3 and block 1 spans pages 4 through 7. Each host write targets 4 KiB.

  1. Initial state. Logical pages 4 and 5 map to physical pages 0 and 1. All other physical pages are erased.
  2. Two overwrites. Write version 2 of logical page 4 into physical page 2, then version 3 into physical page 3. The current map now points to page 3 for logical 4 and page 1 for logical 5. Physical pages 0 and 2 are invalid. Block 0 has no erased pages left.
  3. Collect block 0. The cleaner moves pages 1 and 3 to pages 4 and 5, respectively. Once both mapping changes are durable, it erases block 0. This cycle programmed four physical pages for two host page writes. Write amplification over that window is 16 KiB / 8 KiB = 2, excluding metadata. The copying also adds two physical reads and the erase adds latency, neither of which appears in the write-bytes ratio. Four erased pages were created, but two were spent on survivor copies, for a net gain of two.
  4. Change the victim. A fully invalid block yields four free pages with zero survivor programs. A block with three live pages yields only one net free page and requires three survivor programs. If this pattern repeats, each new page takes one host-data program and three relocation programs, yielding amplification of four. Spare space helps the controller wait for better victims. A discard such as TRIM helps by telling it which logical pages can be dropped.
  5. Inject a lost write instead. Suppose a buggy storage controller suffers a lost write on LBA 4 (V2), leaving V1 on disk while the filesystem already updated inode I with checksum(V2). When the app reads LBA 4 later, the computed checksum checksum(V1) mismatches the inode's stored checksum(V2) — catching silent data loss immediately instead of serving corrupt bytes!

Continue with distributed systems, unreliable networks, and RPC.

Before you move on

Try it in your workspace

Trace a page overwrite in a log-structured Flash Translation Layer (FTL) with out-of-place writes, block erasures, garbage collection, and write amplification, then verify how end-to-end checksums catch silent corruption.

Keep a short note of what you tried, what passed, and what you still need to check.

Your practice record

0 of 3 checked.

Saved in this browser when storage is available. Uncheck any item to revisit it. This is your own record, not an assessment.