Defragmenting Your Pagefile
by Mitch Tulloch, author of Windows Server Hacks11/23/2004
Defragmenting your hard drive regularly is an important part of general system maintenance for Windows XP machines, and the Disk Defragmenter tool in Computer Management lets you do this easily. (You can also get to the Disk Defragmenter tool by choosing Control Panel-->Performance and Maintenance-->Rearrange items on your hard disk to make programs run faster.) But what about defragmenting your pagefile?
Windows dynamically resizes your pagefile as needed to ensure there is sufficient virtual memory to meet the needs of running applications, and as a result of this resizing, it is possible that your pagefile can become fragmented over time, which can slow performance of your machine. Unfortunately, the Disk Defragmenter tool doesn't defragment the pagefile, and you might be tempted to buy a third-party disk defragmenter to do this. However, you can save your bucks by following this simple procedure to defragment your pagefile.
First, here's a look at the fragmentation of the C: drive on my XP machine just before I defragmented it:

Figure 1
After running Disk Defragmenter, the fragmentation of this drive is much reduced:

Figure 2
Let's look at the report generated by Disk Defragmenter to see the condition of the pagefile:
Volume (C:)
Volume size = 4.00 GB
Cluster size = 4 KB
Used space = 2.59 GB
Free space = 1.41 GB
Percent free space = 35 %
Volume fragmentation
Total fragmentation = 0 %
File fragmentation = 0 %
Free space fragmentation = 1 %
File fragmentation
Total files = 12,927
Average file size = 259 KB
Total fragmented files = 0
Total excess fragments = 0
Average fragments per file = 1.00
Pagefile fragmentation
Pagefile size = 767 MB
Total fragments = 3
Folder fragmentation
Total folders = 863
Fragmented folders = 1
Excess folder fragments = 0
Master File Table (MFT) fragmentation
Total MFT size = 14 MB
MFT record count = 13,815
Percent MFT in use = 99 %
Total MFT fragments = 4
Note the small degree of pagefile fragmentation (3 fragments). Because of the way Windows XP manages the pagefile swapping large blocks of data, the pagefile usually doesn't become very fragmented, even on heavily used machines. It can become defragmented enough, though, to affect system performance.
To defragment the pagefile, we first have to remove the pagefile, then defragment the machine, and finally recreate the pagefile. To do this, start by opening the System utility in Control Panel. (You may have to get there by clicking Performance and Maintenance from the Control Panel and then clicking System.) Then select the Advanced tab, click the Settings button under Performance, select the Advanced tab of Performance Options, and click Change to view your Virtual Memory settings:

Figure 3
Now select the No Paging File option and click Set. This will disable paging entirely and should also remove the pagefile (pagefile.sys) from the hard drive the next time you reboot your system. (If it doesn't do this, you can delete this file manually after rebooting. It's normally found in C:\.)
Reboot your machine, and when Windows comes up, use Disk Defragmenter to defragment the volume where your pagefile was previously (C: drive in my example). Once your system is defragmented, open the Virtual Memory box again, and change the pagefile back to System Managed Size. Then, reboot your machine again. This time, when you run Disk Defragmenter, it should say your pagefile has only one fragment. When I ran Disk Defragmenter on my machine after performing these steps, the result was this:

Figure 4
Note that the pagefile (green area) has been moved to the end of the volume (an added bonus to reduce future file fragmentation). Also, as expected, the report generated by Disk Defragmenter indicates there is now no fragmentation of the pagefile:
Volume (C:)
Volume size = 4.00 GB
Cluster size = 4 KB
Used space = 2.59 GB
Free space = 1.41 GB
Percent free space = 35 %
Volume fragmentation
Total fragmentation = 0 %
File fragmentation = 0 %
Free space fragmentation = 0 %
File fragmentation
Total files = 13,194
Average file size = 254 KB
Total fragmented files = 10
Total excess fragments = 32
Average fragments per file = 1.00
Pagefile fragmentation
Pagefile size = 767 MB
Total fragments = 1
Folder fragmentation
Total folders = 865
Fragmented folders = 1
Excess folder fragments = 0
Master File Table (MFT) fragmentation
Total MFT size = 14 MB
MFT record count = 14,084
Percent MFT in use = 99 %
Total MFT fragments
For more tips on optimizing use of your pagefile, see my previous article Optimizing Your Servers' Pagefile Performance on WindowsDevCenter.
Mitch Tulloch is the author of Windows 2000 Administration in a Nutshell, Windows Server 2003 in a Nutshell, and Windows Server Hacks.
Return to the Windows DevCenter.
-
FREE Pagefile.sys Defrag from Microsoft
2009-06-02 11:35:01 alkaline-water [View]
-
Damn near had a heart attack...
2008-07-26 00:45:16 valorail [View]
-
pagefile.sys still in 3 fragments
2007-11-21 23:22:49 riegal [View]
-
got DK to defrag
2007-03-22 10:14:51 turpid [View]
-
defragmenting in general
2006-07-03 13:16:14 cookie175 [View]
-
Help
2006-06-29 06:58:57 rbcb [View]
- Trackback from http://truegrit.weblogs.us/archives/whats_what.html
What's What
2005-10-21 22:38:31 [View]
-
Defrag continued
2005-05-31 13:17:37 JENNIFERRAYEM [View]
-
defragmenting my pagefile
2005-05-31 12:13:16 JENNIFERRAYEM [View]
-
Slightly more than 3 fragments on my drive me thinks.
2005-04-04 05:56:35 penguin666 [View]
-
Slightly more than 3 fragments on my drive me thinks.
2005-06-01 04:07:42 Wierdy1024 [View]
-
Slightly more than 3 fragments on my drive me thinks.
2008-04-03 23:17:31 ashu kumar [View]
-
loose performance
2005-02-03 04:24:41 valko [View]
-
Freeware alternative
2004-11-24 11:18:54 ecloninger [View]

