Why defrag?

Published on 03/02/2010 by in Pre-7 Windows, Windows

27

Windows 98, Windows Me and Windows XP come with a collection of house cleaning tools, including ScanDisk, Disk Defragmenter and Disk Cleanup, to help keep your disk in peak working order.

Why should you bother with the housework? A couple of reasons. First, disks are hard working, mechanical devices and, like all mechanical devices, prone to failure. A little preventative maintenance can warn you of potential problems and fix minor glitches before they can do damage to your data.

Second, the way files are organised on your drive has a perceptible impact on the performance of your computer. If your files are stored neatly, end-to-end, without fragmentation, reading and writing to the disk is speedier.

What is file fragmentation?

Sometimes when you install a program or create a data file, the file ends up chopped up into chunks and stored in multiple locations on the disk. This is called fragmentation.

What makes this happen?

When you first install your operating system and programs on your hard disk, they are written to the disk, for the most part, in one contiguous block without any gaps. The exceptions are certain system files that must be stored in specific locations. Over time, as you create and then delete documents or uninstall programs, once-filled locations are left empty and you end up with files dotted all over the disk.

Now, when Windows is writing a file to the disk, it looks for a suitable piece of free space in which to store it. What happens, then, when you copy a 40MB database or a 100MB video clip to the disk and the biggest slice of free space is only 30MB? Or say you modify an existing file, appending a whole bunch of data so the file now takes up more space on the disk. To accommodate the files, Windows writes the first part of the file in one section of the disk and then scouts around for other places to store the rest of the file. The end result is that a single file may be stored in several chunks scattered about the disk.

Of FAT and files

Your operating system needs to have a way of keeping track of each file’s location. Windows 98 and Windows Me use a system called FAT32. The ‘FAT’ stands for File Allocation Table. When your file is written to disk, FAT32 provides Windows with the address of an unoccupied disk cluster. FAT32 also tells Windows on which disk sectors it will find that cluster; that is, it provides the physical location of the cluster. This information is used by your PC’s BIOS (the Basic Input/Output System) to direct the actual disk writing operation.

If the file is too large to fit in a single cluster, Windows asks FAT32 for another vacant cluster, and another, and another until the whole file is written to disk. If you have lots of free clusters side by side, FAT32 can point Windows to an adjacent series of clusters, resulting in a file which occupies one contiguous chunk of the disk. If no adjacent cluster is available, FAT32 tracks down a space elsewhere on the disk and tells Windows to put the next bit of the file there; and so on until the full file is written to disk.

A record of the clusters used for storing the file is kept by FAT32 so Windows can find the file once more when you want to read it.

Windows XP does NTFS

FAT was introduced in the pre-Windows days when we used an operating system called DOS (Disk Operating System). When Windows 95 appeared on the scene, it originally used FAT, but with Service Pack 2 it shifted to FAT32. More recent versions of Windows don’t use FAT at all; they use NTFS, a file system developed for the server operating system, Windows NT.

When it comes to file systems, Windows XP is a fence sitter. If you install it from scratch it will, by default, use NTFS. But if you upgrade an old computer running Windows 98 or Me to Windows XP, XP inherits the old FAT32 file system, giving you an option to convert to NTFS. NTFS is more reliable and more efficient than FAT32, so in most cases it makes sense to use it.

The fragmentation penalty

Although this all happens quickly, it makes a lot of work for your hard disk. Its read/write head, which moves across the drive platter from location to location transferring data, has to zip all over the place when saving or opening a single highly fragmented file. (By the way, many disks have more than one read/write head and multiple platters.) If a file is unfragmented, the disk head moves to one location, reads the file in one sequential swoop, and that’s it.

A file stored in, say, four fragments, can easily take twice as long to open as the same file unfragmented, although the actual performance hit you take is affected by other factors, including the total size of the file.

Defragging

There’s a simple solution to file fragmentation: use Windows Disk Defragmenter. To do so, click:

Start –> (All) Programs –> Accessories –> System Tools –> Disk Defragmenter

This utility, commonly called Defrag, gathers all the scattered file fragments and writes them into adjacent clusters, so each file occupies an unbroken section of the disk.

NTFS, XP and defragging

From a defragging perspective, it doesn’t matter whether your operating system is FAT32 or NTFS, you still need to defragment. Windows XP’s Disk Defragmenter looks a little different from the one you’ll find in Windows 98 and Windows Me, but it works in a similar way. XP’s Defragmenter is somewhat smarter than its predecessors and isn’t as easily thrown off its stride by background programs.

Defrag works by moving slabs of data to unused parts of the disk, in order to open up a large free section of space. It then assembles the fragmented parts of a file and writes them in one complete piece to the cleared space; it then does the same with the next file; and so on until the entire disk is defragmented.

Powerful alternatives

The built-in Disk Defragmenter is a utility which has been hobbled by the rapid advance of drive technology. It works just fine on a disk of 8G or so; but use it on a 20G drive or – if you dare – an even larger drive and you can say goodbye to using your computer for the most part of a day. Although Microsoft says it’s okay for you to use your computer while defragging, in practice this rarely works, because every write to disk causes Defrag to restart.

