From Wikipedia Encyclopedia
Virtual memory is a computer design feature that
permits software to use more memory than the computer physically possesses. In technical terms, it
allows software to run in a memory address space whose size and addressing
are not necessarily tied to the computer's physical memory. While
concievably virtual memory can be implemented solely by operating system
software, in practice its implementation almost universally uses a
combination of hardware and operating system software.
Virtual memory has been a feature of Microsoft Windows since Windows 3.1
in 1992. 386SPART.PAR (or "WIN386.SWP") is a hidden file created by
Windows 3.1 for use as a virtual memory swap file. It is generally found
in the root directory, however it may appear elsewhere (typically in the
WINDOWS directory). Its size depends on how much virtual memory the system
has set up under (Control Panel) - Enhanced under "Virtual Memory." If a
user moves or deletes this file, Windows will complain the next time it is
started with a "Swap File error."
Windows 95 uses a similar file, except it is named WIN386.SWP, and the
controls for it are located under Control Panel - System - Performance tab
- Virtual Memory.
How it works
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.