Configuring Page Files

It is a common practice to move the default page file stored on the system root drive (typically C:) to a different disk to improve performance. The page files and system drive are frequently accessed by the operating system and separating them on different disks can improve performance. You may also want to increase the size of the page file or spread your page file across multiple volumes based on the needs of your system.

Using a graphical user interface

  1. From the Control Panel, open the System applet.
  2. Select the Advanced tab.
    1. On Windows Server 2003:
      1. Under Performance, click the Settings button.
      2. Click the Advanced tab.
      3. Under Virtual memory, click the Change button.
      4. You’ll see a list of all volumes and any page files that have been configured on them. To modify the size of an existing page file, highlight the drive the page file is on, modify the Initial size and/or Maximum size, and click Set. You can also select System managed size to let the system control the size of the page file. To add a new page file, select a drive that currently does not have a page file and select either Custom size or System managed size. If you select the former, enter the Initial size and Maximum size. Click Set when you are done. A performance tip is to set the initial size the same as the maximum size to reduce unnecessary I/O operations.
    2. On Windows 2000:
      1. Click the Performance Options button.
      2. Click the Change button.
      3. You’ll see a list of all attached disks and any page files that have been configured on them. To modify the size of an existing page file, highlight the drive the page file is one, modify the Initial size and/or Maximum size, and click Set. To add a new page file, select a drive that currently does not have a page file, enter the Initial size and Maximum size, and click Set.

Using a command-line interface

Page file information is stored in the registry, so you can use the reg.exe command to display current settings:

> reg query "\\\HKLM\System\CurrentControlSet\Control\Session Manager\
 Memory Management" /v PagingFiles

For Windows Server 2003, you can also use the systeminfo.exe command to display page file usage:

> systeminfo | findstr Page

The list of page files is stored in a REG_MULTI_SZ value called PagingFiles in the registry. By using the reg add command you can overwrite the current settings in PagingFiles and specify the page files you want. This command configures only one page file on the system located at d:\pagefile.sys:

> reg add "\\\HKLM\System\CurrentControlSet\Control\Session Manager\
 Memory Management" /v PagingFiles /t REG_MULTI_SZ /d "d:\pagefile.sys 580 1024"

The first number after d:\pagefile.sys is the initial size in megabytes for the page file and the second number is the maximum size.

This command causes there to be two page files, one on the C: drive and the other on the D: drive:

> reg add "\\\HKLM\System\CurrentControlSet\Control\Session Manager\
 Memory Management" /v PagingFiles /t REG_MULTI_SZ /d "C:\pagefile.sys 512 1024\0D:\
pagefile.sys 512 1024\0"

You’ll need to reboot for the changes to take effect.

Using VBScript

' This code displays the current page files on the system.
 ' ------ SCRIPT CONFIGURATION ------
 strComputer = "."
 ' ------ END CONFIGURATION ---------
 set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
 set colPF = objWMI.InstancesOf("Win32_PageFileUsage")
 for each objPF in colPF
    Wscript.Echo objPF.Name
    Wscript.Echo "  Initial Size: " & objPF.AllocatedBaseSize
    Wscript.Echo "  Max Size: " & objPF.CurrentUsage
    WScript.Echo "  Peak Usage: " & objPF.PeakUsage
    WScript.Echo
 next

You cannot change the size of a Page file with the Win32_PageFileUsage class (or any other WMI class), you can only retrieve a page file’s properties.

There are two types of memory on computers: random access memory (RAM) (or physical memory) and virtual memory. RAM is stored on specialized chips and is very fast, whereas virtual memory is stored on hard drives and is comparatively slow. On Windows systems, paging files are used to allocate space for virtual memory.

The operating system uses RAM when possible, but when the limits of RAM are exceeded it turns to virtual memory. When the system needs to make room in RAM (e.g., when you open a new application), it pages out the most infrequently used sections of RAM to virtual memory. That means the system has to perform disk reads and writes during this process. Your goal with virtual memory should be to configure the paging files so that they are big enough to handle virtual memory demands and can be accessed quickly.

In fact, your page file configuration can have a significant impact on system performance. When the Windows operating system is first installed, a page file is created (called pagefile.sys) on the drive the operating system is installed on. As I mentioned in the Problem section, you should consider moving this page file to a separate drive so that there isn’t a lot of contention for disk I/O when the system needs to access virtual memory. An even better practice is to create two page files. It is a good idea to have a page file on a non-system partition, but you may still want a page file on the system partition to handle memory dumps. If there is no page file on the system drive and a system crash (blue screen) occurs, the system will not be able to write out a memory dump that can be used to troubleshoot the crash. Windows uses the page file on the least busy partition, so it should primarily use the non-system partition page file for virtual memory. It is also worth noting that you shouldn’t bother with creating two page files unless you have at least two disks. Creating multiple paging files on the same disk doesn’t buy you much in terms of performance.

Regarding the size of the page files, the general rule of thumb is to have at least 1.5 times the amount of RAM, which is the default configuration. So if you had 1 GB of RAM, you should have at least a 1.5-GB paging file. The largest any one page file can be on a single disk is 4 GB.

Another issue to consider if security is a concern for you is clearing the paging files during system shutdown. Some applications write sensitive information, such as passwords, to RAM. If that data gets paged out to virtual memory, it can end up in a page file. That information can remain in the page file for a considerable amount of time (even after reboot) until that space is needed for something else. While the page files are protected by the operating system, it is possible (although not very easy, mind you) for an attacker that has gained control over the system to read that file and any data within it. The solution for this is to clear the page files whenever the system shuts down. To enable this you need to modify a registry setting and reboot the computer. See MS KB 182086 for more information.

Using a graphical user interface
The System Managed option I described in the graphical solution is only available in Windows Server 2003. It is a new feature that lets the system determine how big the page file needs to be. It is a good practice to use this setting unless you have a very good reason not to do so.

Using a command-line interface
Be careful when configuring the page files from the command line. Thoroughly test your command before trying it on a production system. The last thing you want to do is mess up the page files on your systems!

Using VBScript
None of the WMI classes allow you to configure the page files directlyyou can only view them. If you need to do it programmatically, your best bet would be to use the Registry WMI provider to set the corresponding registry values for page files as I described in the command-line solution.