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.