It does this by physically organizing the contents of the mass storage device used to store files into the smallest number of contiguous regions (fragments, extents).
It also attempts to create larger regions of free space using compaction to impede the return of fragmentation.
The movement of the hard drive's read/write heads over different areas of the disk when accessing fragmented files is slower, compared to accessing the entire contents of a non-fragmented file sequentially without moving the read/write heads to seek other fragments.
Defragmentation is the operation of moving file extents (physical allocation blocks) so they eventually merge, preferably into one.
In such a paradigm, no data is ever removed from the disk, so that the operation can be safely stopped even in the event of a power loss.
Placing frequently accessed files onto the outer tracks increases performance.
[3] Improvements in modern hard drives such as RAM cache, faster platter rotation speed, command queuing (SCSI/ATA TCQ or SATA NCQ), and greater data density reduce the negative impact of fragmentation on system performance to some degree, though increases in commonly used data quantities offset those benefits.
However, the average access time can never be lower than a half rotation of the platters, and platter rotation (measured in rpm) is the speed characteristic of HDDs which has experienced the slowest growth over the decades (compared to data transfer rate and seek time), so minimizing the number of seeks remains beneficial in most storage-heavy applications.
A common strategy to optimize defragmentation and to reduce the impact of fragmentation is to partition the hard disk(s) in a way that separates partitions of the file system that experience many more reads than writes from the more volatile zones where files are created and deleted frequently.
A solid-state drive (SSD) is based on flash memory with no moving parts, so random access of a file fragment on flash memory does not suffer this delay, making defragmentation to optimize access speed unnecessary.
Furthermore, since flash memory can be written to only a limited number of times before it fails, defragmentation is actually detrimental (except in the mitigation of catastrophic failure).
Once the maximum fragmentation limit is reached, subsequent attempts to write to disk fail.