Virtual memory refers to the technology in which some space in hard disk is used as an extension of main memory so that a user program need not worry if its size extends the size of the main memory. If that does happen, at any time only a part of the program will reside in main memory, and other parts will otherwise remain on hard disk and may be switched into memory later if needed.
With virtual memory, if a piece of process that is needed is not in a full main memory, then another piece will be swapped out and the former be brought in. If unfortunately, the latter is used immediately, then it will have to loaded back into main memory right away. As we know, the access to hard disk is time-consuming compared to the access to main memory, Thus the reference to the virtual memory space on hard disks will deteriorate the system performance significantly. Fortunately, the principle of locality holds; that is the instruction and data references during a short period tend to be bounded to one piece of process. So the access to hard disks will not be frequently requested and performed. Thus, the same principle, on the one hand, enables the caching mechanism to increase system performance, and on the other hand avoids the deterioration of performance with virtual memory. With virtual memory, there must be some facility to separate a process into several pieces so that they may reside separately either on hard disks or in main memory. Paging or/and segmentation are two methods that are usually used to achieve the goal.