Disk fragmentation is a problem that can occur on hard drives. When the disk space on a hard drive is too fragmented, it can become difficult to access the data. This can cause problems for your computer because it can make it difficult to find and load the files you need. Additionally, fragmentation can also cause your hard drive to fill up quickly and become unstable. If you experience this problem, you should defragment your hard drive.
Today’s Question & Answer session comes to us courtesy of SuperUser—a subdivision of Stack Exchange, a community-drive grouping of Q&A web sites.
The Question
SuperUser reader Simon Sheehan is curious about the state of defragmentation in modern drives:
Let’s turn to some of the contributor answers to investigate Simon’s question.
The Answer
SuperUser contributor Daniel R. Hicks fields the question:
Journeyman Geek adds in the following information about Linux file systems:
Operating systems have gotten smarter as well. Whereas DOS 1.x would have fetched each sector from disk as it was referenced, a modern OS is able to see that you have a file open for sequential access and can reasonably predict that you’ll be fetching additional sectors once you’ve consumed those you have now. Thus it can “pre-fetch” the next several (dozen) sectors.
And any more it’s often better to not have a file contiguous. On a (large) system where the file system is spread across multiple drives a file can actually be accessed faster if it is “spread” as well, since multiple disks can be seeking the file simultaneously.
I defragment every 2-3 years, whether my box needs it or not.
[I’ll add that the important thing is not so much whether the data on the disk gets defragmented as whether the free space does. FAT was terrible at this — unless you defragged things kept getting worse and worse until there were no two contiguous blocks of free space. Most other schemes can coalesce free space and allocate pieces in a somewhat “smart” fashion so the fragmentation reaches a certain threshold and then stabilizes, rather than getting worse and worse.]
One element of the original question that wasn’t addressed is whether or not you should defragment your flash drive. Defragmentation is a very reader/write intensive process and should be avoided on solid-state storage devices like flash drives and Solid State Disks (SSDs). For more information on defragmentation, file systems, and SSDs, check out the following HTG articles:
Modern Linux filesystem(s) keep fragmentation at a minimum by keeping all blocks in a file close together, even if they can’t be stored in consecutive sectors. Some filesystems, like ext3, effectively allocate the free block that is nearest to other blocks in a file. Therefore it is not necessary to worry about fragmentation in a Linux system.
I’d note though that ext4 has online defragmentation so eventually fragmentation IS an issue, even with Linux file systems.
Windows file systems have their clusters placed wherever there’s space to put them, and defrag runs around and replaces them. With Linux, files are preferentially placed where there’s enough space.
I’d note though, Windows 7 has scheduled defragmentation runs, so it isn’t really necessary to run defrag manually.
HTG Explains: Do You Really Need to Defrag Your PC? HTG Explains: What’s a Solid State Drive and What Do I Need to Know? HTG Explains: Why Linux Doesn’t Need Defragmenting
Have something to add to the explanation? Sound off in the the comments. Want to read more answers from other tech-savvy Stack Exchange users? Check out the full discussion thread here.