Concept:
Virtual memory is a sophisticated memory management technique that provides an "abstraction" of the storage resources actually available on a given machine. It creates the illusion to the user and the application that the computer has a very large, contiguous working memory (address space), whereas in reality, the physical memory (RAM) might be quite small and fragmented.
Step 1: Separation of Logical and Physical Memory.
The key to this technique is the separation of the user's logical memory from the actual physical memory.
• Logical Address Space: The addresses generated by the CPU for a process. This space can be much larger than the available RAM (e.g., a 4GB process running on a machine with only 1GB of RAM).
• Physical Address Space: The actual hardware addresses in the RAM chips.
Step 2: How the Illusion is Maintained.
This is achieved through a combination of hardware and software. Only the "active" parts of a process are kept in the RAM, while the rest are stored on a secondary storage device like a Hard Disk Drive (HDD) or Solid State Drive (SSD) in a dedicated area known as the swap space or page file.
Step 3: Demand Paging.
When the CPU needs a piece of data that isn't currently in the RAM, a "Page Fault" occurs. The Operating System then fetches the required page from the disk and places it into an empty frame in the RAM. This "swapping" happens so fast that the application assumes all its data is readily available in the memory at all times.