Page table structure and page table item format in x86

Source: Internet
Author: User

I. page table structure

The paging conversion function is described by a table residing in the memory. This table is called a page table and is stored in the physical address space. A page table can be seen as a simple array of 220 physical addresses. The linear-to-physical address ing function can be simply used as an array for searching. The top 20 digits of a linear address constitute the index value of this array, which is used to select the physical (base) Address of the corresponding page. The low 12 bits of the linear address give the offset in the page, and the base address of the page forms the corresponding physical address. Because the base address of the page is aligned on the 4 K border, the base address of the page must be 12 characters low. This means that the base address of the 20-bit page is connected together with the 12-bit offset to obtain the corresponding physical address.

The size of each page table item in the page table is 32 bits. Because only 20 of them are required to store the physical base address of the page, the remaining 12 digits can be used to store attribute information such as whether the page exists. If the page table item of the linear address index is marked as an existing one, this item is valid and we can obtain the physical address of the page. If the information in the page table item indicates (description, description) that the page does not exist, an exception occurs when accessing the corresponding physical page.

1. Two-level page table structure

The page table contains 220 (1 m) Table items, and each item occupies 4B. If they are stored as a table, they occupy up to 4 MB of memory. Therefore, to reduce memory usage, 80x86 uses two-level tables. As a result, the conversion from a 20-bit linear address to a physical address is also divided into two steps. Each step uses (converts) 10 bits.

The first-level table is called the page Directory ). It is stored on a 1-page 4 K page and has 210 (1 k) Entries of 4B length. These table items point to the corresponding second-level table. The maximum value of a linear address is 10 bits (31-bit ~ 22) used as the index value in the first-level table (page Directory) to select one of the 210 second-level tables.

The second-level table is called a page table. Its length is also 1 page and contains a maximum of 1 kb of table items. Each 4B table item contains the 20-bit physical base address of the relevant page. The second-level page table uses 10 digits in the middle of the linear address (BITS 21 ~ 12) as the index value of the table item to obtain the table item containing 20 physical base addresses on the page. When the physical base address of the 20-bit page is combined with the low 12-bit (intra-page offset) of the linear address, the output value of the paging conversion process is obtained, that is, the final physical address.

Figure 4-17 shows the second-level table search process. The base address of the page Directory table is specified in the "3" register. The top 10 digits of a linear address are used to index the directory table on this page to obtain a pointer to the table on the second-level page. The 10-bit linear address center is used to index the second-level page table to obtain the 20-bit high physical address. The low 12-bit linear address is directly used as the low 12-bit physical address, thus forming a complete 32-bit physical address.



(Click to view the larger image) Figure 4-17 transformation between linear and physical addresses

2. nonexistent page table

Using the second-level table structure does not solve the problem of using 4 MB memory to store the page table. In fact, we have made the problem a little complicated. Because we need to add another page to store the directory table. However, the second-level table structure allows the page tables to be dispersed in various pages of the memory, instead of being stored in a continuous 4 MB memory block. In addition, you do not need to allocate a second-level page table for nonexistent or linear address spaces that are not used. Although the directory Table Page must always exist in the physical memory, the level-2 page table can be distributed as needed. This makes the size of the page table structure correspond to the actual linear address space.

Each table item in the page Directory also has a present attribute, similar to the table item in the page table. The existence attribute in the page Directory table item specifies whether the corresponding second-level page table exists. If the directory table item specifies that the corresponding second-level page table exists, then by accessing the second-level table, step 1 of the table search process will continue with the above description. If the existence bit indicates that the corresponding second-level table does not exist, the processor will generate an exception to notify the operating system. The existence attribute in the page Directory table item allows the operating system to allocate a second-level page table page based on the linear address range actually used.

The existence bits in the directory table item can also be used to store Level 2 page tables in the virtual memory. This means that at any time, only some second-level page tables need to be stored in the physical memory, while others can be stored on the disk. The page Directory items corresponding to the page table in the physical memory will be marked as exist to indicate that they can be used for paging conversion. The page Directory corresponding to the page table on the disk will be marked as non-existent. An exception caused by the absence of a second-level page table will notify the operating system to attach the missing page table to the disk to the physical memory. Storing page tables in virtual memory reduces the amount of physical memory required to save the paging conversion table.

Ii. page table item format

The table item format of the page Directory and page table is 4-18. 31-31 ~ 12. It is a physical base address with a 20-bit high address. It is used to locate a page (also called a page frame) in a physical address space. The low 12-bit table item contains page attribute information. The previous article has discussed the existence of attributes. Here we will briefly describe the functions and usage of other attributes.



(Click to view the big chart) Figure 4-18 table item format of the Directory and page table

P -- bit 0 is the presence flag, used to indicate whether the table item is valid for address conversion. P = 1 indicates valid; P = 0 indicates invalid. During page conversion, if the involved page directory or table items are invalid, an exception will occur. If P = 0, in addition to indicating that the table item is invalid, the other bits are available to the program, as shown in 4-18b. For example, the operating system can use these bits to save the sequence numbers of pages that have been stored on the disk.

R/W -- bit 1 indicates Read/Write. If the value is 1, the page can be read, written, or executed. If the value is 0, the page is read-only or executable. R/W Bit does not work when the processor runs at the Super User Privilege level (level 0, 1, or 2. The R/W bits in the page Directory take effect on all pages mapped to it.

U/S-bit 2 is the User/superuser sign. If the value is 1, programs running on any privileged level can access this page. If the value is 0, the page can only be accessed by programs running on the Super User Privilege level (0, 1, or 2. The U/S bit in the page Directory item takes effect on all pages mapped to it.

A-bits 5 are the Accessed mark. When the processor accesses the page table item ing page, this flag of the page table item will be set to 1. When the processor accesses any page mapped to the page Directory table items, this flag of the page Directory table items will be set to 1. The processor is only responsible for setting this flag. The operating system can periodically reset this flag to count the page usage.

D-bit 6 indicates that the page has been modified (Dirty. When the processor performs a write operation on a page, the D flag of the corresponding page table item is set. The processor does not modify the D flag in the page Directory.

AVL -- this field is reserved for the program. The processor will not modify these digits, and will not upgrade the processor in the future.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.