Monday, March 14, 2011

Virtual to Physical Memory Address

Taking example of 32-bit Windows Operating system. There are basically three types of entities involved in the address translation: Page Directory, Page Tables, Physical Pages. Page Directory contain pointers (PDEs) to Page Tables. Page Tables contain pointers (PTEs) to Data Pages (Pages those contain actual data referenced by the Virtual address). Each individual Page Directory and Page Table are maintained in separate Physical pages.

A virtual address will be 32-bit in size and will contain following members:

 - Page Directory Entry (PDE) Index: 10 Bits
 - Page Table Entry (PTE) Index: 10 Bits
 - Byte Index: 12 Bits.

Since page size is 4KB, 12-bit Byte Index is sufficient to reference each individual byte in a page. Similarly 10 bit PDE and PTE Index are sufficient to refer each individual 4-byte word in a page.
(Number of Bytes in page: 4096, Number of PDE/PTE in a page: 1024)

PDE and PTE are nothing but pointer to actually Physical pages in the memory. They have a similar structure and same size. In this case they are 4 bytes in size.

PDE/PTE consists of two parts: PFN (Page Frame Number) and Sw/Hw Flags associated with that pages.
Flags help memory manager to manage the pages.

PFN is nothing but physical location of each page. PFN is 20-bits long and Page size is 4KB, therefore it can be used to address 4GB physical memory.

The scheme can be modified for different application areas such as addressing large address space, ability to recognize more thatn 4GB of physical memory. The modification include adding more levels in translation, increasing PTE/PDE size, etc.

No comments:

Post a Comment