Example question from a past operating system final, how do I calculate this kind of question?
A computer has a 64-bit virtual address space and 2048-byte pages. A page table entry takes 4 bytes. A multi-level page table is used because each table must be contained within a page. How many levels are required?
How would I calculate this?
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).
To keep track of the frames storing the pages of the divided page table, another page table is maintained. As a result, the hierarchy of page tables get generated. Multilevel paging is done till the level is reached where the entire page table can be stored in a single frame.
Each level of page tables will require a 16 bit page number (because 216 is the maximum size of each page table). Thus, a total of 3 levels of page tables will be required.
The advantage of a multilevel (hierarchical) page table over a single-level one is: (a) Page number lookups are faster. (b) The page table can consume much less space if there are large regions of unused memory. (c) Each segment (code, data, stack) can be managed separately.
Since page table must fit in a page, page table size is 2048 bytes and each entry is 4 bytes thus a table holds 2048/4=512 entries. To address 512 entries it requires log2(512)=9 bits. 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).
The x86-64 default page table size is 4096 bytes, each page table must fit in a page and a page table entry is 8 bytes. Current CPUs only implement 48 bits of virtual address space. How many page table levels are required?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With