Thursday, July 20, 2006

Virtual memory in Windows

Memory paging occurs when memory resources required by the processes running on the server exceed the physical amount of memory installed. Windows, like most other operating systems, employs virtual memory techniques that allow applications to address greater amounts of memory than what is physically available. This is achieved by setting aside a portion of disk for paging. This area, known as the paging file, is used by the operating system to page portions of physical memory contents to disk, freeing up physical memory to be used by applications that require it at a given time. The combination of the paging file and the physical memory is known as virtual memory. Virtual memory is managed in Windows by the virtual memory manager (VMM). Physical memory can be accessed at exponentially faster rates than disk. Every time a server has to move data between physical memory and disk will introduce a significant system delay. While some degree of paging is normal on servers, excessive, consistent memory paging activity is referred to as thrashing and can have a very debilitating effect on overall system performance. Thus, it is always desirable to minimize paging activity. Ideally servers should be designed with sufficient physical memory to keep paging to an absolute minimum. The paging file, or pagefile, in Windows, is PAGEFILE.SYS. Virtual memory settings are configured via the System control panel. To configure the page file size: 1. Open the System Control Panel. 2. Select the Advanced tab. 3. Within the Performance frame, click the Settings button. 4. Select the Advanced tab. 5. Click the Change button. The window shown in Figure 1-1 will appear. Window Server 2003 has several options for configuring the page file that previous versions of Windows did not. Windows Server 2003 has introduced new settings for virtual memory configuration, including letting the system manage the size of the page file, or to have no page file at all. If you let Windows manage the size, it will create a pagefile of a size equal to physical memory + 1MB. This is the minimum amount of space required to create a memory dump in the event the server encounters a STOP event (blue screen).

Figure 1-1 Virtual memory settings

A pagefile can be created for each individual volume on a server, up to a maximum of sixteen page files and a maximum 4 GB limit per pagefile. This allows for a maximum total pagefile size of 64 GB. The total of all pagefiles on all volumes is managed and used by the operating system as one large pagefile.
When a pagefile is split between smaller pagefiles on separate volumes, the virtual memory manager optimizes the workload by selecting the least busy disk based on internal algorithms when it needs to work write to the pagefile. This ensures best possible performance for a multiple-volume pagefile.
While not best practice, it is possible to create multiple page files on the same volume. This is different to what most documentation suggests. This is achieved by placing the page files in different folders on the same volume. This change is carried out via editing the system registry rather than via the standard GUI interface. The process to achieve this is outlined in Microsoft KB article 237740: