Linux Kernel missing page

Source: Internet
Author: User

Linux Kernel missing page

The entire page missing Exception Processing process is very complicated. Here we will only briefly introduce the kernel functions involved in the page missing.

When the CPU generates an exception, it will jump to the entire exception handling process. For page missing exceptions, the CPU jumps to the page_fault exception handler. the handler calls the do_page_fault () function, which reads the CR2 register to obtain the linear address that causes the page missing, identify conditions to determine an appropriate solution to handle this exception.

Do_page_fault () This function uses various conditions to detect the current exception. However, at least do_page_fault () identifies two scenarios that cause page missing: exceptions caused by programming errors, this is caused by linear addresses in the process address space that do not allocate physical memory. In the latter case, it is usually divided into page missing exceptions caused by user space and page missing exceptions caused by kernel space. The kernel exception is caused by vmalloc (), which is only used for memory allocation in the kernel space. Here we need to pay attention to the exceptions caused by the user space. This part of work starts from the good_area label in do_page_fault (), mainly through handle_mm_fault.

Handle_mm_fault () The main function of this function is to assign a physical page box to the process that causes page defects. It first determines whether the page Directory items at all levels corresponding to the linear address that causes page defects exist, if there is no such rule, distribute it by minute. You can call handle_pte_fault () to allocate this page.

Handle_pte_fault () this function is divided into two categories based on whether the physical page boxes described by the page table item pte are in the physical memory: Request page: The accessed page boxes are no longer stored in the main memory, A page box must be allocated. Copy at write time: the accessed page exists, but the page is read-only. The kernel needs to write the page, at this time, the kernel copies the data on this existing read-only page to a new page box. User processes access the memory space allocated by malloc. For request page adjustment, handle_pte_fault () still divides it into three types:

1. If the page table item is indeed empty (pte_none (entry), you must assign a page box. If the current process implements the fault hook function in the vma operation function set, this is a file-based memory ing. It calls do_linear_fault () to allocate a physical page. Otherwise, the kernel will call the function do_anonymous_page () that assigns a physical page box for anonymous ing ().

2. If the table entry on this page is detected as a non-linear ing (pte_file (entry), do_nonlinear_fault () is called to allocate a physical page.

3. If the page box is allocated in advance, but has been swapped out from the primary storage at the moment, call do_swap_page () to complete the page box allocation.

In the preceding three functions, the page missing exception handling function uses alloc_zeroed_user_highpage_movable () to allocate physical pages. Alloc_zeroed_user_highpage_movable () function finally calls alloc_pages (). After such a complex process, the linear address accessed by the user process finally corresponds to a physical memory.

Refer:

1. Download the Linux kernel in PDF

2. For more information about the Linux kernel architecture, see PDF.

This article permanently updates the link address:

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.