RAM, Virtual Memory, PageFile and all that stuff

Virtual Memory

In most modern operating systems, including Windows, application programs and many system processes always reference memory using virtual memory addresses which are automatically translated to real (RAM) addresses by the hardware. Only core parts of the operating system kernel bypass this address translation and use real memory addresses directly. The virtual memory management component of the operating system maintains the tables used by the hardware to provide the mapping of virtual addresses into real addresses. A small amount of RAM is used by those parts of the operating system that can not be paged out (for example, the virtual memory manager) and is thus not available for assignment to virtual memory.

The key point here is that Virtual Memory is always in use, even when the memory required by all running processes does not exceed the amount of RAM installed on the system.

Address Spaces and Process

Any process (e.g. application executable) running under 32 bit Windows versions gets a set of virtual memory addresses (a Virtual Address Space) going from 0 to 4,294,967,295 (2*32-1 = 4 GB), no matter how much RAM is actually installed on the computer. Actually, this is essentially the same for all operating systems running on 32 bit hardware that implement Virtual Memory.

In the normal, default 32 bit Windows OS configuration, 2 GB of this virtual address space are allocated to the process’ private use and the other 2 GB are allocated to shared and operating system use.

Only that portion of the address space that is actually referenced (used) by a process or the system is associated with a page frame in real memory, or in the pagefile.

Pagefile

RAM is a limited resource, whereas virtual memory is, to a large extent, unlimited in that there can be a large number of processes each with its own 4 GB virtual address space, of which 2 GB is private to the process (32 bit Windows). When the memory in use (that is, has been reference) by all the existing processes exceeds the amount of RAM available, the operating system will move pages (4 KB pieces) of one or more virtual address spaces to the computer’s hard disk, thus freeing some RAM for other uses. In Windows systems, these “paged out” pages are stored in one or more files with the name pagefile.sys. There can be one such file in each disk partition.

A frequently asked question is “how big should I make the pagefile”? There is no single answer to this question, because it depends on the workload on the computer, how much RAM there is and how much virtual memory space that workload requires.

With operating systems like Windows XP on older computers with a small amount of RAM it is not uncommon for power users to have many windows open (and thus processes running) and to exhaust the available RAM. In this situation, the goal is provide sufficient pagefile space to avoid running out of available virtual memory, which could cause application failures or at least, significant inconvenience.

There is quite a variety of ideas on this subject, but here’s a place to start for computers (typically older ones) that don't have much RAM:

  • If the computer has less than 1 GB of RAM
  • Minimum – 384 MB
  • Maximum – 1 GB (or less if disk space is in short supply)
  • If the computer has more than 1 GB of RAM
  • Minimum – 1 GB to the amount of RAM installed
  • Maximum – 1 GB to the amount of RAM installed

Most newer computers will have more than I GB of RAM and, in most cases, there is sufficient RAM available that having more virtual memory than the available RAM is a relatively rare occurrence. There is little point in allocating a large minimum size pagefile, since it typically won’t be used. However, having a relatively large maximum will avoid “out of virtual memory” conditions without dedicating a big chunk of disk space for that rare situation.

A common objective in configuring a server is to ensure sufficient RAM so that paging doesn’t happen. Providing a large maximum pagefile is insurance against “out of virtual memory” situations that could cause service interruptions. Servers running a few applications are typically configured with enough RAM that paging is rare. A possible exception are servers used for Terminal Services, where it would be common for some users to be relative inactive for long periods of time and paging may occur routinely without a significant performance penalty.

loading...