How to convert a virtual address to PFN, that is, the page frame number

Source: Internet
Author: User

 

How to convert a virtual address to PFN, that is, the page frame number (that is, the mem_map array subscript is the array of all the physical page description structures, through which you can find the struct page)

The virtual address in the kernel, but a page_offset is added to the physical address, which is 3 GB on x86, as long as the virtual address in the kernel is directly reduced to 3 GB.

UserProgramThe Static Virtual Address is set during compilation. The dynamic address (such as malloc) is set in VMA through the kernel page-based memory management, you need to find the page table in the task_struct of the process and obtain the physical address through level-1 translation.

 

 

During actual compilation, the address is called the logical address, which requires segment management for translation, that is, the segment base address and intra-segment offset. Because the base address of this segment in Linux is 0, therefore, the logical address directly corresponds to the virtual address.

 

 

After obtaining the physical address, we will first convert the low three digits in hexadecimal format to 0. In this way, we will obtain the physical address of the page. Here, we will refer to the 4 K page, then, subtract the address of the first element of mem_map from the physical address of the page to obtain the subscript of this page in the mem_map array. (Note that the pointer Subtraction is not the address subtraction represented by the pointer, instead, the pointer between the two represents the number of element types.) This subscript is PFn. You can get the struct Page Structure by knowing the subscript in the array, you can understand all the page conditions.

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.