Comprehensive understanding of SSD and NAND Flash (2)
4. SSD Firmware (FW) contents
(1) Mapping Table
Logical address: relative address used in user program.
Physical address: absolute address of actual storage unit;
Therefore, the content stored in the mapping table is the mapping information from logical address to physical address. The mapping table is queried by logical address to find corresponding physical address, and then read and write access to actual storage unit.
A mapping table is maintained in SSD. In general, DRAM is on board in SSD, which is used to store temporary data of program running and will be lost when power fails. The mapping table is stored in SDRAM (convenient for quick access), and several mapping tables are stored in NAND Flash (to prevent loss of mapping relationship after power failures). What’s more, the mapping tables in NAND Flash are updated regularly.
(2) Garbage Collection
Garbage collection means moving valid data from several blocks to new ones and then erasing old ones.
There are many garbage collection mechanisms, which are put forward according to different emphasis. So there is no optimal algorithm, just only like a suitable or inappropriate partner. For example, Greedy algorithm chooses the Block with the least valid pages to collect each time, that is, greeds for garbage and collects the most garbage as much as possible each time. In addition, there is also Cost-Benefit algorithm (considering the number of block erasure), Cat collection algorithm, CICL algorithm and so on.
There are two other collection strategies:
· Passive collection strategy: When there are write requests, first judge the comparison between the current available space size and the critical value size. If there is enough space, write directly to the free space. If there is not enough space, first start garbage collection, and then complete write requests to the free area.
· Deficiencies: Writing requests will be delayed when space is insufficient.
· Positive collection strategy: Set periodic tasks through firmware and periodically check the available space size. Perform garbage collection if necessary.
· Skills: Use free time to collect garbage ahead of time to avoid unnecessary delays in requests.
· Deficiencies: If the system has no free time, garbage collection cannot be effectively implemented.
(3) Wear Leveling
Each Block has a lifetime (Program/Erase Count, P/E value) with a limited number of erases. The lifetime of NAND Flash is similar to the barrel principle, depending on the minimum lifetime in all blocks. If you desperately erase a piece, the life of NAND Flash will be reduced to a minimum. Therefore, wear leveling is introduced to balance the erasure times of all blocks.
There are many different wear leveling mechanisms, which can be roughly divided into two categories: dynamic WL and static WL.
· Dynamic WL: Blocks with low P/E values are preferred for erasing.
· Static WL: Data from blocks with low P/E values is moved to blocks with high P/E values.
5. Supplementary concepts
(1) Write Amplication
· Principle of write amplification
Write Amplification = Flash Write Data Volume / Master Write Data Volume = Actual Write Data Volume / Required Write Data Volume
For example, if there is now a request to write a page, the amount of master write data is 1.
However, once this page written with a request triggers garbage collection, the current write request is delayed until the garbage collection is completed.
If garbage collection only moves 5 pages of valid data, the actual write volume should be 6 pages (1 page written with request operation, 5 pages written with moving operation), that is, the amount of flash write data is 6.
So write amplification is 6/1 = 6.
Ideal write amplification is 1, but Sandforce's data will be compressed and written. Optimally, write amplification can be 0.5, breaking Intel's theory of write amplification no less than 1.
· Compressed Writing
Three main benefits: First, reduce the number of storage to save storage space. Second, reduce the possibility of data flipping to be stored, increase the life of NAND Flash and reduce energy consumption. Third, get smaller NAND Flash write amplification to improve the speed of reading and writing.
Compressed writing is divided into lossy compression and lossless compression.
Lossy compression: There is loss of information, unable to save 100% of the original information.
Lossless compression: Accuracy loss is not allowed, and the original information can be recovered 100%. Complexity of compression and decoding in lossless compression is high, which often greatly reduces the advantages of NAND Flash in reading and writing speed.
Nowadays, data compression coding algorithm is not strong enough, so most manufacturers will not use compressed writing, except for Sandforce.
(2) Over Provisioning
· Introduction to OP
According to the process of garbage collection, it is not difficult to understand that the premise of garbage collection is to provide free areas to copy. If there is no free areas, garbage collection will not be able to execute, and then no data writing will be supported. In order to avoid this situation, the over provisioning is proposed.
Over provisioning is not only used to ensure the normal completion of garbage collection, but also to store the system data in SSD (including: bad block information, SSD firmware, Mapping Table, etc.).
Thus, if the storage size is 256GB, actual storage space may only be 238GB (7% of the general is over provisioning).
In addition, the larger the OP, the faster the garbage collection and the smaller corresponding write amplification will be. So reading and writing performance becomes better, but the space the user can use will be reduced.
· The difference between OP and SA
Based on the concept of SSD, over provisioning is not only used to ensure the normal completion of garbage collection, but also to store the system data in SSD (including: bad block information, SSD firmware, Mapping Table, etc.).
Spare Area (SA) is generally used to mark bad blocks and save ECC verification codes for main area data, based on the concept of a block in NAND Flash.
(3) Flash lifetime(Program/Erase Count)
As mentioned earlier, each block has a limited number of erasure, so the lifetime is introduced.