sincosmos
sincosmos

Reputation: 390

Why does Page Directory entries need 20 bits to point 2^10 Page Tables?

I was learning Linux memory management recently, now I am stopped by the paging mechanism.

As with Regular Paging for 32-bit processors, why page directory entries (32 bits in total) need 20 bits to indicate 2^10 Page Tables? I think 10-bits is just enough and no waste. What is wrong with my understanding?

Picture from Wiki

Thank you.

Upvotes: 0

Views: 2213

Answers (3)

Kshitij Patil
Kshitij Patil

Reputation: 86

For a 32-bit processor, it will generate 32-bit address.

If an address generated is 32-bit then, addressable memory is 4GB.(As 2^32 = 4GB)

Now, both page table and page directory reside on memory within a single page.

Also, page size is 4kB.

And in page directory and page table, entries always point to border or edge of page table and page directory respectively.

If you divide 4G(1G=2^30) by 4k(1k = 2^10), you'll get 2^20

That is we need 20bits to access all of 4kb chunks within 4GB memory or maximum addressable memory.

That is why, entries for page table and page directory are always 20-bits

Upvotes: 0

Alex Hoppus
Alex Hoppus

Reputation: 3935

Regular x86 uses 2 level pagetable, but i think the case is that they talk here about one-level page table ... So you have one huge structure with 2^20 entries, each entry associate virtual page address (mentioned 20 bits) with physical page address. Can you provide a link where have you found this picture?

Upvotes: 0

CL.
CL.

Reputation: 180210

A page has a size of 4096 bytes, i.e., 2^12 bytes.

This means that pages are aligned to a multiple of 4 KB, and that the address of a page is xxxxxxxxxxxxxxxxxxxx000000000000. In other words, a page address needs 12 bits less than the address bus size. For 32-bit addresses, this ends up being 20 bits.

A page directory entry has 32 bits, so 2^10 of them fit into a 4 KB page.

Upvotes: 2

Related Questions