When the memory manager sees that some pages are not being used very often it may decide to place these into virtual memory. Quite simply the pages to be swapped will be placed into a special file on the hard drive called the swap file (or page file). The memory manager will then make a note of which pages are in virtual memory and where about in the swap file the page is. It is beyond the scope of this course to look at swapping algorithms.

Virtual memory is commonly used to allow programs to run which may require more memory than is physically available. Image manipluation programs fall into this group. Consider a high definition image of size 4000 x 3000 in 32 bit colour. Each pixel will need 4 bytes to store so -

4 x 4000 x 3000 = 48,000,000 Bytes or 45.7Mb

Image manipulation programs always end up using double or triple the amount of memory for each image (for it's processing). So we could need alomst 150Mb just for one image! It is not hard to see how programs will very quickly eat up all of your memory.

As the hard drive is much slower than main memory the choice of which pages get swapped is important. If poor choices are made there would be a significant reduction in speed. Until the page is loaded back into main memory, that process is blocked. When poor choices are made and lots of memory is continually swapped in and out of main memory you get a situation where the computer becomes very unresponsive. You will also notice the hard drive light on almost continuously. This is known as thrashing. Thrashing occurs when the OS starts making poor choices for swapping pages. This situation can be improved by either updating the OS or getting more main memory. More main memory means less virtual memory will be needed.

One last problem with using virtual memory too much is that it could cause the hard drive to become fragmented. This means that files are not stored in a continuous stream. As we are saving just 32KB per swap, the file manager may place this in different parts of the hard drive. Files then start to become more and more fragmented. This again will reduce system performance but can be rectified by running a defrag tool.