The Windows XP pagefile can become fragmented and hinder the computer's performance. Here are a few techniques you can use to better manage this file.
This article was originally published on TechRepublic March 25, 2002.
The Microsoft Windows XP pagefile is used to extend the amount of computer memory available to applications and services so that they're not limited by the amount of physical RAM installed on the computer. Because the pagefile represents an extension of your physical RAM, anything you do to optimize the performance of the pagefile will have an impact on the overall performance of the computer.
After you carry out my recommendations on pagefile fragmentation, pagefile location and performance, and pagefile security and command-line management, you should find that your Windows XP box runs faster than ever.
This blog post is also available in PDF format in a free TechRepublic download.
It takes longer to read a fragmented file. Files tend to fragment when they're added or changed in a low disk-free space environment. Also, files fragment more frequently on compressed NTFS volumes. Like any other file on a computer hard disk, the pagefile can become fragmented. However, the pagefile is immune to compressed NTFS volume fragmentation because it cannot be compressed.
The pagefile will fragment if there isn't enough contiguous hard disk space to hold the entire pagefile. This typically isn't the case when the operating system is first installed. But, by default, the operating system configures the pagefile to allocate space for itself dynamically. During the dynamic resizing, the file can end up fragmented because of a lack of contiguous disk space.
You can determine the level of pagefile fragmentation with the built-in Disk Defragmenter. Perform the following steps to see how many fragments the pagefile has been split into:
- Click Start | Run.
- In the Run dialog box, type dfrg.msc in the Open text box and click OK.
- Click the Analyze button in the Disk Defragmenter application (Figure A).
- When the Disk Defragmenter dialog box appears (Figure B), click View Report.
- In the Analysis Report dialog box (Figure C), scroll through the Volume Information box and find the Pagefile fragmentation section.
In this example, the pagefile is in three fragments.
- Click Close to close the Analysis Report dialog box.
You could improve the performance on this machine by removing the fragmented pagefile and re-creating it in a way so that it doesn't subsequently fragment. You'd do this by creating a static pagefile, which has the same minimum and maximum size. This prevents the operating system from dynamically resizing the pagefile -- it's the dynamic resizing that causes an unfragmented pagefile to become fragmented.
You can accomplish this task in two ways:
- Temporarily move the pagefile to another disk/partition.
- Use a third-party product such as Diskeeper.
Diskeeper can perform an "offline" defragmentation of the pagefile after the system is restarted. It cannot perform this task while the system is running normally. If you don't have Diskeeper, you'll need to move the pagefile off its current partition and re-create it. See what this Product Spotlight has to say about Diskeeper.
Perform the following steps to remove and re-create the pagefile:
- Click Start and then right-click the My Computer object. Click on the Properties command.
- In the System Properties dialog box, click on the Advanced tab.
- On the Advanced tab, click on the Settings button in the Performance frame (Figure D).
- On the Performance Options dialog box, click on the Advanced tab.
- On the Advanced tab (Figure E), click the Change button in the Virtual Memory frame.
- In the Virtual Memory dialog box, click on the drive that presently holds the pagefile. Click on the Custom Size option button and change the Initial Size and Maximum Size values to 0 (Figure F). Click the Set button.
Zero out the current pagefile.
- Click on another drive. Select the Custom Size option. In the Initial Size and Maximum Size text boxes, type in a value equal to the amount of RAM in the computer. Click Set and then OK (Figure G). You'll see a dialog box informing you that you must restart the computer for the changes to take effect. Click OK three times to complete the process.
Create the temporary pagefile.
- A System Settings Change dialog box will appear and ask if you want to restart the computer. Close all programs and click Yes.
- After the machine reboots, click Start | Run.
- In the Run dialog box, type dfrg.msc in the Open text box and click OK.
- Click the Defragment button in the Disk Defragmenter application. The purpose of this defragmentation run is to create enough contiguous free space to fit your new pagefile. After defragmentation is complete, click the Close button. Then close the Disk Defragmenter application.
- Go back to the Virtual Memory dialog box and put the pagefile back on the original drive. Remove the pagefile from the temporary drive (Figure H). Click OK and then click OK again in the dialog box that tells you that the system needs to be restarted. Click OK two more times and click Yes to restart the computer.
Re-create another pagefile and remove the temporary pagefile.
You can now run an analysis again using the Disk Defragmenter application to confirm that the pagefile is no longer fragmented.
Pagefile location and performance
If you want to max out your computer's memory-handling performance, you must do more to optimize your pagefile. Factors to consider when optimizing the pagefile include:
- Disk type and location
- Gauging performance
Disk type and location
There is some debate on where to place the pagefile. If you look in Microsoft TechNet, you'll see several references on this subject. From my analysis of the available literature, I submit the following recommendations:
- Place the pagefile on a dedicated disk.
- Do not place the pagefile on a RAID volume.
- Do not place the pagefile on a volume that shares the same physical disk with a busy partition, such as the operating system partition.
To get the best performance out of the pagefile, you should place it on a dedicated disk. This is especially the case on high-end systems with a large amount of RAM. If your budget doesn't allow you to do this, you can place the pagefile on a disk that contains files that are occasionally read and written to, such as archive files that you create once a month.
You should not place the pagefile on a RAID volume because RAID volumes typically require extra write time. While RAID 5 volumes have significant advantages in read time, write time isn't any better than with a non-RAID disk. Since the pagefile is subject to frequent reads and writes, you want to make sure it isn't placed on a RAID volume.
Various formulas are available for how to optimally size the pagefile. Most are based on some percentage of the amount of RAM installed on the computer. These RAM-based pagefile size recommendations are just estimates. None of them will accurately reflect the best pagefile size for your computer.
The best way to determine the appropriate pagefile size is to use the Performance Monitor, which has two counters that you can use to determine your pagefile's optimal size:
- % Usage
- % Usage Peak
The % Usage counter tells you in real time what percentage of the pagefile is currently in use. The % Usage Peak counter tells you what percentage of the pagefile was in use during its peak usage (that is, the pagefile usage when the system made the greatest demand on the pagefile). The latter value is most useful in determining the best pagefile size.
Start by creating a pagefile that is 1.5 times the size of your physical RAM. Then, perform the following steps:
- Click Start | Run.
- In the Run dialog box, type perfmon.msc in the Open text box and click OK.
- In the Performance console, click the plus button (+) in the toolbar.
- In the Add Counters dialog box (Figure I), click the Down Arrow in the Performance Object drop-down list box and select the Paging File object. Select the All Counters option. Select the Select Instances from List option and select the pagefile location. Click Add and then click Close.
- Let the counters run for a day or two. You might want to set the interval to 15 seconds or longer (click the Properties button in the toolbar and adjust the Update Automatically field) to reduce the amount of system resources dedicated to the monitoring. Then change to the Report View and examine the usage statistics (Figure J). If you find the pagefile % Usage Peak is under 90 percent, you're in good shape and you don't need to resize the file. If you find the usage peak is over 90 percent, you might want to do a detailed review of the session and see how often the usage goes over 90 percent. If it goes over 90 percent frequently, consider resizing the pagefile and running the monitoring session again.
Analyze the pagefile counter statistics in Report View.
Pagefile security and command-line management
You can take a couple more actions if you want to take command of your pagefile:
- Delete pagefile on shutdown.
- Use the Pagefileconfig command-line utility.
These are optional configurations, but you might want to implement them in special circumstances.
Delete pagefile on shutdownYou can clear the contents of the pagefile on system shutdown with the Local Security Policy console. Click Help and Support and search for Local Security Policy. Select Security Settings | Local Policies | Security Options, and then double-click on the Shutdown: Clear Virtual Memory Pagefile entry and select the Enabled option (Figure K).
I recommend that you enable this option only if you have multiple operating systems on the same machine. It's possible to read the contents of the pagefile if you boot into another operating system. However, if you have only a single operating system, the pagefile will be locked and not readable. With a single operating system, you shouldn't wipe the contents of the pagefile; those contents may be helpful to you if you ever need to run a forensic analysis of the machine.
Pagefileconfig command-line utility
Windows XP includes a command-line utility, Pagefileconfig, that allows you to:
- Change the current pagefile settings.
- Add pagefiles to the system.
- Delete pagefiles from the system.
- Display the current pagefile settings.
Run the CSCRIPT //H:CSCRIPT //S command at the command prompt, and then reissue the Pagefileconfig command without switches. You'll see the screen shown in Figure M.
Pagefileconfig displays the current pagefile status.
You can run the Pagefileconfig /? command to learn more about the utilities that let you manipulate the pagefile.
The Windows XP operating system automatically installs and configures a pagefile during system setup. While the default configuration of the pagefile does a reasonably good job, you can make several improvements on the default configuration. By following the recommendations I've given here, you'll be able to take command of your pagefile and improve your system's performance.
Stay on top of the latest XP tips and tricks with TechRepublic's Windows XP newsletter, delivered every Thursday. Automatically sign up today!