2
votes

Suppose that a machine has 38-bit virtual addresses and 32-bit physical addresses.

(b) With a two-level page table, 16-KB pages, and 4-byte entries, how many bits should be allocated for the top-level page table field and how many for the next level page table field? Explain.

And here's the answer:

The offset field requires 14 bits to address 16 KB. That leaves 24 bits for the page fields. Since each entry is 4 bytes, one page can hold 16KB / 4 byte = 2^12 page table entries and therefore requires 12 bits to index one page. So allocating 12 bits for each of the page fields will address all 2^38 bytes.


I don't quite understand if we have offset 14 bit which is used to address within the page, then what is one page can hold 16KB / 4 byte = 2^12 ? Another offset?

1

1 Answers

5
votes

To answer original question:
No, it is not a second offset, it is just used as index inside in the second-level page table. First 12 bits act as index to the entry in the first level, second 12 bits act as index inside the secondary page table.


  • 38 bit virtual addresses
  • 16KB page size
  • 32 bit physical addresses

We can conclude:

  1. main memory size is 2^32 = 4GB.
  2. log2(16K) = 14, 14 bits for offset.
  3. Page entry is 4 bytes
  4. 38-14 = 24 bits to reference page
  5. 2^24 different virtual pages
  6. 2^18 different physical frames

Now assume we want to allocate space for a page table, if we allocate it a page which is 16KB, how many entries will it have ? 16K/4 = 4K entries.

PAGE:
0x000   entry 1
0x001    
0x002    
0x003          
-----------------
0x004   entry 2
0x005
0x006    
0x007
------------------
.       entry 3
.
.
. 
------------------
0xFFC   entry 4096 (NOTE! 4K = 4096 as its 2^12)
0xFFD
0xFFE
0xFFF
------------------

Now if we divide the 24 bits for pages in half, 12 bits for first level page and 12 bits for second level page. How many pages can we address ?

First level has 2^12 different pages, where each entry points to a second level page table. Second level page table also has 2^12 entries, each entry points to a frame which its size is 16KB.

(2^12)*(2^12)*(2^14) = 2^38

With this 2-level page tables you can address 2^38 virtual addresses.