Page Table


Q&A

  • What does an page table entry contain?
  • Where is the page permission stored?

  • If one entry’s present flag is off, OS can use this entry for other purpose. What can be other purpose? and How to use it properly?


Page table descriptors

Descriptors (types of different PT entries):

  • pte_t: 64-bit/PAE, page table
  • pmd_t: 64-bit/PAE, page middle directory
  • pud_t: 64-bit/PAE, page upper directory
  • pgd_t: 64-bit/PAE, page global directory
  • pgprot_t: 64-bit/PAE, represents the protection flags associated with a single entry.

Cast from integer to the PT entries type: __pte, __pmd, __pud, __pgd, __pgprot

Entries of page directories and page tables have the same structure. Each entry includes the following fields:

  • Present flag. If set, the page is in main memory; If the flag is 0, the page is not contained in main memory and the remaining entry bits may be used by the operating system for its own purposes.
    • when present is cleared for a virtual-physical translation request, then the vaddr will be stored in cr2, and exception 14 - Page Fault will be generated.
  • 20-bit (=32-12) field as page frame physical address.
  • accessed flag. set each time the paging unit addresses the page. OS can use this for swapping. Paging unit will not reset the flag. OS should reset it instead.
  • dirty
  • read/write
  • user/supervisor: contains the privilege level required to access the page or Page Table.
  • PCD & PWT flag. cache control.
  • Page Size flag. Only for Page Table entries. If set, the entry refers to a 2MB or 4MB long page frame.
  • Global flag. Only for Page Table entries. Prevent frequently used pages from being flushed from TLB cache. Works only if Page Global Enable flag of register cr4 is set.

Page Flag setting functions

  • pte_wrprotect() // clears the Read/Write flag
  • pte_rdprotect() // clears the User/Supervisor flag
  • pte_exprotect() // clears the User/Supervisor flag
  • pte_modify(p,v) // set all access right in a PT entry p to a specified value v

Macros acting on Page Table entries

  • pgd_index(addr) // get the index in the page global directory for address addr.
  • pgd_offset(mm, addr) // get the linear address of the entry in a page global directory.
  • mk_pte(p, prot) // receives as parameters the address of a page descriptor p and a group of access rights prot, and builds the correponding Page Table entry.

Page Allocation Functions

  • pgd_alloc(mm) // page global directory
  • pgd_free(pgd)

Reference 1


  1. Understanding the Linux Kernel, 3rd Edition. ↩
Created May 5, 2020 // Last Updated May 5, 2020

If you could revise
the fundmental principles of
computer system design
to improve security...

... what would you change?