home > articles > disk defragmentation explained
36 comments

Disk Defragmentation Explained

By Anna Lind 14 February 2011 in Defragmentation

  Disk defragmentation used to be surrounded in mystery with advice being to never touch your computer mouse while defrag is running, doing it in Safe Mode and bracing yourself for the possibility of data loss from occasional power failure. Many people still fear defragmentation or simply try not to think about it because of the old advice still coming up in internet searches. In this article I will try to explain disk defragmentation and all related notions in simple terms to eliminate every fear or myth associated with it.


  To understand what disk defragmentation is, one first needs to understand how a hard disk operates, what a file system is and how fragmentation really happens. These may sound like very technical terms, but the notions are in reality quite easy to comprehend with a little explaining and some illustrations. Let’s look at them here.


How Your HDD Works

  Your HDD (hard disk drive) is the slowest part of your computer, because it contains moving parts - spinning platters and the read-write head. This is what it looks like inside your computer:

Every time you open a file (or the system tries to access a file), the CPU sends the request to your hard drive and the read-write head starts moving to retrieve the requested data. Instead of going into detail talking about how exactly the read-write head moves (using terms like "angular velocity", "seek time" and such), I will just state a fact you will need to remember - in terms of data access speed, the outer part of the hard drive platter, also referred to as the front of the drive, is the fastest, while the inner part, or the back of the drive, is the slowest.

The disk surface is subdivided into sectors and tracks (see picture below). If this seems like too much information to take in, then don't worry about it. There are two reasons why I'm including this info in my article - it may help create a picture in your mind showing how data is stored on your hard drive, and these are also terms that are frequently used in defragmentation software. So if you can make the extra effort, then by all means please read through this part and try to understand the extremely technical terminology that is going to follow here.

Tracks are basically like the annual rings on a cut tree. And sectors are like the wedges in a pizza, except in computer terminology a single sector is the part of the pizza wedge that belongs to a single track and is usually 512 bytes in size.

Different hard drive models may have a different number of tracks, and sectors. However, the fact remains that data stored on the outer tracks on any hard drive takes less time for the read-write head to access than data stored on the inner tracks.


What Is a File System?

  With huge amounts of data that is stored on the hard drive there has to be a way to organize and control it, which is what file systems do. NTFS is the file system used by Microsoft in the Windows operating system (from Windows NT on). The file system maintains the physical location of each file on the hard drive and makes it possible for your computer to retrieve data when it's requested. The file system combines groups of 512-byte sectors into clusters, which is the smallest unit of space to store a file or part of a file. On NTFS hard drives there are usually 8 sectors per cluster, which means the size of a single cluster is 4096 bytes. This is the size of pieces each file gets divided into. Considering that sizes of many files stored on your hard drive are measured in megabytes or even gigabytes, dividing them into 4096-byte pieces, although necessary for a number of reasons, provides huge potential for fragmentation.


What Is Fragmentation?

  On a freshly formatted hard drive files get written in a continuous manner - all clusters belonging to a single file are neatly stored together and the file is all in one piece, since there is plenty of free space to write each file. And then you begin using your PC. If you didn't use it, it would remain neatly organized and you wouldn't have to worry about fragmentation, but then it would be nothing but an expensive room decoration. Fragmentation happens not because you do anything wrong or because your PC is bad, it is what happens with normal PC use. Imagine a hard drive with files stored neatly one next to another. Now say you delete a 1-megabyte file from the middle of this neatly stored group, and then save a 2-megabyte file to your hard drive. Your system looks for free space to write the file to, it finds the 1-megabyte block of free space that you have just made available by deleting the old file, and starts writing the new file to it, and as one would expect, 1 megabyte later it runs out of space in this spot and starts looking for the next available block of free space. If the next window of space is 1 megabyte in size, then your newly saved file gets broken into 2 pieces only. But let's say the next block of free space is half a megabyte, then having written part of your file into this spot, the system looks for more space and your file is now broken into more than 2 pieces. This is a simplified explanation of how fragmentation occurs.

