Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Number of page table index bits in multilevel paging

A processor uses 36 bit physical addresses and 32 bit virtual addresses with a page frame size of 4 KBytes. Each page table entry size is of 4 bytes. A three level page table is used for virtual to physical address translation, where the virtual address is used as follows :

bits 30 - 31 are used to index into the first level page table
bits 21 - 29 are used to index into the second level page table
bits 12 - 20 are used to index into the third level page table
bits 0 - 11 are used as offset within the page

The number of bits required for addressing the next level page table ( or page frame ) in the page table entry of the first , second and third level page tables are respectively ?

This was a question asked in GATE 2008.
My Analysis: The maximum number of page frames = (physical address size) / ( page size ) = 2^36 / 2^12 = 2^24. Thus, 24 bits will be enough to index the page numbers in the 3rd level page table. Now we have to find out how many page tables will be there in the 3rd level. Its given that 9 bits are used to index into the 3rd level page tables. So there are 2^9 page tables in level 3. That means 2^32 virtual space is contained in 2^9 page tables so entries per page table= 2^32/2^9 = 2^23. So 23 bits are required in an l2 page table entry to index the entries of a particular page table in 3rd level page table. 2^9 page tables are there in L2 from L1 page table we need to get to any one of these 2^9 page tables. So 9 bits are required in L1.

This analysis somehow doesn't seem right. I am very much confused. Can someone please explain the concepts ?

like image 934
Unni Avatar asked Feb 11 '14 12:02

Unni


People also ask

How many bits are needed to index the page table?

Each page table page can hold 216/4, or 214, page table entries. Thus, for each page table level, we will use 14 bits of the virtual address to index into that page table page.

What is page table explain multilevel paging?

Multilevel Paging is a paging scheme that consists of two or more levels of page tables in a hierarchical manner. It is also known as hierarchical paging. The entries of the level 1 page table are pointers to a level 2 page table and entries of the level 2 page tables are pointers to a level 3 page table and so on.

How many levels are there in multi level page table?

The total number of bits available to encode the entry for each page level is 64-log2(2048)=53 bits (the number of bits of address space minus the page offset bits). Thus the total number of levels required is 53/9=6 (rounded up).

How many page table entries are needed for two level paging where 8 bits is used for each level of the page table?

It's desirable to fit a 2nd-level page table in one page. So total number of entries in the 2nd-level page is = 2^10 (size of page) / 2^2 (size of one page table entry) = 2^8. Therefore, we have 14 bits in outer page table and 22-14=8 bits for inner page table and 10 bits for offset.


1 Answers

At first we have physical address of 2^36, and page size is 2^12. Hence 2^24 should be the number of pages. and you figured that right.

Since given 9 bits for 3rd level page table, ie 2^9 and then 4 bytes per entry, so 2^11. Now 2^36/2^11 would give 2^25. Hence 25 bits (25 bits at second level table).

Now again given 9 bits for second level page table. so the same logic applies again 2^36/2^11, which again is 2^25.(25 bits at first level table).

hence the answer must be 25,25,24

One thing that you have to understand is, that though virtual address space is 2^32, we need to map the entire 2^36 entries and not 2^32.Also, each page can take care of 2^9 * 2^2, and you didn't consider this 2^2 as well. The same thing holds at the higher level as well

You should have a look at this question and this wikipedia entry, especially the figure.

like image 73
Amrith Krishna Avatar answered Nov 28 '22 17:11

Amrith Krishna