Hugetlb mips Analysis

Source: Internet
Author: User

Before reading this article, you can read the articles on the use, advantages, and principles of x86 huge pages in the ibm Library: the principles of huge pages, when the kernel page size is fixed, multiple consecutive page boxes with physical addresses are allocated to simulate a large page for user-Mode Program access, thus reducing the number of page defects of user programs, improve performance. In order for the kernel to regard multiple consecutive page boxes as a whole, each CPU architecture has been done separately. First, hugetlbfs does not support read/write. In fact, the use of huge pages is through the user State mmap A hugetlbfs file, and then the first access to the page is missing to complete. For example, for x86, there is a base address register of the table on the base of the page. When a common page is missing (in fact, it should be called tlb miss), the CPU will find the base address of the page table of the process based on the content of the, and then traverse the page table in sequence, finally, the specific page table item (I .e., pte entry) is located ). If the page is missing from the virtual space where hugetlb is located, do_page_fault will add a flag to the last level-2 pmd entry, which is equivalent to telling the CPU that the pmd entry is the last level-1 page table. When page fault is returned and the CPU accesses the missing page address again, the CPU traverses the page table and does not unaddress the page when the page entry is found, for mips, since page table traversal and TLB refilling are completed by software (x86 is completed by hardware), the page table traversal and TLB refilling process need to be modified here. Therefore, the mmap driver of hugetlbfs and the page fault of hugetlbfs are investigated. Mmap: hugetlbfs_file_mmaphugetlbfs_file_mmap is mainly used to set VM_HUGETLB and VM_RESERVED attributes for the mapped vma range. The former is used to identify missing pages caused by huge page intervals in the pagefault process, the latter is used to prevent the pages contained in the vma range of huge pages from being swapped out. Page fault: the function of hugetlb_faulthugetlb_fault is mainly used to allocate consecutive physical page boxes and write the page box address to the page table in a certain way. In this way, when tlb is refilled, you can write it to tlb Based on the ing in the page table. But what is the difference between hugetlb's missing pages and general missing pages? According to the above description, we raised two questions: 1) how the page box address is written to the page table? 2) when the tlb is refilled, we continue to return to the hugetlb_fault process based on the content of the page table. [Cpp] int hugetlb_fault (struct mm_struct * mm, struct vm_area_struct * vma, unsigned long address, unsigned int flags) {pte_t * ptep; ptep = convert (mm, address, huge_page_size (h); entry = huge_ptep_get (ptep); if (huge_pte_none (entry) {ret = hugetlb_no_page (mm, vma, address, ptep, flags ); goto out_mutex ;}} we know that for common page missing, you need to generate a ing tree from pgd to pte, that is, to search the process page table in sequence by using the virtual address where the page is missing as the key, if no corresponding pte table exists, a new pte table is allocated Enter the table address in the top-level pmd entry, and finally return the pte table. The addr's pte entry address (see the pte_alloc_map function). However, for huge pages, assume that a huge page consists of n consecutive page boxes, you need to allocate the possible page table paths of the n page boxes first (pgd-> pud-> pmd-> pte ), that is, if a page is missing, you need to "Confirm" (n-1) the page table path "unblocked ". Therefore, you need to call the huge_pte_alloc function to allocate the pgd to the pte path to the virtual space of addr --> (addr + n * PAGE_SIZE) according to the PGAE_SIZE step, the specific page for allocation is not executed yet. [Cpp] pte_t * huge_pte_alloc (struct mm_struct * mm, unsigned long addr, unsigned long sz) {pte_t * pte = NULL; unsigned long I = 0; unsigned long htlb_entries = 1 <HUGETLB_PAGE_ORDER; addr & = HPAGE_MASK; for (I = 0; I

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.