Defragment pagefile and registry hives in Windows
Having a fragmented virtual memory page file, hibernation file or registry hives can effect the performance of Windows in several ways. This guide covers a simple (and free) way to defragment the paging file (pagefile.sys), hibernation file (hiberfile.sys) and the registry hives. Disk defragment applications like Smart Defrag that run in Windows cannot defragment these files because they are protected and in use. Using PageDefrag from Sysinternals however, these files can be defragmented early in the Windows boot.
Introduction & Requirements
|Software you must download and install|
|Required: You need to download PageDefrag from AfterDawn. It is in a ZIP file so you will have to extract the executable from it. Download|
After you download the ZIP file from AfterDawn, extract the pagedfrg.exe file from the archive (move it to a normal folder). PageDefrag supports Windows 2000, Windows XP and Windows Server 2003 (32bit only). It does not officially support Windows Vista or Windows 7 just yet due to the need to install a driver.
PageDefrag can be downloaded contained in a ZIP file from AfterDawn, and it is also included in the Sysinternals Suite which is also worth a download. When you have extracted it from either download, run the pagedfrg.exe file.
Sysinternals License Agreement
When you run PageDefrag (and most Sysinternal GUI applications) for the first time, you will have to accept the End User License Agreement (EULA). When you click the Agree button, the software will write a new DWORD value (EulaAccepted with a value of 1) to the Windows registry key HKCU/Software/Sysinternals/PageDefrag/. Unless this is manually deleted, Desktops should now ask you to accept the EULA again when you launch it. Other Sysinternals software will still prompt the user to accept the EULA at first use however.
Click Agree when you are ready and the PageDefrag interface should display immediately in a small window.
PageDefrag can tell you very quickly if your pagefile, hibernation file or registry hives are fragmented. In the example picture, the System registry hive shows in 15 fragments on the disk. PageDefrag can defragment the registry hive file itself so that it is in only 1 fragment which is the optimal state.
However, do not misunderstand what PageDefrag does. It will only defragment the file (that is change locations of fragments of the file on the disk), it will not actually defragment or optimize the registry contents in any way. Different software is used to achieve that goal instead such as NTREGOPT.
The best performance increase from PageDefrag can come for low resource systems with a heavily fragmented paging file. PageDefrag will always attempt to get files into 1 fragment, but this might not always be possible. For that reason, it is recommended to defragment the system volume (that contains Windows) with a tool like Smart Defrag first (a guide for that is available here). However, it is fine to only do this if you cannot get your page file into 1 fragment with PageDefrag.
Now, under Defragmentation Control, you will see two options. Defragment at next boot will run PageDefrag just once when you reboot the computer, and Defragment every boot will run PageDefrag during Windows boot every single time. Choose the first option (Defragment once at next boot) and click OK to install the driver.
Once you have done that, you can reboot your computer.
PageDefrag in action
PageDefrag will load in a blue screen (not a bad blue screen) during Windows loading. You will see it going through the list of files like above, checking whether they are in more than 1 fragment. If they are, it will attempt to defragment them. A heavily fragmented pagefile.sys can take quite a while to fully defragment due to its size.
Remember that if you fail to get pagefile.sys into 1 fragment you should clear out temporary files and other junk from your disk (guide for that here), delete any unwanted files that you may have downloaded in the past and then run a program like Smart Defrag (guide for that here) for the best chance of having enough continuous free space for the paging file to be in 1 fragment the next time you run PageDefrag.
Checking if it worked
After your computer boots up again, you can run PageDefrag and it will check whether the system files are fragmented. Hopefully you will see the same thing as I do in the picture above; all files existing in just 1 fragment.
You should check PageDefrag every now and then as it is not uncommon for these files to become fragmented over time, especially if you have had problems with your file system.
Uninstalling the driver
If you decide you want to remove the PageDefrag driver altogether for whatever reason, you can do so by running PageDefrag and selecting the Don't Defragment (uninstall) option. Click OK and it will uninstall.
Thanks to Mark Russinovich and everyone involved with Sysinternals for this, and all the other wonderful tools that have been provided over the years to make life that bit better. If you require any assistance or want to talk about the issues in this guide, please visit our Discussion Forums for help.
Written by: James "Dela" Delahunty
Last updated: 17 August 2010
Last updated: 17 August 2010