Β§44.8–44.9Flash Garbage Collection and Mapping-Table Size

Part III OSTEP pp. 572–578 Β· ~7 min read

  • garbage collection
  • trim
  • overprovisioning
  • hybrid mapping

Log-structuring made the FTL fast, but β€” exactly as with LFS β€” it brings two costs: garbage, and a big mapping table.

44.8 Garbage Collection

Overwriting a logical block writes a new page and leaves the old one as garbage. The FTL runs garbage collection to reclaim it: find a block with dead pages, copy its still-live pages to the log, then erase the block:

Overwrites leave garbage; garbage collection reclaims it. Start: 100β†’4, 101β†’5, 2000β†’2, 2001β†’3 (blocks 100/101 were re-written to block 1). Red = garbage (dead), brown = live, green = erased.
block 0a1G0a2G1b1V2b2V3block 1c1V4c2V5E6E7mapping table100β†’4101β†’52000β†’22001β†’3pages 0,1 = dead old 100/101; pages 2,3 = live 2000/2001

1After overwriting 100 and 101

Logical blocks 100 and 101 were rewritten (c1, c2) into block 1 (pages 4, 5). Their OLD copies (a1, a2 at pages 0, 1) are now garbage β€” valid on the flash, but no longer pointed to by the map.

step 1 / 4

The ideal victim is a block that is entirely dead β€” it can be erased with no data migration at all. Two things help:

Aside: The trim Command

Because a log-structured SSD keeps a flexible logicalβ†’physical map, it helps to know when a block is truly unneeded. The trim command lets the file system tell the SSD β€œthis block range is deleted” β€” so the FTL can drop the mapping and reclaim the space at GC time. Here the implementation (flexible mapping) shapes the interface (a new command).

To cut GC’s cost further, SSDs use overprovisioning : build in more physical flash than the advertised capacity. The slack lets GC run lazily in the background (when the device is idle) and adds internal bandwidth for cleaning β€” so it barely dents the performance the client sees.

44.9 Mapping-Table Size

The second cost is memory. A page-level map needs one entry per 4 KB page β€” about 1 GB of RAM for a 1 TB SSD. Too much. The alternatives trade table size against write flexibility:

Trading mapping-table size against write flexibility.
mapping memorywrite behavior
page-levelone entry per PAGE β€” hugefully flexible: any page anywhere; fast writes
block-levelone entry per BLOCK β€” tiny (Γ· pages-per-block)a sub-block ("small") write forces read-modify-write of the WHOLE block β†’ high write amplification
hybridper-page log table (small) + per-block data tableflexible writes go to a few log blocks, merged back periodically
page-map + cachecache only the hot mappings in RAMgreat if the working set fits; a miss costs an extra flash read (and maybe a write)
Dotted-underlined cells have explanations β€” click one.

Block-level mapping (one pointer per block, like using bigger pages in VM) is compact but murders small writes β€” a write smaller than a block forces reading the whole block and rewriting it elsewhere.

The popular compromise is hybrid mapping : keep a few erased log blocks with per-page mappings (a small log table) for flexible writes, plus per-block mappings (a data table) for everything else. Reads check the log table first, then the data table. The trick is keeping log blocks few, so the FTL periodically merges them back into block-mapped form:

  • switch merge (best): a log block was filled exactly like a data block, so it simply becomes one, replacing all its per-page pointers with a single block pointer β€” no copying.
  • partial merge: only some pages were rewritten; the FTL reads the rest from the old block and appends them, then switches. Extra I/O.
  • full merge (worst): the log block’s pages belong to many different data blocks; the FTL must gather scattered pages to rebuild each β€” lots of extra work, best avoided.

Check yourself: flash GC and mapping tables

1.In a log-structured FTL, what creates garbage, and what does garbage collection do about it?

2.How does the FTL decide whether a page is live or dead during GC?

3.Why does garbage collection contribute to write amplification?

4.What is the trim command, and why is it useful for SSDs?

5.Why is a pure page-level mapping table impractical, and why is pure block-level mapping also problematic?

6.How does hybrid mapping balance the two, and what is a switch merge?

6 questions