Hacker News new | ask | show | jobs
by jewel 3975 days ago
In summary, what book printers used to do is have a line of numbers on the title page of the book, which they would erase one at a time with each printing run. The reason why is that they would be reusing the original plates in the printing press, and it was easy to erase a number (by destructively removing it from the plate) as opposed to recreating a whole new plate for the title page.

Flash memory works in a similar way. After a block is erased, which is a slow process, it starts with all ones. It's very fast to switch a cell from a 1 to a 0, but to turn a 0 back into a 1 you have to erase the whole block again. (Block sizes can vary considerably, as much as 512 KiB on SSDs.) Note that it's the erase cycle which reduces the lifetime of the flash, not the switch from a 1 to a 0.

USB flash devices and SSDs don't expose low-level access to the NAND flash so it's not possible to take advantage of this property, but if you could you'd be able to have a small counter with one bit per number. Perhaps in some circumstances a bitmask would also work well. A bloom filter could also be implemented efficiently this way.

I imagine that embedded programmers and the SSD firmware takes advantage of this property of flash memory for its own data structures, I'd love to hear if that's the case.

3 comments

Flipping single bits from unprogrammed (conventionaly 1) to programmed (0) state is commonly used in both embedded systems and flash filesystems and translation layers.

Typical modern flash filesystem or FTL is copy-on-write and only marks old version of the block by either programming one bit (1-valid, 0-invalid) or programming address of new version into the old block.

Typical 80's/90's prepaid phone card is simple serial (E)EPROM that decrements count of remaining credit by programming successive bits. Modern smartcards also often have blocks that require separate access rights to be programmed and to be erased (although they also tend to implement normal binary counters that can be only decremented). Features of various programmable devices that relates to code security also tend to depend on this property of Flash/EEPROM (EEPROM and Flash differs mostly in the fact that for EEPROMs the size of write block is same as the size of erase block, typically one byte).

The convention that 1-unprogrammed and 0-programmed comes mostly from NMOS and TTL, where for both technologies, 0 is the strongly driven state (output strongly driven into ground) and 1 is essentially undriven.

I found it interesting that reusable printing plates are called stereotypes or clichés, both of which then made their way into general usage.
Does that mean that it's better to securely erase flash disks with FF's rather than 00's?
There is no difference from security point of view. To erase SSD you just TRIM[0] the whole device and wait some time while it erases underlying flash.

[0] https://en.wikipedia.org/wiki/Trim_(computing)