Search code examples
memoryoperating-systempagingpage-tables

Calculating the size of a 2-level page table


So I have page sizes of 4kb, 32 bit address CPU and an implemented 2-level page table.

I want to store 1081 pages, so I need:

  1. 1024 entries in the 2-nd level page-table
  2. 57 entries in another 2-nd level page table
  3. A top level page table holding 2 entries.

Now, do I need to store in memory the full size of these page table or just what they occupy?

  1. In the first case, I would then use 4bytes * 2 + 4bytes * 1024 + 4bytes * 57
  2. Otherwise it would be 1 * 4bytes * 1024 + 2 * 4bytes * 1024

Any hint?


Solution

  • You would need 3 pages (or 12K) for your page table - one for the top level page, and two 2nd level pages. Allocating just the space that is currently needed would be more complicated and likely slower than the alternative.

    Check out Prof. Levy's slides for some nice pictures on two level paging.