Storage, Buses & I/O

wear leveling

Imagine a staircase where each step can only survive being trodden on a few thousand times before it crumbles. If everyone always steps on the same three steps, those wear out fast while the rest stay pristine and the staircase fails early. The fair fix is to route footsteps so every step gets roughly equal wear. Wear leveling is exactly that idea applied to flash memory: it spreads write-and-erase activity evenly across all the blocks so no single block is worn out long before the others.

It is needed because flash cells have a hard limit: each block can be erased only a finite number of times — perhaps a few thousand to a hundred thousand cycles depending on the flash type — before it stops holding charge reliably. Real workloads are lopsided: some logical blocks (a database log, a filesystem table) get rewritten constantly while most data sits untouched. Without intervention, the hot blocks would die quickly. Wear leveling, run by the flash translation layer, tracks how many erase cycles each physical block has endured and steers new writes toward the least-worn blocks; some schemes even relocate cold, rarely-changed data off low-wear blocks so those blocks can take a share of the churn.

Why it matters: wear leveling is the main reason an SSD's lifetime is measured in total bytes written across the whole drive rather than dying the moment one hot spot is exhausted. The honest caveat is that it does not make flash immortal — it equalizes wear, it does not remove it. Every drive still has a finite endurance rating, and write amplification (extra physical writes per logical write) eats into that budget. Wear leveling buys longevity and predictability; it does not grant infinite writes.

A drive has 1000 blocks, each good for 3000 erases. A naive scheme that always rewrites block 0 kills it after 3000 writes while the other 999 are fresh. Wear leveling rotates writes across all blocks, so the drive can absorb roughly 1000 x 3000 = 3 million block-erases before wear becomes a problem.

Spreading the same writes across every block multiplies usable lifetime by the block count.

Wear leveling extends life but does not make flash eternal. Drives ship with an endurance rating (total bytes written); exceed it and reliability drops. It also means SSDs degrade gradually with use, unlike an HDD whose mechanics do not 'wear out' from reading.

Also called
wear-levellingwear levelling磨損平衡耗損平均