SSD0123B0erases 00123B1erases 00123B2erases 0FTLLBA 0–LBA 1–LBA 2–1write(a, x, 8192); fsync(a);2write(b, y, 4096); fsync(b);3pwrite(a, z, 4096, 4096); fsync(a);4unlink("b.txt");012LBAs IN USEFILE SYSTEM012101
Back: the SSD (flash blocks of pages, the controller and its FTL map)Front: your program and the file systemPages: L0 = holds LBA 0 · crossed out = stale · blank = erasedAt the back, an SSD: three flash erase blocks of four pages, the controller that runs the flash translation layer (FTL), and its map from LBAs to flash pages. In front, the program and the file system. Writes land in the next free page. Changing LBA 1 writes a new page and leaves the old one stale. Deleting b.txt frees LBA 2 only in the file system until TRIM tells the SSD. Garbage collection copies the two live pages to block 1 and erases block 0. Real SSDs have many thousands of blocks (a 256 KB block holds 64 pages of 4 KB), many flash chips working in parallel, and spare blocks the file system never sees. The figure keeps 3 blocks of 4 pages so every page is visible.

Flash and the FTL

  1. The file system sees the disk as a row of numbered blocks, logical block addresses (LBAs), that it can overwrite in place. An SSD keeps data in flash chips that cannot be overwritten. A controller inside the SSD hides the difference.

Writing and deleting

Cleaning up

What happens

;; step 1/10 · two-views
file system view   LBA 0, LBA 1, LBA 2, ...   (here: 4 KB blocks)
                   "write LBA 1" replaces it in place
inside the SSD     flash chips + a controller
                   flash cannot overwrite in place
the controller     makes the flash look like the simple view

Real SSDs have many thousands of blocks (a 256 KB block holds 64 pages of 4 KB), many flash chips working in parallel, and spare blocks the file system never sees. The figure keeps 3 blocks of 4 pages so every page is visible. Which LBAs a file gets is the file system's choice, and it also writes metadata (inodes, bitmaps, a journal). The figure shows only the data blocks and gives them LBAs 0, 1 and 2.