Garbage collection in an SSD is the background process in which the SSD controller copies still-valid data out of partly used flash blocks and then erases those blocks so they can accept new writes. In storage hardware, it exists because NAND flash cannot overwrite data in place: pages can be written only when empty, and emptying them requires erasing a much larger block.
Garbage collection is therefore a permanent part of how a solid-state drive manages free space, and it shapes sustained write speed, latency consistency and endurance. Not to be confused with automatic memory management in programming languages, which shares the name but works on a different problem.
Why NAND flash needs garbage collection
NAND flash needs garbage collection because of an asymmetry between write and erase units. Data is programmed in pages of typically 16 KB, but it can be erased only in blocks that hold hundreds or thousands of pages, often several megabytes in modern 3D NAND. A page that holds data must be erased before it can be programmed again.
To avoid erasing a whole block for every small update, the controller performs out-of-place writes: new data goes to a fresh page, the flash translation layer updates its mapping table, and the old copy is marked stale. Over time, blocks fill with a mix of valid and stale pages, and garbage collection reclaims that wasted space.
| Unit | Typical size | Operation allowed |
|---|---|---|
| Page | 4 to 16 KB | Program (write) and read |
| Block | Several MB in 3D NAND | Erase |
| Superblock | One block per die, striped | Managed as one GC unit by many controllers |
| Logical sector | 512 bytes or 4 KB | Host read and write |
How the controller performs garbage collection
The controller performs garbage collection in a select, relocate and erase cycle. It chooses a victim block, copies the valid pages to a free block, updates the mapping table, and erases the victim so it returns to the free block pool.
- Victim selection: the firmware picks a block with few valid pages, often weighted by age and wear.
- Relocation: valid pages are read and rewritten into an open destination block.
- Mapping update: the flash translation layer points logical addresses to the new physical pages.
- Erase: the victim block is erased and returned to the pool of free blocks.
Victim selection policy matters. A greedy policy picks the block with the fewest valid pages and minimizes immediate copying. A cost-benefit policy also considers how long the data has been unchanged, which separates hot and cold data and reduces future copying. Most controllers combine these with wear leveling, so rarely changed blocks are periodically recycled as well.
Garbage collection runs in two modes. Background garbage collection uses idle time and is invisible to the host, while foreground garbage collection runs when free blocks are nearly exhausted and competes directly with host writes, causing latency spikes and throughput drops.
Garbage collection and write amplification
Garbage collection is the main source of write amplification, the ratio between data written to NAND and data written by the host. Every valid page that is relocated is an extra write the host never requested, and it consumes program and erase cycles that count against the drive endurance rating.
The amount of extra work depends on how full the drive is and on the workload. The following table shows the main factors that raise or lower the cost of garbage collection.
| Factor | Effect on GC cost | Reason |
|---|---|---|
| Over-provisioning | Lower with more spare area | Victim blocks hold fewer valid pages |
| TRIM | Lower when enabled | Deleted data is not relocated |
| Small random writes | Higher | Valid and stale pages mix within blocks |
| Large sequential writes | Lower | Whole blocks become stale together |
| High fill level | Higher | Less free space forces foreground GC |
| Hot and cold separation | Lower | Blocks invalidate more uniformly |
Typical write amplification ranges from close to 1.0 for sequential workloads to 3 or more for random writes on a nearly full drive. Exact values depend on firmware design and are rarely published, so they should be measured rather than assumed.
Related mechanisms in SSD management
Garbage collection works together with several other SSD features, and each one addresses a different part of the free-space problem. Understanding the boundaries helps when diagnosing performance.
| Mechanism | Primary purpose | Interaction with garbage collection |
|---|---|---|
| TRIM | Host reports deleted data | Marks pages stale before GC runs |
| Wear leveling | Spreads erase cycles evenly | Influences victim and destination choice |
| Over-provisioning | Reserves hidden spare capacity | Provides room for efficient GC |
| SLC cache | Absorbs bursts at high speed | Cache must be folded and collected later |
| Zoned namespaces | Host writes zones sequentially | Moves most GC decisions to the host |
With Zoned Namespaces and Flexible Data Placement in the NVMe specifications, the host groups data with similar lifetimes, which can bring device-level write amplification close to 1.0 in suitable data center workloads.
Practical effects and common misconceptions
The practical effect of garbage collection is that fresh-out-of-box performance is not steady-state performance. A new drive writes into clean blocks; after the drive has been filled and rewritten, sustained random write speed can fall to a fraction of the initial figure, which is why enterprise tests precondition drives before measuring.
- Garbage collection is not the same as TRIM; TRIM only informs the drive, while garbage collection does the physical work.
- Manual defragmentation does not help; it adds writes and increases wear without improving flash layout.
- Leaving free space helps: keeping 10 to 20 percent of a consumer drive empty acts as extra over-provisioning.
- Idle time matters: drives that never idle rely on foreground GC and show more latency variation.
In simple terms
An SSD is like a notebook where you can write only on blank pages, and the only way to get blank pages is to tear out a whole chapter at once. When you change a note, the drive writes the new version on a blank page and crosses out the old one.
Eventually chapters fill up with crossed-out notes. Garbage collection is the tidy-up job: the drive copies the still-useful notes elsewhere, then wipes the whole chapter clean. Doing this quietly during breaks keeps the drive fast; doing it in a rush slows things down.
A practical example
A video surveillance server records eight camera streams to a 2 TB consumer NVMe SSD that is filled to 95 percent, with old footage overwritten continuously. After a few weeks, operators notice dropped frames during busy periods. Monitoring shows write latency jumping from under a millisecond to tens of milliseconds whenever the drive runs foreground garbage collection.
The administrator moves recordings to a 4 TB drive, limits the retention policy so the drive stays about 75 percent full, and confirms that TRIM is issued when old files are deleted. With more free blocks available, garbage collection finishes in the background, latency stays stable, and the recorder no longer drops frames under peak load.