If you’d like to speed up Defrag and eliminate some of its problems, try one of the commercial defraggers. They’re far more at home with large hard drives, run on all versions of Windows from XP onwards, and they provide a less frustrating experience. Some of the alternatives are:

Defrag goes auto in Vista and Windows 7

With Vista and Windows 7, defragging happens automatically in the background whenever your computer is idle. If the defrag process is interrupted, it will resume the next time your computer is sitting idle. So for most Vista and Win 7 users, defragging becomes a non-issue.

Step-by-step: Efficient defragging

  1. Defrag works most efficiently when your drive has ample space for its operations. If you run Defrag with a drive that’s chockablock, it must work like mad simply to clear enough space to start writing files. So it pays to delete all unnecessary files before you start defragging. Uninstall unwanted programs, archive old data, delete unwanted backups, and then run Disk Cleanup (Start –> (All) Programs –> Accessories –> System Tools –> Disk Cleanup).

  1. Defrag also works best when completely uninterrupted. Background programs such as Task Scheduler and anti-virus software can cause Defrag to stop and restart repeatedly. To avoid such interruptions, do a clean boot before running Defrag:
    a. Click Start –> Run, type msconfig in the Open box and click OK to open the System Configuration Utility.
    b. On the General tab, click Selective Startup and remove the ticks beside Process System.ini File, Process Win.ini File and Load Startup Group Items. (On some versions of Windows you may also see Config.sys, Autoexec.bat and Winstart.bat options – remove the ticks beside these as well).
    c. Click OK and allow your computer to restart.

  1. Once you’ve cleaned out unnecessary files and stopped background programs from loading, you’re ready to defrag:
    a. Click Start –> Programs –> Accessories –> System Tools –> Disk Defragmenter.
    b. Select the drive you wish to defrag.
    c. Click Settings and make sure there’s a tick beside the two options in the section When Defragmenting My Hard Drive, then click OK twice to begin.
    d. After Defrag has finished, open the System Configuration Utility once more, click Normal Startup on the General tab, click OK and reboot.
  • samsun

    Nice article. I second that third party tools are more powerful than the built in defragger, in terms of speed and ability to defrag severely cluttered drives. My preference is the first of the three above mentioned programs. Its excellent in the automatic mode and also has amazing advanced features.

  • samsun

    Nice article. I second that third party tools are more powerful than the built in defragger, in terms of speed and ability to defrag severely cluttered drives. My preference is the first of the three above mentioned programs. Its excellent in the automatic mode and also has amazing advanced features.

  • samsun

    Nice article. I second that third party tools are more powerful than the built in defragger, in terms of speed and ability to defrag severely cluttered drives. My preference is the first of the three above mentioned programs. Its excellent in the automatic mode and also has amazing advanced features.

  • Bridget

    I really liked your why defrag article. When things are explained in plain English it is so much easier to understand. I checked out the software companies you recommended. Diskeeper is having a Memorial Day sale on their defrag software. It’s $10 off until 6/4/10. I thought I would share. Here is the link: http://www.diskeeper.com/products/products.aspx

  • Bridget

    I really liked your why defrag article. When things are explained in plain English it is so much easier to understand. I checked out the software companies you recommended. Diskeeper is having a Memorial Day sale on their defrag software. It’s $10 off until 6/4/10. I thought I would share. Here is the link: http://www.diskeeper.com/products/products.aspx

  • Bridget

    I really liked your why defrag article. When things are explained in plain English it is so much easier to understand. I checked out the software companies you recommended. Diskeeper is having a Memorial Day sale on their defrag software. It’s $10 off until 6/4/10. I thought I would share. Here is the link: http://www.diskeeper.com/products/products.aspx

  • KAL

    great article, I have 2 hard drives on my pc.. (C) drive defrags without a problem, but my (D) drive is Fat32, Capacity 5.68GB, Free space 657MB , % Free Space 11%, but whenever I want to defrag, it comes up telling me I need at least 15% free space to defrag, or do I want to do it anyway, which I never choose….. so in your opinion, would you defrag it anyway? I dont know whats installed on it, so far my XP is working fine, thanks for your help, kal

  • http://www.geekgirls.com Rose Vines

    Kal: If things are working smoothly, I think I might be inclined to leave well enough alone.

    Is that D: drive possibly a backup partition created by the computer maker? If you don't know what's on it and it's only 5.68GB in size, it's quite likely that it's simply there to hold a backup copy of your original system installation. In that case, you really should just leave it alone; you certainly don't want to go deleting files from it to make room to defrag if you don't know what those files are.

  • kal

    thankyou Rose, my thoughts exactly, I believe all my original system installation is on the D drive as you stated, recently due to that nasty virus few months ago, I had to do a full system recovery 🙁 and it returned to the same 11% space available…….so I will leave well enough alone, lol…

  • Nospam

    doesn't a multitasking system with say … 10 disk accessing processes negate the concept of head seek per process since, at any time, a process readinga disk track may have its time slice expire and another process, reading disk, will move the head away to its required track? In this example, does defragmentation add any value?

  • http://itshrunk.com/cd4340 Patricia

    Thanks for this article. Simple and to the point. It is frustrating when you are given mumbo jumbo directions to do something. Yours was extremely easy for us who do not understand all the techie stuff. Thanks again.

  • Pingback: Defragment my computer | Kappeetc()

  • GeekBoy

    Multitasking doesn't really help; in fact with ten processes reading, if the files are of any significant size, it probably hinders.

    Fragmented files, especially large ones broken into lots of small fragments, are slower to retrieve from a disk than sequential files due to the amount of time the disk spends just “spinning” without doing any useful work, whilst the heads are seeking to the start of the next fragment.

    Most processes block when they are waiting to read file data. Each request for a file gets put in a queue (the hard disk controller's queue). There is only one hard disk controller, so if ten processes all ask for a different file at the same time, all ten processes will block and the hard disk controller then has to go away and seek out each file (or part thereof) as quickly as it can.

    One consequence of this is that for large files it may be faster to let each process run sequentially, so the hard disk controller can concentrate on getting all the data from one part of the platter before moving the heads to another region to get the next file. Otherwise the hard disk ends up spending most of its time seeking (also known as “thrashing” because of the loud noise the old drives used to make when the heads moved frantically).

  • Nospam

    Thanks for your input …
    Let me try and clarify …
    1. I did not mean to imply that multi-tasking “helps” or supports the defragging argument. I said it “negates” the argument.
    2. The concept of thrashing is clear. What I was trying to illustrate is that multiple processes (execution threads) in a time-sliced multi-tasking environment (like Windows NT and beyond) stop executing when their time slice expires. If a stopped process was performing disk access then the excution context is saved and the next process continues its execuiton in a previous saved context. If the previously saved context was in the middle of a disk access (with a single controller) then the heads may (and likely would) move to a new location. Hence – thrashing.
    3. I'll make one argument for defrag – if the buffer size is large enough and the system is fast enough, then and entire file may be loaded into space reserved for a process if the file is contiguous on disk. In that case (unlikely on moany machines) then a return to that context after slicing would _not_ result in a head position change.
    4. The concept of letting each process run sequentially on a modern, Windows-based system is not strictly supported by architecture. It would defeat the concept of multiple execution threads which is where the “general” computing systems are heading (Intel, AMD support this on-board)

    Thanks again for your input.

  • http://steamcommunity.com/id/snowman345 ($S360)~§ηǿwӍ@η345²~

    this is a very useful article, i defragged my pc for the first time today and it took 5 hours o_0

  • Andre

    I have no problem using Windows while its defragmenter is running. So I'd like to ask if there is any advantage in other similar tools for this purpose. Thanks.

  • http://www.geekgirls.com Rose Vines

    My feeling is if it's working for you, there's no need to change things. Other defraggers may offer better performance and more control over the defragmenting process, but if you're satisfied with your current setup, there's no real need to use anything other than Windows' built-in defragger.

    I find in Windows 7, where defragging is done automatically in the background, it becomes a complete non-issue.

  • http://varisphere.blogspot.com Varisphere

    Thanks for the article. Simple and easy to understand.

    I wonder about the bad sector on disk; Is it not affecting defragment process? (because you are not mention it)

  • http://twitter.com/jingle000 Jingle Karen Rhodes

    I keep defragging a 20gb hard drive in my Compaq EVO. Toward the end of the resolution bar, when the defragging is finished, there is a huge blank space…then some more files. How do I erase this blank space?

  • Michelle

    Absolutely there is: I keep three programs to hand on a USB flash drive, jkgefrag (gui version – this means graphical user interface, easy to use), ccleaner, and windirstat.

    jkdefrag uses the windows defrag routines, but it also finishes by by re-organising the files on the disk. Note: If there isn’t enough space it’s still worth doing, it just means some larger files won’t get defragged.

    Ccleaner is extremely powerful, use it carefully – simply allowing it to clean up and empty all the caches for your browser may give you a Gb or more of space which can help with your defrag.
    Cleaning the registry can dramatically improve your speed. It is simply a data-base of info about everything on your computer – in time it becomes massively bloated with redundant links and slows everything down. Make a restore point first.

    Windirstat is brilliant. It simply shows you, in graphical form, how the space is being used up. You will often find there are multiple installation downloads of, for example, java. Each one can be 100 Mb and the older ones can be deleted. Just hover and click, and get to know where stuff is. If in doubt, google the name and check up before deleting. Now do a defrag.

    These programs are all free.

    Finally, do you really need to install? If you search for ‘portable’ Open Office etc. you will find there are now dozens of programs which you do not have to install (including browsers). Each is contained in a folder which can be on the hard drive, or on a USB drive to be carried around. Usually they leave no trace when they are closed. I have one XP computer which (with v few exceptions) has only portable apps installed. It is my main work machine, it is quite old, and it still opens in 17 seconds!