The Resume of Waine Hanks

Taking control of your pagefile in Windows XP

E-mail Print PDF

The Microsoft Windows XP pagefile is used in addition to any existing physical ram, and windows uses it in a very similar way. It is needed because applications and services cannot function properly when limited to the amount you have installed, so Microsoft developed the Pagefile as a way of covering itself from falling over. So it makes sense that anything that can be done to optimise the Pagefile will greatly benefit your system.

After you carry out any of these alterations to your Pagefile, whether just defragmenting or moving it as well. Your system should be running quicker than ever.

Pagefile fragmentation

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. It takes longer to read a fragmented file. Like any other file on a hard disk, good old Mr Pagefile can become very 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 it in one solid piece. This typically isn't the case when the operating system is first installed as there is normally more than enough room to start with. 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 as space on the drive becomes more fragmented.

You can determine the level of pagefile fragmentation with the built-in tool 'Disk Defragmenter'. Follow these 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 'Analyse' in the Disk Defragmenter application (FigA).

FigA

4. Once the Disk Defragmenter dialog box appears (FigB), click View Report.

FigB

5. In the Analysis Report dialog box (FigC), scroll through the Volume Information box and find the Pagefile fragmentation section.

FigC

here (in the upper window), the pagefile is in 3 fragments.

6. Click Close.

You could improve the performance here by removing the fragmented pagefile and re-creating it in a way so that it doesn't 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 the fragmentation.

You can do this in two ways:

  • Temporarily move the pagefile to another disk/partition.
  • Use a third-party product such as Diskeeper.

Defrag Apps

There are many 3rd party applications for defragmenting on the market that can perform an "offline" defragmentation of the pagefile after the system is restarted. Otherwise you will need to do the following:

Perform the following steps to remove and re-create the pagefile:

1. Click Start > right-click My Computer. Click > Properties command.
2. In the System Properties dialog box, click on the Advanced tab.
3. On the Advanced tab, click the Settings button in the Performance frame (FigD).

FigD

4. On the Performance Options dialog box, click on the Advanced tab.

5. On the Advanced tab (FigE), click the Change button, in the Virtual Memory frame.

FigE

6. 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 (FigF). Click the Set button.

FigF

Make the current pagefile 0MB in size.

7. 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 (FigG). 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.

FigG


Create the temporary pagefile.

8. A System Settings Change dialog box will appear and ask if you want to restart the computer. Close all programs and click Yes.

9. After the machine reboots, click Start | Run.

10. In the Run dialog box, type dfrg.msc in the Open text box and click OK.

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

12. Go back to the Virtual Memory dialog box and put the pagefile back on the original drive. Remove the pagefile from the temporary drive (FigH). 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.

FigH

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 optimise 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. Generally,  you can assume 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.

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 (FigI), 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.

FigI

5. 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 (FigJ). 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.

FigJ

Analyse 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 the 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 (FigK).

FigK
figK

It is recommended 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 (FigL):

FigL

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

FigM

Pagefileconfig displays the current pagefile status.

You can run the Pagefileconfig /? command to learn more about the utilities that let you manipulate the pagefile.

Conclusion

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 here, you'll be able to take command of your pagefile and improve your system's performance.

Thanks to all 3rd party sources such as MS TechNet, MS and TechRepublic.