How does disk defrag work?
Browse the article How does disk defrag work?
How does disk defrag work?
The word "disk defrag" is typically used to refer to the Microsoft Windows utility called Disk Defragmenter. It is designed to solve a problem that occurs because of the way hard disks store data. If you have read the article How Hard Disks Work, then you know three key facts about hard disks:
- Hard disks store data in chunks called sectors. If you imagine the surface of the disk divided into rings (like the rings of a tree), and then imagine dividing each ring into pie-slices, a sector is one pie-slice on one ring. Each sector holds a fixed amount of data, like 512 bytes.
- The hard disk has a small arm that can move from ring to ring on the surface of the disk. To reach a particular sector, the hard disk moves the arm to the right ring and waits for the sector to spin into position.
- Hard disks are slow in computer terms. Compared to the speed of the processor and its memory, the time it takes for the arm to move and for a sector to spin into place is an eon.
So let's imagine that you install a new application onto an empty hard disk. Because the disk is empty, the computer can store the files of the application into sequential sectors on sequential rings. This is an efficient way to place data on a hard disk.
As you use a disk, however, this efficient technique becomes harder for a disk. What happens is that the disk fills up. Then you erase files to reclaim space. These files that you delete are scattered all over the surface of the disk. When you load a new application or a large file onto the disk, it ends up being stored in hundreds or thousands of these scattered pockets of space. Now when the computer tries to load the scattered pieces, the disk's arm has to move all over the surface and it takes forever.
The idea behind the disk defragmenter is to move all the files around so that every file is stored on sequential sectors on sequential rings of the disk. In addition, a good defragmenter may also try to optimize things even more, for example by placing all applications "close" to the operating system on the disk to minimize movement when an application loads. When done well on older disks, defragmenting can significantly increase the speed of file loading. On a new disk that has never filled up or had any significant number of file deletions, it will have almost no effect because everything is stored sequentially already.
As you might imagine, the process of indivdually picking up and moving thousands of files on a relatively slow hard disk is not a quick process -- it normally takes hours.
|
Starting with Windows 98, the defragmenter places the data on the hard drive in the same sequence Windows uses it. The Windows 98 defragmenter also knows what programs you run the the most often, and places those on the disk so the computer can access it the fastest possible time.
The defragmenter can take a considerable time to run, so start the Defragmenter before going out for the evening or at the end of the day, before going to sleep.