Virtual and Real Memory in PC

Real memory: refers to the physical memory chips that are physically installed in the computer. All programs actually run in this physical memory. However, as the programs concurrently running on a PC increase, real memory might not enough to accommodate those programs. Therefore, it is useful to allow PC to temporarily rent hard disk space (by creating a swap file on hard disk) for the memory purpose, which is called virtual memory. And those virtual memory is controlled by virtual memory manager which will be activated whenever virtual memory exists.

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. 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.

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.

Reference URL: http://www.pcguide.com/ref/ram/sizeVirtual-c.html