Saikat Das
Saikat Das

Reputation: 51

Multi-level page tables Hierarchical paging

Consider a virtual memory system with 32-bit virtual addresses and 1KB pages. Each page table entry requires 32-bits. It is desired to limit the page table size to one page.

  1. How many levels of page tables are required?
  2. Tables at two of the levels have 256 entries;tables at one level have 64 entries.(8+8+6=22). If the top level page table has 2^6 entries then how many pages are possible?
  3. If middle level page table has 2^6 entries then how many pages are possible ?
  4. If bottom level page table has 2^6 entries then how many pages are possible ?

Upvotes: 2

Views: 5655

Answers (1)

Dougvj
Dougvj

Reputation: 6585

There are 2^32/2^10 = 2^22 pages on such a system. This means that only 22-bits are needed to address a page. For simplicity and practicality, most modern systems would align that to 32-bits and use the extra bits as flags, so at 32-bit page table entries there are 16 MB in page table addresses. A single page can hold 256 entries, necessitating a total number of pages to 2^22 / 256 = 16384 for the deepest level. The next level would then have 16384 / 256 = 64; The highest level would fit on one page, since 64 < 256, and therefore the answer is 3.

If you disgregard 32-bit alignment (which would be untenable in real world scenarios), then the answer is still three, since at 22-bits there are a maximum of 372 entries per page and therefore, 2^22/ 372 = 11275 for the first and 11275 / 372 = 30 for the second, and 1 for the third.

Alternatively you could interpret it from top to bottom, so instead of starting from the deepest level you start from the top level. In this particular case, starting from the top will lead to the deepest level having the most unused entries per page. This is obviously not ideal and it is better to have unused page table entries at higher levels.

With either of these interpretations, however, the answer is unequivocally 3.

Upvotes: 6

Related Questions