Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why using hierarchical page tables?

I'm learning the Linux kernel and reading the book The Linux Kernel.

Can anybody explain why can't we just use the table which maps directly between logical and physical memory instead of the tree-like multilevel structure?

Added:

The total number of entries needed is fixed, so I assume that it's more space wasting to store a complicated structure than a simple one.

like image 200
Determinant Avatar asked Mar 23 '12 05:03

Determinant


People also ask

What is the main advantage of using hierarchical page tables over linear page tables?

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.

What is a hierarchical page table?

Multilevel Paging is a paging scheme that consists of two or more levels of page tables in a hierarchical manner. It is also known as hierarchical paging. The entries of the level 1 page table are pointers to a level 2 page table and entries of the level 2 page tables are pointers to a level 3 page table and so on.

Why do we use multilevel page table?

Paging has multiple advantages over segmentation. We no longer need a complex memory allocation algorithm, since any free physical page can be used when space is allocated. Program sections no longer need to be contiguous, and there is no external fragmentation.

What is the advantage offered by inverted page tables over forward page tables?

Reduced memory space – Inverted Pagetables typically reduce the amount of memory required to store the page tables to a size bound of physical memory.


2 Answers

You will appreciate the space optimization of multi-level page tables when we go into the 64-bit address space.

Assume you have a 64-bit computer ( which means 64 bit virtual address space ), which has 4KB pages and 4 GB of physical memory. If we have a single level page table as you suggest, then it should contain one entry per virtual page per process.

One entry per virtual page – 264 addressable bytes / 212 bytes per page = 252 page table entries

One page table entry contains: Access control bits ( Bits like Page present, RW etc ) + Physical page number

4 GB of Physical Memory = 232 bytes.

232 bytes of memory/212 bytes per page = 220 physical pages

20 bits required for physical page number.

So each page table entry is approx 4 bytes. ( 20 bits physical page number is approx 3 bytes and access control contributes 1 byte )

Now, Page table Size = 252 page table entries * 4 bytes = 254 bytes ( 16 petabytes ) !

16 petabytes per process is a very very huge amount of memory.

Now, if we page the pagetable too, ie if we use multi level page tables we can magically bring down the memory required to as low a single page. ie just 4 KB.

Now, we shall calculate how many levels are required to squeeze the page table into just 4 KB. 4 KB page / 4 bytes per page table entry = 1024 entries. 10 bits of address space required. i.e 52/10 ceiled is 6. ie 6 levels of page table can bring down the page table size to just 4KB.

6 level accesses are definitely slower. But I wanted to illustrate the space savings out of multi level page tables.

like image 87
Pavan Manjunath Avatar answered Oct 30 '22 15:10

Pavan Manjunath


http://en.wikipedia.org/wiki/Page_table#Multilevel_page_table is to overcome the Inverted page table's pitfalls.

like image 36
Dyno Fu Avatar answered Oct 30 '22 13:10

Dyno Fu