Wear leveling, what is it?
Wear leveling is a technique used by some SSD controllers to increase the lifetime of the memory. The principle is simple: evenly distribute writing on all blocks of a SSD so they wear evenly. All cells receive the same number of writes, to avoid writing too often on the same blocks.
Flash memory in Solid State Drives (SSD’s) allows only a certain number of reading and writing processes. It usually ranges from 10,000 to 100,000. If we were to write 100 GB of data daily on a SSD with 400 GB of space, wear leveling will ensure that the 100 GB of data is not written always at the same location in the physical flash blocks. The data would instead be distributed evenly over all the physical cells of the SSD. Simply put, it will divide the 400 GB of physical memory into 4 blocks of 100 GB each and call it blocks 1, 2, 3 and 4. Thus, when you write 100 GB of data on day 1, it is written in block 1. When you delete and rewrite data on day 2, then it will be write in block 2 and so on. This ensures that all physical cells are used consistently to improve the lifespan of the SSD.
Application of wear leveling
Wear leveling algorithms
There are many algorithms for wear leveling. Let us limit ourselves here to two major basic principles:
- Dynamic wear leveling
- Static wear leveling
Dynamic wear leveling
With dynamic wear leveling, only the blocks that are rewritten are moved to new blocks. At the time of a rewrite the algorithm selects an empty block to write the data to update.
To achieve this, the SSD controller keeps track of the number of writes to each block using a non-volatile memory. When the SSD is brand new and unused, the counter is at 0. It is then incremented by 1 at each new write.
The dynamic wear leveling is however not optimal. Indeed, when a block is assigned to data that is read-only or not frequently updated, they do not move. It is better to place this type of data on the used blocks and place the data which is updated frequently on unused blocks.
Static wear leveling
Here, the controller selects the block in which rewrite the data from all blocks of the hard drive: it will take a block that has relatively few entries, corresponding to blocks containing static data, or empty blocks few used.
Due to these characteristics, the SSD is a hard drive that is important to optimize. Wear leveling is a recognized technique to achieve this. There are other types of optimization designed to reduce wear on SSD by limiting the volume of writing to improve durability.