Part 3 of 7 · 2 min read
Overwrite problem
Think of a book where one page may be changed only by reprinting the whole chapter. A clerk who reprints the chapter for each typo wastes the printing press. A clever clerk puts the new page in a spare slot, marks the old page as "ignore", and fixes the table of contents. The analogy stops in one place: the drive must also tidy up the ignored pages later.
In plain words: If the drive overwrote a page in place, it would read the 64 pages of the block, erase the block, and program the 64 pages again with one changed. One host write would cause 64 page writes and one erase. A real drive does not do this. It writes the new data to any erased page, remembers the new place in a table, and marks the old page stale. This table is the central job of the flash translation layer (FTL), which is the firmware inside the drive.
A worked example. A host overwrites logical page 7, which sits in a block with 64 pages. With the naive method the drive reads 64 pages (3.2 ms), erases (3 ms), and programs 64 pages (32 ms): 38.2 ms and 64 page writes. With the table method it programs one erased page (0.5 ms), updates the table, and marks the old page stale. That is 0.5 ms and 1 page write, and it is 76 times quicker.
The key lines. The table maps a logical page number, which is the number the OS uses, to a physical page, which is the place on the chip. The two numbers are no longer related. This is the same idea as the logical block address of page 1, taken further.
Flash translation layer
The flash translation layer (FTL) is firmware in a flash drive that maps the logical page numbers that the OS uses to physical pages on the chips. It writes updates to fresh pages, marks the old pages stale, and collects stale space by garbage collection.
Example: after logical page 7 is rewritten, the table entry for 7 points to a new physical page, and the old physical page is marked stale.
Check yourself: 1. Why can a drive not simply reprogram a used page? 2. In the worked example, why is the table method 76 times quicker? 3. What does the FTL do with the old copy of a rewritten page?