Sign in
← Back to feed
Operating systems kuki 4 on this track
Orkhan Huseynli @orkhanhuseynli · · 2 min read

In my previous post, I talked about how a virtual address is structured. To recall, a virtual address has 2 parts: virtual page number (VPN) and the offset.

We also mentioned that the OS keeps a per-process data structure called page table. For now just imagine it as a list of page table entries (or PTEs).

When the process is running, the OS stores address of the page table in the page table base register (PTBR). So to find the page you're looking for, all you need to do is:

\(ThePage = PTBR + (VPN * sizeof(PTE))\)

Now, the PTE has some flags like dirty, present, some protection bits and so on (see the picture). The PTE also stores address of the actual physical page on RAM or on disk (if the page is swapped to disk).

page table entry

If the page you're accessing has present bit set to 0, a page fault will happen. Upon a page fault, the OS will either find the page's contents on disk or will send a SIGSEGV signal to the process and will kill it (because its invalid memory address). Which we call a segmentation fault.

Also when I say "a virtual address has 2 parts", don't believe me. There are also multi-level page tables, which are tree-like structures. In that case, VPN will have several parts like address of 1st level, 2nd level 3rd level etc.

Read more: https://pages.cs.wisc.edu/~remzi/OSTEP/vm-smalltables.pdf