![]() |
Why Defragmentation is Needed
Why defrag? The goal is efficiency. If you are defragmenting your computer for any other reason, then you've missed the point. We defrag a drive to make it more efficient. Fewer fragments mean less unnecessary work for the drive, which means better read times when a file is read or written. Since hard drives are slow compared to RAM, an efficient drive reduces waiting times, which means the computer can get the job done faster. ![]() How File Fragmentation OccursConsider any generic computer with several processes running in the background, and each process creates a log file with entries in it. If the files reside in different parts of the disk, they can usually grow without running into any other files. Eventually, though, one of the files will encounter a situation where the next available block of disk space is already in use by another file. At that point the operating system will allocate another block of space on the disk. This will be a "non-contiguous" block, i.e. not adjacent to the other ones. At this point the file is said to be fragmented. Any file that grows over time risks becoming fragmented into many non-contiguous pieces.
If the blocks of data are physically close to one another on the drive, the time taken to move the head to the correct position for each subsequent block of data (3.) is very small, i.e. insignificant. But whenever a non-contiguous block occurs, the seek time is usually much longer. Reading a file with several hundred fragments is therefore going to take longer than a file of the same length where all blocks are contiguous. So there is a mechanical performance cost associated with a fragmented file.
File PositioningIn addition to the level of fragmentation of a file, there is also the question of the location of the file on a hard drive. It is easy enough to measure the performance of a hard drive and note that the "inside" of the drive has slower read times to the "outside" of the drive. When the drive is formatted, this usually means that the lower-numbered clusters can be read faster than higher numbered ones.
Defragmenting FilesThere are times when it is best to just leave the file alone, and not worry if it is fragmented. Other times it is better to do something about it, for the sake of the PC performance and the hard drive life. How can you tell? Consider a large SQL database file, say 15GB in size. The file is fragmented into two pieces, which are separated by a tiny file that uses only one block. Given that the two file pieces are close together and the mechanical performance cost is so low, it isn't worthwhile rearranging 15GB of data to eliminate one fragment. If the database is in constant use, the extra hard drive load caused by trying to defragment the file may be far worse than the minor hiccup of one small file.
Boot-Time or Offline DefragmentationSome files are in use by the operating system from the time it loads. An obvious example of this is the Windows Page File ("pagefile.sys"). Since it is used a lot by the operating system, particularly when available RAM is low, it is best to have a single contiguous file. This led to the idea of doing a defrag of this file as soon as possible during the boot-up stage of the computer, before Windows started using the file. Another method was to create a boot disk that would allow the user to perform maintenance of the drive, while running the operating system from a different drive, such as the CD or USB memory stick. This is known as "offline" defragmentation, because the normal operating system is not in use.
Background DefragmentationAnother approach to file fragmentation is to "chip away" at the problem as a background or scheduled task. This "set it and forget it" approach means that the user doesn't have to run the defrag program manually. The problem with this approach is to determine a convenient time to run the defrag. If the PC is idle at a particular time every week, such as during a weekly management meeting, this is the obvious time to choose. Another approach is to leave the computer running all night and do the defrag in the early hours of the morning. But this uses power, which is expensive.
Optimisation TechniquesThere are twice as many optimisation techniques as there are programmers. Some techniques concentrate purely on removing file fragmentation. Others try to place the files in a more optimal position, based on one or more of a dozen factors. Some also try to allocate free space in a way that would be helpful to the user or the operating system. Some try to be as thorough as possible, while others adopt a more pragmatic approach, defragmenting files where this could improve performance.
Drive UtilisationAs a drive fills up with data, the effects of fragmentation become more obvious, and general system performance also slows down. Newer Windows systems change the colour of the drive information when space is getting low, typically 90% full. Some commercial defrag programs become ineffective at around 75%, or when the available free contiguous space is less than the size of the largest file to be defragmented. Some programs try to minimise the amount of file movement that needs to be done, by figuring out what to do in a single pass. Others try a multi-pass approach. What about RAID drives?Defragmentation of RAID drives is required if the files are not contiguous and they are causing performance problems. Bear in mind that the data in a RAID5 array is spread over 5 drives, so a badly fragmented file could cause all 5 drives to work harder. Defrag utilities work at the logical file system level, not the physical level. When you are defragmenting a RAID drive, you are also causing a lot more hardware work to be done, because of all the error correction and redundancy work that goes on. A more pragmatic approach is called for. In fact this applies to server hard drives in general. What about USB Hard Drives?The USB interface to the hard drive slows down the data transfer rates to a crawl, so you shouldn't bother too much about trying to improve USB drive performance by defragmentation, especially if the drive is being used for archives or backups. A light defrag pass and optimising the directories is all you are likely to need. This will improve the performance from dreadful to awful, and may prolong the life of the drive a bit. Just make sure you don't let the drive overheat, or you can kiss your data goodbye. See AlsoSee the article on "Before You Defrag Your PC" for advice on speeding up your PC and reducing risk.
blog comments powered by Disqus
| ||
|