To see why it matters for your PC's performance, have a look at the picture below. On the left you see a schematic representation of a file stored all in one piece in one location. On the right you see the same file fragmented into several pieces stored in different locations on the hard drive. Now imagine the amount of work the read-write head has to do to retrieve the file on the left and compare it to the amount if work it has to do jumping place to place to fetch the file on the right. It is obvious that it will take longer to access the file on the right. The more pieces the file is broken into, and the further apart those pieces are scattered on the hard drive, the longer it takes for the read-write head to retrieve it, which results in slower performance.

disk defragmentation

Besides file fragmentation itself, there is the issue of free space fragmentation, which in turn causes more file fragmentation. This usually occurs when data gets deleted leaving small sections of free space scattered in-between remaining files. The result is that when new files get saved to the hard drive, the system breaks them up into pieces to fit in these small sections of free space.


How Disk Defragmentation Works

  Now that you know all you need to know about hard drives, file system and fragmentation, we shall move on to the main subject of this article, which is disk defragmentation. I hope it is clear why it is necessary to defragment your hard drive. This operation not only helps put file pieces back together, but can also consolidate free space so that there are larger blocks of space available to write new files thus preventing further fragmentation. A good defragmenter will also include an algorithm for smart file placement that utilizes the knowledge of faster and slower data access zones on the hard drive. Let’s take a closer look at these aspects of disk defragmentation.


File Defragmentation

  In simple terms, file defragmentation is the process of putting file pieces back together. What disk defragmenters do is re-write files into contiguous blocks of free space making sure that all file fragments are written in a consecutive order. This way the hard drive's read-write head has to go to one location to access the requested file instead of having to gather file pieces all over the drive.


Free Space Defragmentation

  Defragmentation, or consolidation, of the free space on a hard drive is one of the most effective fragmentation prevention techniques. When free space is in large contiguous blocks instead of scattered around the hard drive in smaller sections, new files that get written to the hard drive can be easily placed in one piece. When rewriting files during disk defragmentation, defraggers try to place all files closer together so that the remaining free space is consolidated into larger sections.


Smart File Placement

  Knowing how a hard drive operates and how data is stored and accessed on it, you can more easily understand the theory behind smart file placement. There are actually more than a few ways files can be placed on a hard drive with the intent of improving system performance. Different defragmenters may use different techniques or algorithms for placing files, some offering a choice of algorithms a user may pick to match their individual PC usage style.

Defragmenters may try to keep together the files that are normally accessed together, such as a group of .dll files needed when an application is launched. This greatly reduces the amount of work the HDD's read-write head needs to do to when these files are requested. Placing system files to the fast outer tracks of the hard drive reduces the time it takes for your system to start up, as well as for applications to launch. This fast zone on the hard drive can also be used to place most frequently accessed files improving the speed of everyday tasks. At the same time, moving rarely used files to the back of the drive (the slower inner tracks) ensures they are out of the way and don't take up valuable free space in the fast zone.


  As you can see, disk defragmentation is not just putting file fragments together, there is so much more to it. All of the various techniques used in defragmenters offer great potential for improvement of system speed and performance. People who proclaim that defragmentation is not needed with modern hard drives may not have tried a modern defragmenter with a powerful optimization engine. Anyone who uses their PC a lot, editing, saving and deleting files, installing and uninstalling software, playing computer games or working on long-term school projects will definitely notice an improvement in their computer's performance after using feature-rich defragmentation software on it. As they say, seeing is believing. Try defragmenting and optimizing your hard drive to see what difference it can make in your PC's performance.

Did you like this article?
4054 people rated the article "Disk Defragmentation Explained". Article rating: 4.93.

It’s a pity you didn’t like the article

Please tell us what’s wrong with it. Be specific, and we’ll do our best to make the necessary changes

Thanks for reading!

Hey, but don't keep this article a secret - share it with your friends!
Like Us on Facebook!

About the Author

Anna Lind Anna Lind
Anna's passion is helping novice users understand computers and software better.

Discussion

This helped me realize that I have desperately need to run regular disk defrags. I've only defraged my computer once since I got it and that was about 7 months ago and I'm a heavy gamer and I run programs that are demanding on my laptop. Thank you for being so helpful.
Autumn Brandenberger
August 2nd, 2012 @01:05 am
Reply
0

Leave a comment





Fields marked with * are required.
Please note: All comments will be moderated.