Electronic – How NAND Flash controllers erase single pages efficiently

flashmemory

I'm working on some code to manage a NAND flash and I need to erase single pages, given that the smallest erasable unit is a block, the only solution I could think of is to:

  1. Erase a reserved block
  2. Copy the entire block to the reserved one
  3. Erase the block
  4. Copy the reserved block back and skip that page.

While this works fine (haven't tested it much but it should work in theory) it's obviously very slow, I was wondering how flash controllers, for example in USB sticks, handle erasing a single page efficiently ?

Best Answer

Have a look at this paper from Micron : use a mapping of logical block to physical block. Maintain a supply of pre-blanked pages and write into the next available one (or one chosen by your wear-levelling algorithm).

Eventually almost all your blocks are full, with some holes where pages within the block have been marked "deleted" but not actually erased. Then you do your algorithm: find block(s) with most deleted pages, copy to new location, erase old location, put old location on the "free" list.

This then raises the question of how to store the mapping data itself; one common approach is to extend the blocks slightly and put the mapping data on the block itself (as a "tag"). At bootup the controller can cache some or all of the mapping in RAM. Another approach is to use the NOR flash of the controller itself to store the mapping data.