Real and Virtual Memory
Real memory refers to the actual memory chips that are installed in the computer. All programs actually run in this physical memory. However, it is often useful to allow the computer to think that it has memory that isn't actually there, in order to permit the use of programs that are larger than will physically fit in memory, or to allow multitasking (multiple programs running at once). This concept is called virtual memory.
The way virtual memory works is relatively simple. Let's suppose the operating system needs 80 MB of memory to hold all the programs that are running, but there are only 32 MB of RAM chips installed in the computer. The operating system sets up 80 MB of virtual memory and employs a virtual memory manager, a program designed to control virtual memory, to manage the 80 MB. The virtual memory manager sets up a file on the hard disk that is 48 MB in size (80 minus 32). The operating system then proceeds to use 80 MB worth of memory addresses. To the operating system, it appears as if 80 MB of memory exists. It lets the virtual memory manager worry about how to handle the fact that we only have 32 MB of real memory.
Of course, not all of the 80 MB will fit in the physical 32 MB that exist. The other 48 MB reside on the disk, in the file controlled by the virtual memory manager. This file is called a swap file. Whenever the operating system needs a part of memory that is currently not in physical memory, the virtual memory manager picks a part of physical memory that hasn't been used recently, writes it to the swap file, and then reads the part of memory that is needed from the swap file and stores it into real memory in place of the old block. This is called swapping, for obvious reasons. The blocks of memory that are swapped around are called pages.
Virtual memory was a very important invention in computing, as it allows multitasking as we know it today. Without virtual memory, you couldn't run a spreadsheet, word processor and database program at the same time unless you had enough memory to hold all of them at once, because you would constantly be running out of memory and having to shut down program "A" in order to open program "B". Most PCs, when running multitasking operating systems like Windows 95, are using virtual memory.
However, virtual memory can also hamper performance. The larger the virtual memory is compared to the real memory, the more swapping has to occur to the hard disk. The hard disk is much, much slower than the system memory. Trying to use too many programs at once in a system with too little memory will result in constant disk swapping, called thrashing.
Thrashing can cause system performance to slow to a crawl. It is caused especially when trying to use an operating system with a lot of system overhead, such as Windows NT, on a computer
with insufficient system RAM. If you try to run Windows NT on a PC with only 16 MB, the operating system will have to swap almost constantly whenever you run an application, because Windows NT itself needs about 12-16 MB to run. The PC can't hold NT and the application you are trying to use in memory at the same time, and it will thrash wildly swapping system tasks and application tasks back and forth from the hard disk.
In a real system, it's important to carefully manage how the total memory in the system is used. Some systems try to improve performance through the use of disk caching. As they say, the road to performance hell is often paved with good intentions. In some cases, the system will reserve so much of system memory
for caching disk accesses, that the remaining memory isn't enough and thrashing will occur. So you are using part of disk as virtual memory, and part of your memory as virtual disk. Talk about self-defeating! See this section of the Optimization Guide for ideas on optimizing virtual memory and the swap file.