Search code examples
assemblyoperating-systempagingvirtual-memorymemory-segmentation

we see virtual address of a process (in paging system), where does these virtual address exist?


We see virtual address corresponding to any instruction,so my question is where does these virtual address exist ? If we see disassembly in gdb we saw virtual address where does these address reside ? Please don't say it is only virtual address it have to mapped to a physical address by page table, I know it but where these virtual address that we saw in gdb exist ? In RAM or in Hard disk ?


Solution

  • An address (or any other numeric value for that matter) can exist in CPU registers, memory and any other storage, including disk. But that probably isn't surprising to you nor is what you're asking about.

    If we're talking about 32-bit x86 page translation, then page tables don't contain virtual addresses that undergo translation to physical addresses. Page tables contain only physical addresses, but not virtual. It is not needed to store virtual addresses inside page tables.

    Let's simplify things and suppose that the system has only one page table and this page table contains 1024 physical addresses of code/data pages. Where are virtual addresses in here? They are pretty much indices into the page table. If pages are 4KB in size and all addresses are 22-bit, then the 12 low bits of a virtual address specify the location inside a code/data page (0 to 4095) and the 10 top bits of a virtual address select one of the 1024 pages through the page table. When the CPU uses a virtual address to access memory, it breaks the virtual address into an index into the page table and into an offset within the selected page. Then it gets the physical address of the page (from the page table), adds the offset within the page to it and then uses the resultant physical address read or write memory at.