Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Page Tables are stored in the main memory?

i know that page tables are stored in memory , and each process has its own table , but each table has entries as the number of virtual pages in virtual memory so how can every process has a table and each table resides in main memory besides , the number of entries in each table is larger than the number of physical pages in main memory ...can someone explain that to me i'm very confused , Thanks in Advance.

like image 530
SE Student Avatar asked Dec 04 '22 06:12

SE Student


1 Answers

Typically, page tables are said to be stored in the kernel-owned physical memory. However page tables can get awfully big since each process have their own page tables (unless the OS uses inverted paging scheme). For even a 32 bit address space with a typical 4KB page size, we shall require a 20 Bit virtual page number and a 12 bit offset. A 20 bit VPN(Virtual Page Number) implies that there would be 2^20 translations. Even if each translation i.e the Page Table entry requires 4 Bytes of memory, it amounts to 4x(2^20)= 4MB of memory, all just of address translations, which is awful.

Hence modern OSes place such large page tables in virtual kernel memory which is the Hard Disk, and swaps them to the physical memory whenever required. Thus page table is virtualized the same way each page is virtualized.

I would suggest you to go through this wonderful and easy book to get a clear under standing of Memory Virtualization and Paging related concepts: http://pages.cs.wisc.edu/~remzi/OSTEP.

like image 115
Old Markus Avatar answered Apr 06 '23 22:04

Old Markus