Fragmented Files


About the Windows Defrag Utility

What is the purpose of a defragmentation program?

When a file is created, MS-DOS tries to store all of the data end to end in a contiguous location on the disk. As other files are created, they are placed immediately behind the previously created file. However, if a file is subsequently modified, it may need more disk space than it originally got. If MS-DOS cannot find enough contiguous space to hold the modified file, it stores the excess in a noncontiguous location. This concept is illustrated below using numbers to represent a file clusters:

1111111 When file 1 is first created, all of its clusters are contiguous.
1111111222222 When file 2 is created, it is placed right behind file 1 and is still contiguous.
111111122222211 If the size of file 1 is later increased, its clusters must be separated because file 2's clusters are in the way and there is no room to store all of file 1's clusters together.

This separation of a file's parts, called fragmentation, is not a big problem because the FAT maintains a record of the location of each file's clusters. However, if a files individual clusters are noncontiguous (i.e., they are spread all over the disk surface and separated by the clusters of other files) the read/write heads have to spend extra time moving from track to track looking for all the bits and bytes needed to load the file into memory. The result is a degradation in disk operations.

DEFRAG makes the clusters in fragmented files contiguous. It does this by copying each of the fragmented file's clusters to an unused portion of the disk. It then rewrites the data back to disk so that all of the file's clusters are contiguous (continuous).

A defragmentation program like DEFRAG offers the following benefits:

  • Speeds up file access and improves disk operations.

  • Increases the chances for full recovery if a file is accidentally deleted.

  • Increases the disk space available for a swap file.

What is DEFRAG and when should it be used?

Picture a stack of papers on a desk.  To organize them properly they have to be collated into a logical order.  If you did not do that you would have to keep jumping back and forth through the stack to read a complete file.  Defragmentation is essentially the collating process.
DEFRAG is the Windows disk optimization utility. Over time the files on a disk can become "fragmented" meaning that the pieces of a file are stored on the disk in separate, noncontiguous clusters. While fragmentation is a normal part of disk operations and does not affect data integrity, it does take longer to read and write to a fragmented file than to an unfragmented file. In addition, if a file is accidentally deleted, the chances for full recovery are much lower if the file was fragmented.

DEFRAG reorganizes the files on a disk so they are not fragmented. As a general rule, DEFRAG should be used anytime the percentage of unfragmented files falls below 92%.

Notes:

  • DEFRAG cannot be used to optimize a network or Interlink drive
  • DEFRAG will not move system files (but it will move hidden files)

In general, SCANDISK or CHKDSK should be run before using DEFRAG.

Why do we need DEFRAG anyway?

When Windows creates a new file on your hard drive, it will search for some empty space, and save the file at that location. When a file is deleted, you will get a hole at that location which is later filled by a new file and so on.

The problem is, not all files are of the same size. The solution is to split the files into smaller equally sized parts. This way, when you delete one file and save another one, the parts of the new file will fit into the holes of free space.
This works very well, but, after a while your files will be scattered all over your hard drive. When you try to read a particular file, your computer will have to search your hard drive for all the small parts.
This will obviously take a lot of time. (Imagine trying to read a book with the pages in random order.)

When you run , all the small file-pieces on your hard drive will be reorganized so that all the parts of a particular file are stored sequentially, in one place. This can increase the speed of your system considerably! (Especially if it has been running for a long time without defragging.)

Why does DEFRAG take so long?

Depending on the degree of fragmentation in your file structure, defragmentation can be a long process.  If your drive is kept in good condition it usually completes fairly quickly.
When DEFRAG is reorganizing your hard drive, it is very important that no other programs are using the hard drive. If some program decides to save a file while you are defragging, the defragmentation process will often be interrupted and start all over again. Because of this, defragmentation may take a considerable amount of time or may not finish at all.

So, what's the solution?
To make sure that the defragmentation is not interrupted, here are a few things you should do before starting DEFRAG:

  1. Terminate all processes not critical to the system. Use the Task Manager to find out which processes to terminate. (Leave Explorer and Systray running.)
    Anti-virus programs should be stopped from within that program. (there is usually an option to temporarily disable virus scanning.)
  2. Disable screensavers or other programs starting after a few minutes.
  3. Disable any scheduled programs like virus checks.
  4. Don't use your computer while Defragging!

How Should I Defrag My Hard Drive?

There are several methods to employ in order to make the process work properly.  If you are using, Windows 98 and your drives are using the FAT32 file system, I recommend replacing your Win 98 disk tools with the Windows ME versions.  The Windows 98 versions were written for the FAT16 file system and do not work well with the different cluster sizes of FAT32.  If you are having a problem defragmenting the drive, the most likely cause is active processes on your computer.  Many of these processes cause the drive to be written to even though you are doing nothing other than the defrag.  Needless to say, working in another application at the same time is going to cause a problem.

To make sure that the defragmentation is not interrupted, here are a few things you should do before starting DEFRAG:

  1. Terminate all processes not critical to the system. Use the Task Manager to find out which processes to terminate. (Leave Explorer and Systray running.)
    Anti-virus programs should be stopped from within that program. (there is usually an option to temporarily disable virus scanning.)
  2. Disable screensavers or other programs starting after a few minutes.
  3. Disable any scheduled programs like virus checks.
  4. Don't use your computer while Defragging!

Another method is to start your computer in Safe Mode and then run Defrag.  You could also use third party software that is designed to assist you with the process.  See "Solutions" for information about programs that will do it for you.

Solutions

The solution really depends on the cause of the problem but the following is definitely a good starting point to isolate your particular issue.


Read these informative pages by Ron Badour MS-MVP
http://home.satx.rr.com/badour/html/defrag.html
http://home.satx.rr.com/badour/html/scandisk.html

You can download the latest version of GEODisk (my own software solution) from this site

http://dundats.mvps.org/Files/GEODisk.zip

 

Another excellent software solution is ScanDefrag, co-authored by another MS-MVP and two regular posters to the Microsoft newsgroups. ScanDefrag can be downloaded from;
http://home.earthlink.net/~bblanton2/scandefrag/main.htm

or from
http://www.blueorbsoft.com/scandefrag/index.html

 

You can download the Windows ME disk tools (much faster than Win98 tools) from here

http://dundats.mvps.org/Files/MEDiskT.zip