World's most popular travel blog for travel bloggers.

Virtual address lookup without using all the space to store the physical addresses

, , No Comments
Problem Detail: 

How is a virtual address mapped to a physical address?

The most logical solution I, with my meager knowledge, can think of would be to actually store the physical address. The problem with the above is that the more physical addresses there are, the bigger the number you need to store, which needs more physical memory to store said number. Meaning, you would need the majority of your memory to actually store the small amount of virtual data you actually want to save. Which seems absolutely stupid and unpractical.

But how does the system actually do it?

Asked By : black

Answered By : Gilles

What makes it work is that instead of storing the physical address corresponding to each virtual address, the system only stores the physical address corresponding to a page.

On a memory access, the MMU breaks the virtual address down into (virtual base address + offset), where the virtual base address is the address of the first byte of the page. It then looks up the virtual base address in a table (the page table) and obtains the corresponding physical address. The physical address of the original request is (physical base address + offset). For efficient hardware computation, the offset consists of the $n$ rightmost bits of the address.

A typical page size is 4096 bytes (i.e. the offset is the 12 low-order bits), and 4 bytes are used to store the physical address on a 32-bit machine, so it only takes 0.1% of the memory to store the page tables.

(I simplified many things: there are multiple levels of page tables, there's one page table per process on a typical multitasking system, the page size can vary, etc. But that doesn't change the fundamental idea.)

Best Answer from StackOverflow

Question Source :

3200 people like this

 Download Related Notes/Documents


Post a Comment

Let us know your responses and feedback