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.
You must be logged in to the O'Reilly Network to post a talkback.
Showing messages 1 through 13 of 13.
-
Damn near had a heart attack...
2008-07-26 00:45:16 valorail [Reply | View]
I did as you said, went in, set the page file, rebooted...And what happens? I can't do anything. I was no longer able to access the internet, run any program, or attempt to finish going through with, or undo, what I had already done. I thanked god that I have two computers that are linked to each other, so that I could fix the problem.
-
pagefile.sys still in 3 fragments
2007-11-21 23:22:49 riegal [Reply | View]
Followed the steps outlined in the article. Had to manually delete the pagefile.sys. After rebooting Disk Defragmenter Analyze showed pagefile.sys in 2 fragments. After Disk Defragmenter Defragment pagefile.sys in 5 fragments. And Sysinternals Pagedefrag says the pagefile.sys is as contiguous as possible. Is this normal? My computer use to show the pagefile.sys in 1 fragment. Thank you for any information you can provide.
-
got DK to defrag
2007-03-22 10:14:51 turpid [Reply | View]
Curently i have got the latest version of Diskeeper running on my network. I find it unobtrusive and smooth, i think it was a neat buy for me.
-
defragmenting in general
2006-07-03 13:16:14 cookie175 [Reply | View]
I have a question rather than an answer. I've just finished the disk defrag and at the end it says Total MFT fragments = 3 Is that OK? but below that it says "Files that cannot be defragmented - 2 file size is 195KB \system Volume Information\_restore{549de61-ccd3..... and gives a whole long file name ended by a .sys, Is this something that needs to be cleaned up, fixed?
-
Help
2006-06-29 06:58:57 rbcb [Reply | View]
I tried the "defrag your pagefile" on my notebook. It is not used as a server. 15 G HD. free mem 23%. Now my pagefile is 1.2 G and has 250+ fragments.
Is this normal?
-
Defrag continued
2005-05-31 13:17:37 JENNIFERRAYEM [Reply | View]
this is a copy of my defrag
Volume (C:)
Volume size = 9.54 GB
Cluster size = 4 KB
Used space = 3.72 GB
Free space = 5.82 GB
Percent free space = 61 %
Volume fragmentation
Total fragmentation = 0 %
File fragmentation = 0 %
Free space fragmentation = 0 %
File fragmentation
Total files = 17,900
Average file size = 325 KB
Total fragmented files = 1
Total excess fragments = 17
Average fragments per file = 1.00
Pagefile fragmentation
Pagefile size = 479 MB
Total fragments = 1
Folder fragmentation
Total folders = 1,544
Fragmented folders = 1
Excess folder fragments = 0
Master File Table (MFT) fragmentation
Total MFT size = 32 MB
MFT record count = 19,467
Percent MFT in use = 59 %
Total MFT fragments = 2
--------------------------------------------------------------------------------
Fragments File Size Files that cannot be defragmented
None
how do get both of the green blocks together, at the beginning of the drive?
-
defragmenting my pagefile
2005-05-31 12:13:16 JENNIFERRAYEM [Reply | View]
I noticed that my defrag barely dedfragged. I tried to coax it by removing programs, defragging in safemode, using command line, /f
everything. I was concerned, because when I got the PC, the previous owner got locked out, her password did not work, so she installed XP HOME
over XP, and a previous NT. I have gone through deleting what seemed to be from previous files in C: only had a couple of programs, mainly spyware-related, Zone Alarm, and Kaspersky Anti-virus, and still only had 50% on C: available, not to mention I wanted to scan any files on the pagefile as well. I figured out how to eliminate the pagefile on my own, rebooted, then ran clean system, anti-virus etc; and found and deleted the culprits. defragged again, and this time there was a dramatic improvement in my disk.
without the page file I am at 69% and with it 61%
the problem is this. Even without the page file,
a green block of immovable data appears, MFT files? then when I reenable the pagefile, set to
system designates, 2 green blocks appear. And the setup is contiguous files, blue, white space, green ( pagefile) white smaller block of green MFT? then a small block of contiguous files at the end. I also cleaned all the free space with Window Washer x32 on the bleach several times on the free space in between defrags, and it did seem to do some good. Now I need to know how to get rid of MFT if necessary, so that it comes back up as originally, with the green page or swap file, and at the beginning as opposed to at the end?
-
Slightly more than 3 fragments on my drive me thinks.
2005-04-04 05:56:35 penguin666 [Reply | View]
Volume M354G4 (C:)
Volume size = 110 GB
Cluster size = 512 bytes
Used space = 79.87 GB
Free space = 30.09 GB
Percent free space = 27 %
Volume fragmentation
Total fragmentation = 33 %
File fragmentation = 66 %
Free space fragmentation = 0 %
File fragmentation
Total files = 62,539
Average file size = 2 MB
Total fragmented files = 5,309
Total excess fragments = 2,305,860
Average fragments per file = 37.87
Pagefile fragmentation
Pagefile size = 768 MB
Total fragments = 26,735
Folder fragmentation
Total folders = 6,116
Fragmented folders = 135
Excess folder fragments = 863
Master File Table (MFT) fragmentation
Total MFT size = 601 MB
MFT record count = 83,262
Percent MFT in use = 13 %
Total MFT fragments = 9
--------------------------------------------------------------------------------
Fragments File Size Most fragmented files
65,497 799 MB \Documents and Settings\Me\Desktop\somehting.avi
26,735 FRAGMENTS!!!
Surely that must be some sort of record.
How has my computer got this bad I just don't understand. Only had it for 2 years. Disk defragmentor just gives up after about 4% and it does absolutely nothing. I now have Raxco Perfect Disk. An offline defragment takes 3 hours to analyse then after another three hours it doesnt even get past defragmenting the first file (I guess its the page file).
penguin666
-
loose performance
2005-02-03 04:24:41 valko [Reply | View]
there is a major drawback of putting page file at the end of the drive - more seek time and you will loose performance I think - it is much better page file to be at the begining of the hard drive. So I use completely different strategy - after fresh OS install make page file min And max settings equal with size about 2.5 your memory - or use some commercial software for settings/defrag like Norton System Works, Diskeeper etc.
-
Freeware alternative
2004-11-24 11:18:54 ecloninger [Reply | View]
There is a freeware pagefile defragmenter available at www.sysinternals.com. I've been using it for several years on NT/2000/XP with no problems. It does not require you to turn off virtual memory and it does it's job requiring only one reboot.










This is a FREE routine from Microsoft sysinternals that will defrag pagefile.sys *and* all internal system file. WORKS GREAT......plus it's FREE