Take control of the Windows XP pagefile

The pagefile extends the capabilities of your computer's memory. Like any other file on a PC, though, the pagefile can become fragmented and hinder the computer's performance. Here are a few techniques you can use to better manage this beast.

The 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.

Pagefile fragmentation
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:
  1. Click Start | Run.
  2. In the Run dialog box, type dfrg.msc in the Open text box and click OK.
  3. Click the Analyze button in the Disk Defragmenter application (Figure A).

Figure A

  1. When the Disk Defragmenter dialog box appears (Figure B), click View Report.

Figure B

  1. In the Analysis Report dialog box (Figure C), scroll through the Volume Information box and find the Pagefile fragmentation section.

Figure C
In this example, the pagefile is in three fragments.

  1. Click Close to close the Analysis Report dialog box.

You could improve the performance on this machine by removing the fragmented pagefile and recreating 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 review
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 TechProGuild has to say about Diskeeper 7.0 here.

Perform the following steps to remove and re-create the pagefile:
  1. Click Start and then right-click the My Computer object. Click on the Properties command.
  2. In the System Properties dialog box, click on the Advanced tab.
  3. On the Advanced tab, click on the Settings button in the Performance frame (Figure D).

Figure D

  1. On the Performance Options dialog box, click on the Advanced tab.
  2. On the Advanced tab (Figure E), click the Change button in the Virtual Memory frame.

Figure E

  1. 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.

Figure F
Zero out the current pagefile.

  1. 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.

Figure G
Create the temporary pagefile.

  1. A System Settings Change dialog box will appear and ask if you want to restart the computer. Close all programs and click Yes.
  2. After the machine reboots, click Start | Run.
  3. In the Run dialog box, type dfrg.msc in the Open text box and click OK.
  4. 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.
  5. 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.

Figure H
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.

As in Windows 2000, in Windows XP the terms volume and partition are based on whether you’re using dynamic disks or not.

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.

In several places, the TechNet literature mentions placing the pagefile on a mirror set (RAID 1) when running Microsoft Exchange and SQL. No rationale for this decision is given in any of the references, so it’s difficult to determine why you would want to do this. It could be that the systems in question didn’t have the requisite disk resources to remove the pagefile from the mirror set. You might want to test performance both ways and determine which works best for you.

Gauging performance
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:
  1. Click Start | Run.
  2. In the Run dialog box, type perfmon.msc in the Open text box and click OK.
  3. In the Performance console, click the plus button (+) in the toolbar.
  4. 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.

Figure I

  1. 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 toolbarand 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.

Figure J
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 shutdown
You 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 (see Figure K).

Figure K

I recommend that you only enable this option 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, which allows you to:
  • Change the current pagefile settings.
  • Add pagefiles to the system.
  • Delete pagefiles from the system.
  • Display the current pagefile settings.

When you first try to run the Pagefileconfig utility from the command prompt, you’ll see the following dialog box (Figure L):

Figure L

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.

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 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.