Linux high-end memory mapping

Source: Internet
Author: User

Overview

On a 32-bit system, the kernel occupies a linear address space from 3gb~ 4GB, a total of 1GB size, and the kernel directly maps the 0~896MB of the former 896MB to the physical memory, i.e. the linear mapping, which takes the remaining 128M linear address space as a window to access the memory above 896M.

The main reason for the introduction of high-end memory mapping is that when we install more than 1G of memory, the 1G linear address space of the kernel cannot establish a full direct mapping to reach the entire physical memory space, while for 80x86, the maximum allowable physical memory can reach 64G. So the kernel frees up its last 128M of linear address space to complete a temporary mapping of high-end memory.

There is no such problem on a 64-bit system because the available linear address space is much larger than the installable memory. Describes how the kernel 1GB linear address space is divided.

One of the areas which can be used to accomplish the above mapping purposes is the Vmalloc area,persistent kernel mappings region and the Fix_kmap area in the fixed map linear address space, which correspond to the mapping mechanism of the three regions, respectively, the non-contiguous memory allocation , Permanent kernel mappings , and temporary kernel mappings .

Permanent Kernel mappings

When the kernel initializes the page table management mechanism, it specifically uses the pkmap_page_table variable to save the address of the Pkmap_base corresponding page table entry, and the pkmap_page_table to maintain the mapping of the page table entries for the permanent kernel map, the total number of page table entries is Last_ A pkmap.

The permanence here is not that the mapping relationship established by calling Kmap () will persist, but that this mapping will persist between calling Kunmap () de-mapping, as opposed to the temporary kernel mapping mechanism.

It is important to note that when there are no idle page table entries available for mapping in the permanent kernel mapping area, the process that requests the mappings is blocked, so the persistent kernel mapping request cannot occur in interrupts and deferred functions.

Temporary kernel mappings

The most important feature of a temporary kernel mapping versus a permanent kernel mapping is that it does not block the process of requesting a mapped page box, so the temporary kernel mapping request can occur in interrupts and deferred functions. Each CPU in the system has its own temporary kernel mapping window, which, depending on the requirements, chooses different windows to create the mappings.

The implementation of a temporary kernel mapping is also simpler than a permanent kernel mapping, when a process requests a window to create a map, even if the window has already been mapped before, the new map will be built and overwrite the previous mappings, so the mapping mechanism is temporary and does not block the current process.

Non-contiguous memory allocation

Discontinuous memory allocation refers to the mapping of a page box with a discontinuous physical address to a linear address continuous linear address space, which is primarily used for large-capacity memory allocations. The main advantage of allocating memory in this way is to avoid external fragmentation, and the disadvantage is that the kernel page table must be scrambled and the access speed is slower than the contiguous allocation of physical page frames.

The linear address space for non-contiguous memory allocations is from Vmalloc_start to Vmalloc_end, a total of 128M, whenever the kernel wants to use VMALLOC class functions for non-contiguous memory allocation, it will request a VM_STRUCT structure to describe the corresponding Vmalloc area, The interval between two vmalloc zones is at least the size of one page box, or page_size. Non-contiguous memory allocation area

Summarize

At this point, the mapping of all areas of high-end memory has been introduced. In my opinion, the linear address space of the kernel can be regarded as a resource because the page table must be accessed through a linear address, and the corresponding physical memory is further accessed through the page table.

Due to the limited linear address space of the kernel, there are three ways to map high-end memory using the above mentioned methods. It is important to be clear that the mapping between the linear address and the page table is fixed, and that the mapping between the page table and the physical page box can be changed, and that the kernel is using the variability of the mapping between the page table and the physical page frame to create a "temporary" mapping for high-end memory, which is essentially a return to this.

Permanent kernel mappings and temporary kernel mappings, both of which are specified by the kernel to be mapped, that specifies the page descriptor (the relationship between the page descriptor and the physical page box is fixed and immutable), in the permanent kernel mapping, the kernel only needs to find the idle in the permanent kernel mapping area. That is, the page table entry corresponding to the linear address that is not mapped, then assigns it to the page, if not found will block the request to establish the mapping process, and the temporary kernel mapping more direct, even the linear address of the mapping window is fixed, if it has been assigned to a page box, then directly grab to use, As a result, the previous mappings were overwritten, reflecting a temporary nature.

Non-contiguous memory allocation, the kernel does not specify a specific page, just specify the size of the memory to be requested, the kernel will find a corresponding size virtual address space in the non-contiguous memory allocation area, and then the partner system to allocate the page box, but also through the slab allocator for some data structures to allocate memory, and finally in the same way ( Set the PTE table entry) to establish the mapping, which involves both the partner system and the parts of the slab assignment are not specifically analyzed, and in the later articles, focus on these parts.

Problems
    • Does the user space (process) have a high-end memory concept?

User processes do not have high-end memory concepts. Only high-end memory exists in kernel space. A user process can access up to 3G of physical memory, and the kernel process can access all physical memory.

    • How much physical memory can a user process access? How much physical memory can the kernel code access?

The 32-bit system user process can access up to 3GB, and the kernel code can access all physical memory.
The 64-bit system user process can access more than 512GB, and the kernel code can access all physical memory.

PS
This article is the book of this series of articles:

    • Linux high-end memory mapping (top) (http://blog.csdn.net/vanbreaker/article/details/7579941)
    • Linux high-end memory Mapping (medium) (http://blog.csdn.net/vanbreaker/article/details/7580771)
    • Linux high-end memory mapping (bottom) (http://blog.csdn.net/vanbreaker/article/details/7591844)

Linux high-end memory mapping

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.