Search code examples
operating-systemvirtualization

Does a virtual address always translate to a physical one


I am studing operating systems and I have one question. Does a virtual address always translates to a physical one and if so why ?


Solution

  • No.

    You can see this similarly to physical memory. If your CPU can address like 64 GiB of memory (as with x86 and PAE), are you required to have 64 GiB of memory installed? No.

    If you have an (x86) instruction addressing memory, like

    mov eax, [1234h]
    

    the double word at the virtual address 1234h = 0x1234 is attempted to be accessed. Now, roughly the following happens:

    1. The page table is checked whether it defines a corresponding page frame for the page addressed by 0x1234.

    2. If not, a page fault is raised. In this case, the virtual address 0x1234 does not translate to a physical one.

    3. If yes, the MMU calculates the physical address from the virtual address and returns the double word located there. The execution flow proceeds normally.

    After all, not all pages are necessarily mapped to page frames, i.e., physical memory. This case is indicated by a page fault, which is handled by a page fault handler.
    You should also read this on how paging works.