Microsoft designed Windows NT to use paging for virtual memory regardless of how much physical memory is available. Paging is the process of temporarily transferring some of the contents of a system's physical memory to the hard disk until the system needs the contents of that memory again. When NT starts, it creates a paging file (pagefile.sys) on the hard disk to store information. Paging frees up physical memory on the system and lets more processes execute. When a process needs code or data that was swapped to the hard disk, the system puts that code or data back into physical memory and transfers other information to the hard disk if necessary. The difference in performance between a hard disk and physical memory is astounding. Hard disk access time is typically 10 milliseconds (ms), whereas physical memory access time is around 60 nanoseconds (ns). Accessing memory is several orders of magnitude faster than accessing the most technologically advanced hard disk drives.
To make your system run more efficiently, you must minimize the effects of paging. One option to reduce paging activity is to add memory. Adding memory reduces the likelihood that the system will rely solely on the hard disk for virtual memory. You can monitor your system's changing memory requirements and properly configure the paging file to maximize paging performance. You must consider the paging file location and size.
Paging File Location Considerations
During the installation process, NT uses contiguous disk space to automatically create the paging file. NT always places the file in the system partition's root directory, although this location is not necessarily ideal. To achieve optimal paging performance, you must look at your disk subsystem configuration to determine whether your system has more than one physical hard disk. If your system has only one hard disk, you'll want to consider adding an extra hard disk. NT supports as many as 16 paging files that it can distribute across multiple drives. Configuring the system to have multiple paging files lets the system make multiple, simultaneous I/O requests to the various hard disks, thereby increasing I/O requests to the paging file.
A system with only one hard disk limits your ability to optimize paging performance. The hard disk must process system and application requests and access the paging file. The physical hard disk might have multiple partitions, but dispersing the paging file among the partitions is a bad idea. Multiple paging files spread across multiple partitions do not increase the hard disk's ability to read or write to the pagefile.sys file. In fact, this setup impedes system performance, because the hard disk must handle paging requests for multiple paging files. However, you can use multiple smaller paging files on multiple partitions on one physical disk when a partition lacks the space to contain an entire paging file.
Calculating Paging File Size
The size of the paging file is critical. Regardless of how many paging files you create, you need to properly size them, or your system will have performance problems. If the paging files are too small, the system might have to enlarge them to compensate for increased paging activity. When a system increases paging file size on the fly, it has to create new space for the paging file while handling paging requests. In this situation, the system will experience excessive page faults. A page fault is when the system must find information outside the process' working set, either elsewhere in physical memory or in the paging file. The system might also start thrashing. Thrashing is when the system lacks the physical and virtual memory resources to satisfy usage requirements and thus relies on the disk subsystem for virtual memory. Thrashing causes the system to spend more time paging than executing applications. Thrashing occurs when the Memory: Pages/sec counter that you monitor from Performance Monitor (Perfmon) is consistently above 100 pages per second. This problem severely decreases system performance. Expanding the paging file on the fly also causes fragmentation. The system might scatter the paging file throughout the disk rather than maintaining it in contiguous space. This fragmentation introduces system overhead and severely degrades performance. Don't make the system responsible for increasing the paging file size.
Microsoft recommends a minimum paging file size of physical RAM + 11MB. During installation, NT configures the minimum paging file size to reflect this value. To determine the appropriate paging file size for your system, you'll want to estimate paging requirements during typical usage (as I explain later in the article), compare your estimate with Microsoft's recommendation, and use the higher value as the minimum. If you want to configure multiple paging files for a system, the minimum size applies to the paging files collectively rather than to each paging file.
To change the paging file's location or size configuration parameters, open the System applet in Control Panel or right-click My Computer on the desktop and select Properties. On the Performance tab, click Change. In the Virtual Memory dialog box, you can change the paging file's location or size to meet the anticipated requirements, as Screen 1 shows. To add another paging file to the existing configuration, select a hard disk that doesn't already have a paging file. Specify the initial size and maximum size (in megabytes) for the paging file, and click Set, OK. Reconfigure the other paging files so that the sum of their minimum sizes reflects the minimum size for the entire system.
To change a paging file's minimum and maximum size, select the hard disk where the paging file resides. Specify the initial size and maximum size (in megabytes) for the paging file, and click Set, OK. Click OK on the System Properties dialog box. When the system prompts you to restart the computer, click Yes.
NT provides several tools to help you determine the system's paging requirements. You can use Task Manager, NT Diagnostics (winmsd.exe), or Perfmon to determine the proper size so the paging file doesn't have to expand on the fly during normal operation.
The absolute minimum paging file size is only 2MB. However, your system performance will suffer if you set the paging file size to such a low value, because the system will have to expand the paging file until it can meet paging requests.
Task Manager. Task Manager lets you easily check for the correct paging file size. Task Manager shows you how the system is using the paging file and gives you other vital system information. To run Task Manager in NT 4.0, press Ctrl+Alt+Del and select Task Manager, or right-click the taskbar and select Task Manager. After you start Task Manager, click the Performance tab to get realtime system statistics, as Screen 2 shows. The most important paging file size information on the Performance tab is the Commit Charge section. This section tells you whether the Commit Peak (the highest amount of physical and virtual memory the system has allocated to processes thus far) has approached or exceeded the Commit Limit or the system's physical memory. Commit Limit is the amount of virtual memory that the system can commit to memory without expanding the paging file.
As paging activity increases, the Commit Total (committed memory) also increases. The system needs to expand the paging file as the Commit Total approaches the Commit Limit. The goal is to prevent the paging file from expanding, so you need to keep the Commit Total from approaching the Commit Limit. The worst case occurs when the two values are equal and the paging file can't grow to meet system requirements.
Task Manager's Commit Charge section also tells you whether the system's main memory can accommodate system tasks. If the Commit Total regularly exceeds the system's RAM, the system might not have enough physical memory. For example, if a system with 64MB of RAM also has a Commit Total of 64MB, the system needs additional physical memory.
NT Diagnostics. Like Task Manager, NT Diagnostics displays system statistics related to processes and memory. However, this tool doesn't present information in realtime. You must manually refresh the display to get current information. On the Memory tab, click Refresh, which Screen 3 shows. NT Diagnostics is useful in estimating but not calculating a minimum paging file size.
Performance Monitor. Perfmon is the best and most reliable tool for determining a minimum paging file size. Perfmon lets you monitor counters that pertain to virtual memory. Before you start monitoring the counters, follow Microsoft's recommendation (physical RAM + 11MB) to set the minimum paging file size. Then you can monitor typical operations' memory use.
The four main counters for monitoring virtual memory are Memory: Committed Bytes, Memory: Commit Limit, Paging File: % Usage, and Paging File: % Usage Peak. The following list explains how each of these counters helps you determine minimum paging file requirements:
- Memory: Committed Bytes shows the amount of virtual memory that processes are currently using. Memory: Committed Bytes is the amount of committed rather than reserved virtual memory.
- Memory: Commit Limit shows the amount of virtual memory the system can commit without expanding the paging file. Commit Limit equals physical memory plus the paging file size, minus the memory reserved for the operating system (OSwhich is a dynamic value).
- Paging File: % Usage shows the percentage of the paging file that processes are currently using.
- Paging File: % Usage Peak shows the highest percentage of space the paging file is using.
The Committed Bytes and Commit Limit counters work side by side. If you monitor the counters separately, you won't have enough information to properly set the paging file's minimum size. You must monitor both counters to determine whether the paging file is approaching or has reached full capacity. When the Committed Bytes approaches the Commit Limit, the system is running out of virtual memory. The system will warn you of this problem, as Screen 4 shows. You must then close some applications, manually increase the paging file, and restart the system. Committed Bytes won't exceed the Commit Limit if you configure the minimum paging file size properly. You can add an alerting mechanism that will warn you if the Committed Bytes value becomes too large. Perfmon can also alert you when the Committed Bytes is within 20 percent of the Commit Limit.
To add and configure alerts in Perfmon, choose Alert from the View menu. Next, select Add to Alert from the Edit menu to add counters. Choose the object you want to monitor and the appropriate counter within it. For example, choose the Memory: Commit Limit counter. For the Alert If option, specify a value for the counter. Select Over if you want Perfmon to trigger an alert when the counter exceeds this value, or Under if you want Perfmon to trigger an alert when the counter falls below this value. In the Run Program on Alert box, you might want to specify an application, such as paging software, to run. When you finish configuring the alert options for the counter, click Add to add the counter to the alerting scheme.
If the Committed Bytes counter equals or exceeds the Commit Limit, the system is experiencing excessive hard page faults because you haven't properly configured the minimum and maximum paging file size to meet memory usage requirements. A hard page fault occurs when the system has to retrieve a page from the hard disk rather than main memory; hard page faults significantly delay performance. The Memory: Pages/sec counter shows the number of hard page faults. When the system runs low on virtual memory, the Memory: Pages/sec counter exceeds 20 pages per second, and system performance decreases significantly. To prevent this problem, increase the paging file size to accommodate the largest memory usage requirements.
Other counters you can use to determine minimum paging file size are Paging File: % Usage and Paging File: % Usage Peak. You can use these counters together or monitor them separately to determine what percentage of the paging file the system is using. Recommended values are % Usage counter below 40 percent and % Usage Peak below 75 percent. If the counters stay in the acceptable ranges, the system won't have to increase the paging file.
You can use these counters to estimate how much physical memory the system needs to keep from relying on the paging file. For example, if the minimum paging file size is 80MB and the % Usage counter averages 20 percent, you can add 16MB of RAM to the system and thus reduce the percent usage. In this case, 20 percent paging file use tells you that if you add memory equal to 20 percent of the paging file, the system's main memory will accommodate most server functions without relying on the paging file.
You also need to consider maximum paging file size to boost the paging performance on your system. The maximum value is the highest value you expect the paging file to grow, and you must have enough free hard disk space to accommodate this limit. A general rule is to set the maximum paging file value at the minimum value plus 50 percent. However, if you configure the minimum paging file size properly, the system is unlikely to approach the maximum value. Your paging performance will be optimal if you properly configure the minimum paging file size and set the maximum paging file size to the recommended value.
NT's reliance on paging can benefit the system and user applications, but paging sometimes negatively affects performance. You can't always add memory to the system configuration, and adding memory doesn't necessarily correct paging performance problems. However, you'll want to configure your system with as much memory as possible because it's currently inexpensive. You must consider several alternatives to increase your system's paging performance, including proactive monitoring, proper paging file configuration, and location. If you properly configure the minimum and maximum paging file size, you reduce the risk of compromising performance during peak memory utilization periods.