Virtual Memory is a system of memory management that divides up the contents of physical RAM, manages these contents in memory, and stores them in either physical RAM or in secondary storage, such as the computers hard disk.

When the System and applications’ thirst for memory address space outstrips the available physical RAM, or RAM fragmentation results in inadequate amounts of free RAM in consecutive blocks, portions of the RAM’s contents are managed by Virtual Memory system and are written to the hard drive. A portion of the contents of the physical RAM are divided into pages and page frames, which are small segments of memory sized between 1k to 4k in size.

A Page Table is developed to track these page frames and their location. When the data in RAM exceeds the capacity of the physical RAM, some of the pages are written to swap space on secondary storage — usually the computer’s internal hard drive. When the processor needs data stored in a page, it uses the Page Table to find the page. If it is found still residing on in the physical RAM, it is considered a page hit. If the page is not found in the physical memory of the machine, it is called a Page Fault. With a Page Fault, the system must retrieve the page from the swap space on the hard disk.

For increased machine performance, the system tries to predict what data is least likely to be needed. The pages the system considers as having the least value are called Victims. Victims are the pages that the system has determined are the least frequently used or oldest pages still in memory. The page frames are often moved to secondary storage as the system likely will not need to use them as soon as other contents of the RAM.

The issues related to Virtual Memory management are two-fold, though. There is overhead required to track the changes of the location of the pages and update the Page Table. The second issue results when the system has a Page Fault and has to access information written to the swap space on the hard disk. The time to access these pages frames is slower due to the fact it is in secondary storage. The system must make a call to the hard drive, the hard drive must find the page in the swap space, read it into the drives buffer, and then transport the frame across the system bus, into physical memory. Only after these steps have occurred can it then be accessed by the processor and the thread it is needed for.

The Virtual RAM swap space for a Mac is held within the directory /private/var/vm. There are often several different swap space directories and also the directory of the sleepimage. This directory, private/var/vm/sleepimage, is where the entire contents of the machines RAM is written, as an encrypted disk image, when the computer sleeps long enough to go into hibernation.

Editor’s note: Virtual RAM needs can be significant and your machine will use every bit of free disk it has for this function. My workstation at Small Dog currently has about 225GB of free space. According to Activity Monitor, every scrap of that free space is allocated to virtual RAM. The general rule used to be to keep 10% or so of your hard drive free for virtual RAM. For a 200GB drive, that means roughly 20GB. I’m not sure what the cutoff is at this point, but the bottom line is that as your drive gets closer to filling up, you will notice performance dropping to the point where the machine may barely work at all.