Using virtual memory is a way for the computer to accomplish more than the limits of what its physical memory can perform. The computer system uses a portion of the hard disk as if it was physical RAM. When all physical memory is ﬁlled, the OS can transfer some of the least-recently-used data from memory to a ﬁle on the hard disk called the pageﬁle, thereby freeing up an equivalent amount of space in main RAM for other purposes. When the original data is needed again, the next least-recently-used data is moved out of RAM onto the hard drive to make room to reimport the needed data.
Figure : Virtual memory.
Virtual Memory and RAM Speed
Virtual memory is not nearly as fast as actual memory. Modern SDRAM DIMMs read/ write speeds are measured in nanoseconds, whereas hard drive seek, read, and write times are measured in milliseconds. If your computer is frequently exceeding its physical RAM and having to resort to using a pageﬁle on disk, adding more physical RAM may be the most economic way of effecting a noticeable change in performance.
The Virtual Memory Process
When data is stored in virtual memory:
1. An application loads and requests memory from the system.
2. The Virtual Memory Manager (VMM) assigns it a page of memory addresses from within the virtual memory space.
3. The application stores information in one or more of the virtual memory locations.
4. The VMM maps the virtual address the application uses to a physical location in RAM.
5. As physical RAM becomes full, the VMM moves inactive data from memory to the pageﬁle in a process called paging or swapping.
Figure: Storing and retrieving virtual memory data.
When data is retrieved from virtual memory:
1. An application requests data from its virtual memory location.
2. The VMM determines which physical RAM location was mapped to this virtual memory address.
3. If the VMM ﬁnds that the data is not present in the RAM location, it generates an interrupt called a page fault.
4. The VMM locates the data in the pageﬁle, retrieves the data from the hard disk, loads it back into RAM, and updates the virtual-to-physical address mapping for the application. If necessary, the VMM swaps other data out of RAM to release space.
5. The application retrieves the data from RAM.
Optimizing the Pageﬁle
When you install Windows, the system automatically creates a pageﬁle named Pageﬁle.sys at the root of the drive. The size of the pageﬁle varies within a range determined by the pageﬁle’s initial size value and maximum size value. The system sets the size values of the pageﬁle using an algorithm that takes into account the amount of physical memory and the space available on the disk. When the system starts, the pageﬁle is set to the initial size; if more virtual memory space is needed, the system adds it to the pageﬁle until it reaches the maximum size. An administrator can alter the initial and maximum size values to optimize the pageﬁle and virtual memory performance. In modern systems, there is rarely a severe shortage of either physical RAM or disk space, so optimizing the pageﬁle might not be an issue, but you can consider the following tips:
- Although Microsoft recommends an initial pageﬁle size of 1.5 times the amount of RAM, the more RAM you have, the smaller a pageﬁle you need.
- If the initial size of the pageﬁle is too low, the system will waste time as it adds more space to the pageﬁle. Adding space to the pageﬁle after startup also increases disk fragmentation. Consequently, it is often a good idea to set the initial size to the same value as the maximum size. If the initial size is too high, however, the pageﬁle will be mostly empty, which wastes disk space.
- If you get a lot of “low virtual memory” errors, increase the maximum size of the pageﬁle.
- If you have multiple drives, you can move the pageﬁle off the drive that contains the Windows system ﬁles, so that the computer can access system ﬁles and pageﬁle information simultaneously. Put the pageﬁle on the fastest drive that does not contain Windows.
- If there is not a noticeable speed difference between drives, create additional pageﬁles on multiple drives. This speeds access time because the system can read and write from multiple drives simultaneously. However, there is no performance advantage to putting the pageﬁle on different partitions on the same disk.
————— Thanks everyone