Unspoken rules of flash memory: your fault is more important than the solution

Hello everyone, I am May.

foreword

At present, the vast majority of storage devices use flash memory as the storage medium , and many internal firmware algorithm solutions are serving flash memory.

No matter what the algorithm is, it is based on the premise of following the characteristics of Flash .

What are the hidden rules of flash memory?

erase first write

The flash memory block (Block) cannot be overwritten , it does not allow developers to write repeatedly in one place, it must be erased first.

Generally speaking, when a piece of data is written, the data is arranged to be written to a new address space . When you really don’t know whether an address has valid data, the safe way is to erase it first and then delete it. write.

Write the whole page, erase the whole block

The smallest write unit allowed by flash memory is page , and the minimum amount of data written must be 1 page.

There is a basic operation in the FTL algorithm, which will combine the data passed down by the host into 1 page, and then write it into Flash. If it is less than 1 page, it will be placed in Dbuf, and wait for the next data to form 1 page, and then write it into Flash. .

The basic unit for flash memory to be erased is a block . As long as the erase operation occurs, the data of the entire block will be cleared, so we generally do not easily erase the entire block.

Solution: When there is a piece of new data, it will put the data in the new physical address. This is to avoid erasing easily and avoid erasing valid data by mistake. Repeated erasing and writing on the same physical address will consume the life of the flash memory block too quickly.

Writing data needs to be randomized

When we write, if we simply write the data in, we will encounter many errors, sometimes the writing fails, and sometimes the read data is incorrect.

This is caused by the working mode of flash storage electronics, which is particularly sensitive to the pattern of data writing. If all 0s or all 1s are continuously written, it will easily lead to insufficient internal charge, resulting in a decrease in signal anti-interference.

The intuitive phenomenon is that you will find that some data bits have been flipped.

Solution: Before writing data, the data needs to be randomized first , that is, the data is disrupted so that the distribution of 0 and 1 is even.

But scrambling is not just random scrambling. It will be randomized in some way and written to flash. When reading data, it will first perform an anti-randomization process to get real data .

Only when the data fills the entire block will it be stable

Flash memory also has a strange feature, that is, you have to write a whole block of data before the data in this block will be stable .

But many times, we don't have so much data to fill an entire block.

Solution: In order to ensure the stability of the written data, after we write a piece of data, we will write a few extra pages of data . The purpose is to keep the written data stable, and the extra pages of data written are called For additional logical page data.

Flash memory blocks have a certain lifespan

Every write and erase will cause wear to the flash memory block . After a long time of wear, the flash memory block will be broken. Its life is measured by PE (erasing times).

In use, we try to avoid repeatedly erasing and writing on the same area, otherwise the blocks in this area will wear out soon.

Solution: FTL needs to do a wear leveling process, so that all blocks can share the data writing .

Distribute the data to other blocks so that each block wears evenly, which can not only ensure the maximum amount of data written to the flash memory, but also prolong the life of the flash memory.

The number of reads per flash block is limited

In addition to the limit on the number of erasing and writing, the flash memory block also has a limit on the number of reads. If the number of reads is too high, the data will be corrupted . This phenomenon is called read interference.

Solution: The FTL algorithm needs to perform read interference processing . When the number of reads of a block reaches a certain threshold, the data is moved from the block to a new block .

Data remains lost

The principle that flash memory can store data is the storage of charge, but the charge is erratic. Over time, the charge will be lost , and the reflected phenomenon is the loss of data.

This time is hard to say, it can be more than ten years, a few years, a few months, or even shorter.

If it is in a high temperature environment, the rate of charge loss will be faster.

Solution: The FTL algorithm needs to do a scanning process to find out whether there is any data loss problem. If it is found, immediately move the data to a new location to take precautions.

Bad blocks are inevitable

Bad blocks in the flash memory are unavoidable. Some are bad blocks when they leave the factory, and some are bad blocks that are generated during use of the flash memory.

Symptoms of bad blocks are erase failure, or write failure, or read failure (ECC error correction cannot be corrected) .

Solution: FTL algorithm needs to do a bad block management process, mark bad blocks on bad blocks, do not use these bad blocks when using them , and use good blocks.

For MLC or TLC, there is a next page corruption problem

For MLC, a worlLine has Upper page and Lower page;

For TLC, a worlLine has Upper page, Extra page and Lower page;

When writing, if an accident occurs, such as abnormal power failure, the data successfully written on the Lower page will be destroyed .

Solution: One way is to add a capacitor to the circuit. Once an abnormal power failure occurs, the capacitor will start to discharge. During this time, the data will be saved and the normal power-down process will be started.

Another way is to do a power-down recovery process in the FTL algorithm , and restore the lost data by rebuilding the mapping table .

Generally, whether there is a capacitor or not, the FTL will have an abnormal power-down processing module.

summary

There are so many problems with flash memory, but companies in the major storage fields are still unable to resist entering the market to study its problems. After all, all solutions are based on characteristics. Only when you understand the characteristics can you have a solution.

Well, this time I will write here first, I wish you a happy life.

Guess you like

Origin blog.csdn.net/weixin_41904238/article/details/131173944