oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button
Windows Server Hacks

Optimizing Your Servers' Pagefile Performance

by Mitch Tulloch, author of Windows Server Hacks

The paging file (pagefile.sys) is a hidden system file that forms a key component of the Virtual Memory Manager (VMM) on Windows platforms. The origin of this file dates back to early 1990s when Windows ran on PC hardware that had limited physical memory due to the high cost of RAM and the limitations of motherboard design. (The concept of virtual memory itself, of course, is older, as this article describes.) The purpose of the pagefile was to allow memory-hungry applications to circumvent insufficient RAM by allowing seldom-used pages of RAM to be swapped to disk until needed (hence the term swapfile used on earlier Windows platforms). For example, if a Windows 3.1 machine had 8MB of RAM and a 12MB permanent swap file (386spart.par) on its C: drive, then the effective memory that applications could use was 8 + 12 = 20MB, or in other words:

(physical memory) + (swapfile) = (virtual memory)

The downside of the virtual memory architecture was that performance could be degraded as memory-hungry applications caused frequent swapping of pages between RAM and disk. But as motherboard design improved and RAM became cheaper, adding more RAM could improve performance by reducing the amount of disk thrashing caused by paging. The evolution of applications kept pace with these hardware developments, though, and as applications grew and became bloated, the need for improved paging architecture became paramount. Over the years Microsoft has tweaked the VMM architecture for each version of Windows until today it works quite well. But if you want to get the most out of your servers in terms of performance, you need to go beyond the default pagefile settings.

Moving the Pagefile

The most significant performance gain you can achieve with regard to the pagefile on Windows 2000 and Windows Server 2003 is to move the pagefile to a different partition or volume. By default, Windows creates a pagefile of size 1.5 x RAM and locates it on the root of the boot partition (usually C: drive). Unfortunately, this means the I/O subsystem must contend for access to operating system files (%systemroot% and %systemroot%\system32) and the pagefile (%systemdrive%\pagefile.sys), which increases disk activity and slows performance. By moving pagefile.sys to a different volume, this contention is reduced--especially if the pagefile volume is on a different hard drive with its own controller.

To move the pagefile, open the System utility in Control Panel and select the Advanced tab, click Settings under Performance, then select Advanced and click Change to display the Virtual Memory properties sheet (see Figure 1).

Figure 1
Figure 1. Configuring pagefile settings on Windows Server 2003.

In Windows 2000 the procedure is a little different and goes like this: Open System in Control Panel, select the Advanced tab, click Performance Options, and click Change (see Figure 2):

Figure 2
Figure 2. Configuring pagefile settings on Windows 2000.

Note that Windows Server 2003 provides two pagefile options not present in Windows 2000. First, the System Managed File option lets the operating system determine how large the pagefile should be. If you choose this option, Windows will set the size of the pagefile equal to RAM + 1 MB, which is just sufficient for Windows to save a Memory.dmp file in the event of a STOP error (blue screen). Second, the No Paging File option lets Windows run with no pagefile.sys, something Windows 2000 couldn't do. (If you try setting the pagefile size to zero in Windows, a temporary pagefile (temppf.sys) 20MB in size will be created in your %systemroot%\system32 folder upon startup and you will be prompted to reconfigure your pagefile settings to the recommended values).

Related Reading

Windows Server Hacks
100 Industrial-Strength Tips & Tools
By Mitch Tulloch

Moving the pagefile is a two-step process. First, create a new pagefile on the target drive by selecting the drive and specifying its pagefile settings. Then select C: and remove the pagefile there by selecting No Paging File (Windows Server 2003) or specifying initial and maximum pagefile sizes of zero (Windows 2000). You'll be warned that having no pagefile (or a pagefile smaller than RAM) on your boot partition means that Windows won't be able to save a crashdump file should a STOP error occur. If you're concerned about that (no crashdump could make it harder to troubleshoot system failures) then go ahead and leave a pagefile of size RAM + 1MB on C: drive as you'll still experience the performance gains desired. The reason is that when you have a pagefile split across several volumes, the VMM chooses the least busy drive for writing pages to disk, which in our example would mean the pagefile on E: would almost always be used since C: has a lot of system activity.

