Reputation: 51
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.
Upvotes: 2
Views: 5655
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