In the next section, the main reference is "deep Linux kernel Architecture" (section 3.3), linux-3.18.3
1. Operation on Pte
The items in the last Level page table contain not only pointers to the memory location of the page, but also additional information about the page in the above bits. Although these data are CPU -specific, they provide at least some information about page access control. The following bits can be found in most CPUs supported by the Linux kernel .
Arch/x86/include/asm/pgtable_types.h #define _PAGE_BIT_PRESENT 0/* is PRESENT */#define _PAGE_BIT_RW 1/writeable/#define _PAGE_BIT_USER 2 */Userspace addressable */#define _PAGE_BIT_PWT 3/* Page write through */#define _PAGE_BIT_PCD 4/* Page cache disabled */#define _PAGE_BIT_ACCE SSED 5/* is accessed (raised by CPU) */#define _PAGE_BIT_DIRTY 6/* was written to (raised by C PU) */#define _PAGE_BIT_PSE 7/* 4 MB (or 2MB) PAGE */#define _PAGE_BIT_PAT 7/* on 4KB PA GES */#define _PAGE_BIT_GLOBAL 8/* GLOBAL TLB entry ppro+ */#define _PAGE_BIT_SOFTW1 9/* Avail Able for programmer */#define _PAGE_BIT_SOFTW2/* */#define _PAGE_BIT_SOFTW3/* */#defin E _page_bit_pat_large/* on 2MB or 1GB pages */#define _PAGE_BIT_SPECIAL _page_bit_softw1#define _page_b It_cpa_test _page_bIt_softw1#define _page_bit_splitting _PAGE_BIT_SOFTW2/* Only valid on a PSE PMD */#define _page_bit_hidden _PA GE_BIT_SOFTW3/* Hidden by Kmemcheck */#define _PAGE_BIT_SOFT_DIRTY _PAGE_BIT_SOFTW3 */SOFTWARE DIRTY tracking */#defi NE _page_bit_nx */No execute:only valid after CPUID check */#define _PAGE_BIT_NUMA (_page_bi t_global+1) #define _page_bit_protnone _page_bit_global#define _page_bit_file _page_bit_dirty#define _PAGE_PR ESENT (_at (pteval_t, 1) << _page_bit_present) #define _PAGE_RW (_at (pteval_t, 1) << _PAGE_BIT_RW) #defi Ne _page_user (_at (pteval_t, 1) << _page_bit_user) #define _PAGE_PWT (_at (pteval_t, 1) << _page_bit_ PWT) #define _PAGE_PCD (_at (pteval_t, 1) << _page_bit_pcd) #define _page_accessed (_at (pteval_t, 1) << _p age_bit_accessed) #define _page_dirty (_at (pteval_t, 1) << _page_bit_dirty) #define _PAGE_PSE (_at (pteval_t, 1) << _page_bit_pSE) #define _page_global (_at (pteval_t, 1) << _page_bit_global) #define _PAGE_SOFTW1 (_at (pteval_t, 1) << _PAGE_BIT_SOFTW1) #define _PAGE_SOFTW2 (_at (pteval_t, 1) << _page_bit_softw2) #define _PAGE_PAT (_at (pteval_t , 1) << _page_bit_pat) #define _page_pat_large (_at (pteval_t, 1) << _page_bit_pat_large) #define _page_ Special (_at (pteval_t, 1) << _page_bit_special) #define _page_cpa_test (_at (pteval_t, 1) << _page_bit_cpa_te ST) #define _page_splitting (_at (pteval_t, 1) << _page_bit_splitting)
_page_present: Specifies whether the virtual memory page exists in memory. The page may be swapped out to the swap area.
_page_accessed: each time the CPU accesses the page, the _page_accessed is set automatically . The kernel periodically checks the bit to confirm how active the page is using. Pages that are not used more often are more suitable for swapping out. This bit is set after read-write access.
_page_dirty Indicates whether the page is "dirty", that is, whether the content of the page has been modified.
the value of _page_file is the same as _page_dirty , but it is used in different contexts, that is, when the page is not in memory. A nonexistent page cannot be dirty, so you can re-interpret the bit. If there is no setting, the item points to the location of a swap out page. If the item belongs to a non-linear file mapping, you need to set _page_file.
_page_user: Whether user-space code access is allowed. No settings can be accessed only in the kernel state.
_page_read,_page_write , and _page_execute Specify whether a normal user process allows reading, writing, executing, and its code in the page.
The pages in kernel memory must prevent user processes from writing. However, the page cannot be guaranteed to be writable, even if it belongs to a user process. For architectures with less granular access permissions, if there is no further guideline to differentiate between read and write access, a _PAGE_RW constant is defined that is used by colleagues to allow or disallow read and write access.
Each architecture must be provided so that the memory management subsystem can modify the extra bits in the pte_t key, the __pgprot data type of the bits that are saved , and modify those bits pte_modify function. The kernel also defines various functions for querying and setting the state of the memory page in relation to the architecture. The following functions are commonly used to set memory pages.
Function |
Describe |
Pte_present |
Whether the page is in memory |
Pte_read |
Whether the user space is readable |
Pte_write |
Whether you can write to the page |
Pte_exec |
Whether the data in the page can be executed as a binary |
Pte_dirty |
Whether the page is dirty or has its contents modified |
Pte_file |
Does the page table entry belong to a nonlinear map? |
Pte_young |
Access bit set up Yes No (_page_accessed) |
Pte_rdprotect |
Clear Read Permissions for this page |
Pte_wrprotect |
Clear Write Permissions for this page |
Pte_exprotect |
Clear permissions to perform binary data in this page |
Pte_mkread |
Set Read permissions |
Pte_mkwrite |
Set Write permissions |
Pte_mkexec |
Allow page content to be executed |
Pte_mkdirty |
Mark a page as dirty |
Pte_mkclean |
The purge page, often referred to as eliminating _page_dirty bits |
Pte_mkyoung |
Set access bits, which are _page_accessed on most architectures |
Pte_mkold |
Clear Access Bit |
These functions are often 3 1 groups that are used to set, delete, and query a specific property. The kernel assumes that access to page data can be controlled in 3 different ways, that is, read, write, and execute permissions.
2. Creation and operation of page table entries
Function |
Describe |
Mk_pte |
Create a page table entry. You must pass the page instance and the required pages access control permissions as parameters |
Pte_page |
Gets the page instance address for pages that are described by the page table entry |
Pgd_alloc |
Allocating and initializing memory that can hold a full page table |
Pud_alloc |
Pmd_alloc |
Pte_alloc |
Pgd_free |
Frees the memory occupied by the page table |
Pud_free |
Pmd_free |
Pte_free |
Set_pgd |
Set the value of an item in a page table |
Set_pud |
Set_pmd |
Set_pte |
Linux Kernel Explorer memory management (IV): Operations on page tables and page table entries