And, by the way, always restart the computer after moving or reconfiguring the paging file, even if Windows doesn't prompt you to do so. Otherwise some Windows utilities may display an incorrect value for total pagefile size.

Keeping the Pagefile Separate

If you're going to move the pagefile to a different volume, your best performance gains will be achieved if this volume is not only located on a separate hard drive but is also the only volume on that hard drive and pagefile.sys is the only file on the volume. In other words, move the pagefile to a hard drive dedicated to hosting pagefile.sys and nothing else. And buy the best drive you can for this purpose, which for IDE means a drive that has non-volatile RAM for storing write cache settings. Make sure you enable write caching on an IDE drive that hosts the pagefile as this will increase I/O and improve paging performance. To enable write caching, right-click on any volume in Windows Explorer and select Properties, select the Hardware tab, choose the hard drive where the pagefile is located, and click Properties to open the properties sheet for the drive. Then select the Disk Properties tab (Windows 2000) or Policies tab (Windows Server 2003) and select the checkbox to enable write caching for the drive. On Windows Server 2003 there is an additional checkbox you can select to improve drive performance even more (Figure 3):

Figure 3
Figure 3. Enabling write caching on the drive where the pagefile is located.

If your pagefile is located on a SCSI drive instead, make sure tagged queuing and synchronous transfers are disabled for the drive. These settings are found on the SCSI Properties tab of the drive's properties sheet following the procedure described above. And don't put your pagefile on a RAID-5 volume or other fault-tolerant drive; it may actually decrease pagefile performance instead of increase it. Pagefiles don't need fault tolerance anyway.

Defragment the Pagefile

If you move your pagefile to a dedicated hard drive as described above, then the likelihood of your pagefile becoming fragmented is greatly reduced. Pagefile fragmentation, like other forms of disk fragmentation, can have a considerable impact on performance. The built-in Disk Defragmenter utility of Windows 2000 and Windows Server 2003 cannot defragment pagefiles, so if you really want to keep your system humming along you might want to consider purchasing an enterprise-grade disk defragmentation tool like Diskeeper Server, Defrag Manager, or PerfectDisk. If your budget is restricted, you can also check out PageDefrag, a free pagefile defragmenting tool from SysInternal.

Another tip for avoiding pagefile fragmentation is to set both the initial and maximum pagefile sizes to the same value (see below). This prevents the pagefile from expanding beyond its initially configured size and becoming fragmented, though if you do this, make sure the size you specify is sufficient for any memory-hungry applications running on your machine, otherwise your system might run out of memory and crash.

Increasing the Pagefile Size

While the default setting of 1.5 x RAM is sufficient for pagefile size for some server roles, if your machine is running disk- and memory-intensive applications like Exchange or SQL Server then you may want to increase the initial pagefile size to 2 x RAM or even larger. Microsoft doesn't recommend increasing the pagefile to more than 3 x RAM, however, and the maximum allowed size for any one instance of pagefile.sys on a machine is limited to 4GB. So, if you have a powerful machine with 4GB of RAM then you have to split the pagefile to overcome this limit. This splitting can be done in two ways: create separate pagefiles on different volumes (done in the usual way) or create multiple pagefiles on a single volume. (See KB 237740 for how to do this.) On a more modest machine with 1GB of RAM though, you would probably be best served to set the initial pagefile size to 2GB (2 x RAM) and the maximum pagefile size to 3GB (3 x RAM).


Finally, if you're using Windows 2000 make sure you use the System utility in Control Panel for configuring your pagefile settings, not Computer Management. Although it appears you can configure pagefile settings by right-clicking the root node in Computer Management, selecting Properties, selecting the Advanced tab, and so on, these settings aren't retained by the system when you configure them. This is not the case in Windows Server 2003 however, where the GUI has been fixed to work properly.

Mitch Tulloch is the author of Windows 2000 Administration in a Nutshell, Windows Server 2003 in a Nutshell, and Windows Server Hacks.

Return to