Is virtual memory related to virtual address space of a process

pagingvirtual-memory

I have understood that Paging is a memory management technique which allows computer to bring data from secondary storage to main memory for executing process. It gives an impression to process that it has a large contiguous address space available to it (virtual address space).
Page table maps virtual addresses of a process to physical address.
Virtual addresses are the address that CPU uses. When need to access memory, physical address(actual address in RAM) corresponding to virtual address is obtained from page table using translation process.
And
concept of Virtual memory – when CPU needs memory more than the physical memory present, OS uses some part of secondary storage as RAM.

I get confused when I try to relate these two concepts. My question is – is virtual memory related to virtual address space of a process.
Is virtual address space of a process actually present in virtual memory? But how is it possible since virtual memory is actually part of secondary storage. OR virtual address space of process is located in RAM? Does both the Virtual and Physical address space of a process present in RAM?
Kindly clarify.

Best Answer

Virtual memory and paging should not be confused with the page file (also called the swap file).
The two concepts are indeed related, but still different.

Virtual memory refers to the virtual address space of a process: each process "thinks" it has a dedicated 32-bit (or 64-bit) address space, without actually doing so -- it might be that some pages don't actually exist in memory, or might exist at a different physical address, but the process doesn't care.

The method by which this is implemented is called paging: Whenever a process accesses memory, the Memory Management Unit translates the virtual address by looking up the physical page of RAM corresponding to the virtual page of memory. (A page is a larger unit of memory management, often 4KiB big). If no mapping exists, it triggers a page fault, to let the operating system know.

At this point, the operating system decides what happens next. It could terminate the program, it could generate the data randomly (!), or it could store or retrieve it from a page file (or swap file) on another storage device. But at this point, the hardware doesn't care what happens -- the operating system could do whatever it likes when handling the request.

So, virtual memory and the page file are not inherently related, but they just happen to come hand-in-hand in typical situations.

Related Question