Virtual memory is a feature of an operating system (OS) that allows a computer to compensate for shortages of physical memory by temporarily transferring pages of data from random access memory (RAM) to disk storage.
Eventually, the OS will need to retrieve the data that was moved to temporarily to disk storage -- but remember, the only reason the OS moved pages of data from RAM to disk storage to begin with was because it was running out of RAM. To solve the problem, the operating system will need to move other pages to hard disk so it has room to bring back the pages it needs right away from temporary disk storage. This process is known as paging or swapping and the temporary storage space on the hard disk is called a pagefile or a swap file.
Swapping, which happens so quickly that the end user doesn't know it's happening, is carried out by the computer’s memory manager unit (MMU). The memory manager unit may use one of several algorithms to choose which page should be swapped out, including Least Recently Used (LRU), Least Frequently Used (LFU) or Most Recently Used (MRU).
One of the major advantages of virtual memory is that it is the helping hand for computer to effectively manage physical memory and solves major problems of processes and their address space, it illustrate much larger memory than physical memory which can be used for applications which are even larger than the physical memory.
I think there is couple of reasons that could outweigh cost like it helps manage physical memory better; it swaps the process address back and forth to protect user data and code from being demolished by other processes.
Reference:
Rouse, M. (2014, Sep 15). virtual memory. Retrieved from Tech Target: