Linux memory Management-high-end memory

Source: Internet
Author: User
Tags blank page

High-end memory refers to memory with a physical address greater than 896M. For such memory, it is not possible to map in "Kernel Direct mapping Space".


Why?

Because "kernel direct mapping Space" can only be from 3G to 4G, only directly mapped 1G physical memory, for more than 1G of physical memory, powerless .

In fact, "kernel direct mapping Space" also does not reach 1G, but also to leave a bit of linear space to "kernel dynamic mapping space" it.

Therefore, Linux specifies that "kernel direct mapping Space" maps up to 896M of physical memory .

For high-end memory, the corresponding page can be obtained through alloc_page () or other functions, but to access the actual physical memory, the page must be converted to a linear address (why?). Consider how the MMU accesses physical memory, which means that we need to find a linear space for the page that corresponds to the high-end memory, a process called high-end memory mapping.


There are three ways of high-end memory mapping:
1. map to "kernel dynamic mapping Space"

This is simple, because with Vmalloc (), when the "kernel Dynamic mapping Space" is requested for memory, it is possible to obtain a page from high-end memory (see VMALLOC implementation), so that high-end memory may be mapped to "kernel dynamic mapping Space" .


2. Permanent Kernel mapping

How do I find a linear space for a page with a high-end memory corresponding to the Alloc_page ()?

  The kernel specifically leaves a linear space for this, from Pkmap_base to Fixaddr_start, to map high-end memory . On the 2.4 kernel, this address range is 4g-8m to 4g-4m. This space is called "Kernel permanent Mapping Space" or "permanent kernel mapping Space"

This space and other space use the same page catalog table, for the kernel, is swapper_pg_dir, for ordinary processes, through the CR3 register point.

Typically, this space is 4M in size, so just a page table is needed, and the kernel looks for the page table by pkmap_page_table.

With Kmap (), you can map a page to this space to

Since this space is 4M in size, you can map up to 1024 page at a time. Therefore, for unused page, should be released in time from this space (also in addition to mapping off is the solution system), through the Kunmap (), can be a page corresponding to the linear address from this space release.


3. Temporary mapping

The kernel retains some linear space between Fixaddr_start and fixaddr_top for special needs. This space is called " Fixed mapping Space ".

In this space, there is a subset of temporary mappings for high-end memory.

This space has the following characteristics:

1, each CPU occupies a piece of space

2, in the space occupied by each CPU, divided into several small spaces, each small space size is 1 page, each small space for a purpose, these purposes are defined in the kmap_types.h in the Km_type.

When you want to do a temporary mapping, you need to specify the purpose of the mapping, according to the mapping purposes, you can find the corresponding small space, and then the address of the space as a map address. This means that a temporary mapping will cause the previous mappings to be overwritten.

Temporary mappings can be implemented by Kmap_atomic ().

Simple and simple representation of how to map high-end memory

The linear address space size of Linux memory is 4GB and is divided into 2 parts: The User space section (usually 3G) and the kernel space section (usually 1G). Here we focus primarily on the kernel address space section.

The kernel manages all of the physical memory through the Kernel page Global directory , and since the 3G space for the linear address is used by the user, the first 768 items (just 3G) of the kernel page global catalog are 0, except for 0, 12 items, and the last 256 items (1G) are used to manage all physical memory. The kernel-page global catalog is statically defined at compile time as an swapper_pg_dir array, which is stored at the physical memory address 0x101000 .

Visible from the diagram, the kernel linear address space part fromPage_offset(usually defined as 3G), in order to load the kernel into memory,starting from Page_offset the 8M linear address is used to map the physical memory address where the kernel resides (or the virtual address where the kernel is located, starting with Page_offset)Next is the Mem_map array, where the starting linear address of the MEM_MAP is related to the architecture, such as for the UMA structure, since the 16M Physical address space corresponding to the 16M linear address space from Page_offset is the DMA zone, the MEM_MAP array usually starts at Page_ Linear address space for offset+16m, from Page_offset to Vmalloc_start–vmalloc_offset, directly mapped to physical memory space (one by one corresponds to innuendo, physical address <==> linear address-page_ OFFSET), the size of this area is related to the physical memory size that the machine actually has, hereVmalloc_offsetOn the X86 for 8M,primarily used to prevent cross-border errorsOn a system with small memory, the remaining linear address space (also minus the white space, or vmalloc_offset) is used by the Vmalloc () function to map the discontinuous physical address space to a continuous linear address space on a system with large memory, Vmalloc () Use a linear address space from Vmalloc_start to Vmalloc_end (that is, pkmap_base minus 2 pages of blank page size page_size (interpreted vmalloc_end)). At this point the remaining linear address space (also minus 2 pages of white space that is vmalloc_offset) can be divided into 2 parts: the first part from Pkmap_base to Fixaddr_start is used by the Kmap () function to establishpermanently map high-end memoryThe second part, from Fixaddr_start to Fixaddr_top, is a fixed-sizetemporarily map linear address space, (citation: Fixed virtual addresses is needed for subsystems, need to know the virtual address at compile time such as the A PIC), in the X86 architecture, Fixaddr_top is statically defined as 0xffffe000, at which point the fixed size space ends at the end of the entire linear address space before the last 4K, the fixed size space size is computed at compile time and stored in the __fixaddr_size variable.

It is precisely because of the presence of vmalloc () usage zones, Kmap () and fixed large cells (kmap_atomic () zones) that the Zone_normal area is limited in size, because the kernel needs these functions at runtime, so at least vmalloc_ in the linear address space Reserve size of space. The size of the Vmalloc_reserve is architecture-related, and on X86, Vmalloc_reserve is defined as 128M, which is why the zone_normal size is usually 16M to 896M.

On the 32-bit processor platform that supports MMU, theaddress ranges for physical storage and virtual storage space in Linux systems are from 0x00000000 to 0xFFFFFFFF, respectively, to 4GB, But the physical storage space is completely different from the virtual storage space layout. Linux runs in virtual storage space and is responsible for mapping physical memory that is actually present in the system to as much as 4GB to the entire 4GB based on different requirements Virtual storage space .

Physical storage space Layout

Linux the physical storage space layout is processor -specific, and details can be found in the relevant sections of the Storage space distribution table (memory map) of the processor user manual,where we only list the general layout of the physical memory space of the embedded processor platform Linux.

Description

1) The maximum node number n cannot be greater than max_numnodes-1.

2)max_numnodes indicates the maximum number of node supported by the system . In arm systems, the sharpchip supports up to 16 nodes, and the other chips support up to 4 nodes.

3)NumNodes is the actual number of memory node in the current system .

4) in a system that does not support the CONFIG_DISCONTIGMEM option, there is only one memory node.

5) The maximum bank number m cannot be greater than nr_banks-1.

6)Nr_banks represents the maximum number of memory banks supported in the system , typically equal to the number of RAM slices selected by the processor. In arm systems, the sharpchip supports up to 16 banks, and the other chips support up to 8 banks.

7) TheMem_init () function frees all nodes of the page Frame code table to occupy space, Hole page descriptor space, and free memory pages.

I don't seem to understand.

Virtual Storage space Layout

In the system that supports MMU, when the system completes the hardware initialization, it can be the MMU function, so that the whole system runs in virtual storage space, the virtual storage space to the physical storage space mapping function is the processor MMU, and the virtual storage space and The mapping of the 5-way storage space is managed by the Linux kernel. 32-bit system of physical storage space accounted for 4GB space, virtual storage space also accounted for 4GB space,Linux The physical space in the actual existence of much less than 4GB of memory space mapped to the entire 4GB virtual storage space in addition to mapping All the space outside the I/O space, so the virtual memory space is much larger than the physical memory space, which means that the same piece of physical memory may be mapped to multiple virtual memory address spaces, which is where the Linux memory management responsibilities lie. Figure 18-5 lists the general layout of the virtual memory space in the Linux kernel ( in fact I/O space is in it, usually occupying high-end memory space, not shown here).  

Description

1) Linear address space: Refers to the Linux system from 0x00000000 to 0xFFFFFFFF of the entire 4GB virtual storage space.

2) kernel space: Kernel space represents code or data running at the highest processor level in Super User mode (supervisor mode), which occupies 1GB linear address space from 0xc0000000 to 0xFFFFFFFF. The kernel linear address space is shared by all processes, but only those processes running in the kernel state can access it, and the user process may switch to kernel-state access through the system call, and the address generated by the process running in the kernel state is in kernel space.

3) User space: User space takes up from 0x00000000 to 0xBFFFFFFF a total of 3GB of linear address space, each process has a separate 3GB User space, so the user space is unique to each process, but the kernel thread does not have user space because it does not produce a user-space address . In addition, the child process share (inherit) the user space of the parent process is simply a mapping with the same user-linear address to the physical memory address as the parent process, rather than the shared parent process user space. User space can be accessed by processes running in both the user state and the kernel state.

4) kernel logical address space: refers to page_offset (3G) to high_ The linear address space between memory (the size of physical memory, maximum 896), is the system physical, mapped area, which maps all or part (if the system contains high-end memory) physical memory. Kernel logical address space and figure 18-4 in the system ram memory Physical address space is one by one corresponding (including memory hole is also one by one corresponding), the address in the kernel logical address space and ram the corresponding address in the physical address space of the memory is only a fixed offset (3g), if ram The physical address space of the memory from 0x00000000 address addressing, then this offset is page_offset.

5) low-end memory: The kernel logical address space mapped physical memory is low-end memory (the actual physical memory size, But less than 896), the low-end presence linux linear address space always has a permanent one by one corresponding to the kernel logical address, The low-end memory is permanently mapped to the kernel logical address space in the system initialization process, and the Virtual Mapping page table is established for low-end memory. Conversion between physical and linear addresses of physical memory in low-end memory can be done through __pa (x) and __va (x) two macros, # Define __PA (x) ((unsigned long) (x)-page_offset) __PA (x) Converts the address of the kernel logical address space x to the corresponding physical address, equivalent to __virt_to_phys ((unsigned long) (x)), __va (x) Instead, translates the address of the low-end physical memory space into the corresponding kernel logical address, Equivalent to

6) High-end memory: physical memory above the low-side memory address is high-end memory (above physical memory 896), there is no fixed one by one corresponding kernel logical address in the Linux linear address space in high-end , the Mapping page table for these memory is not mapped to the Linux linear address space during system initialization, but instead the mapping page table for allocated high-end physical memory needs to be used when high-end memory is needed, so that it can be used by the kernel, otherwise it cannot be used. The conversion between the physical address of high-end memory and the linear address cannot use the above __PA (x) and __va (x) macros.

7) The origin of the high-end memory concept: as described above,Linux willThe linear address space of the 4GB is divided into two parts,from0x00000000 to 0xBFFFFFFF total 3GB the space as user space is exclusive by the user process, and this part of the linear address space does not have a fixed mapping to the physical memory space; from0xc0000000 to0xFFFFFFFF the first4GB linear address space as the kernel space, in the embedded system, this part of the linear address space in addition to mapping the physical memory space to map the processor internal peripheral register space, etc.I/O space.0xc0000000~high_memorythe kernel logical address space between the systems is dedicated to fixing the physical memory in the mapping system,Other wordsThe amount of space between 0xc0000000~high_memory is the same as the amount of physical memory space in the system (of course, CONFIGUREDCONFIG_DISCONTIGMEMD option in a non-contiguous memory system, the kernel logical address space and physical memory space may have a memory hole, if the physical memory capacity in the system is much smaller than1GB, the kernel logical address space in the kernel-line address spaceThere is still enough space between the HIGH_MEMORY~0XFFFFFFFF to fix the mappings.I/O space. Butif the physical memory capacity (including memory holes) in the system is greater than 1gb, then there is not enough kernel linear address space to fix all the physical memory of the mapping system and some i/o space, in order to solve this problem, x86 processor platform set an experience value: 896mb, that is, if the system of physical memory (including memory holes) is greater than 896mb, Then the former 896mb physical memory fixed mapped to the kernel logical address space 0xc0000000~0xc0000000+896mb ( =high_memory), and the physical memory after 896MB does not establish a fixed mapping to the kernel linear address space, this part of memory is called high-end physical memory. At this point the kernel linear address space high_memory~0xffffffff between the 128mb space is called high-end memory linear address space, used to map high-end physical memory and i/o space. 896MB is x86 processor platform experience value, left 128mb linear address space to map high-end memory and i/o address space, in the embedded system can be modified according to the specific circumstances of this threshold, for example, mips set this value to 0x20000000b (512mb), the kernel needs to be configured only if the physical memory space in the system is greater than 0x20000000b The config_highmem option enables kernel-to-high memory allocation and mapping. The setting principle of what needs to be divided into high-end physical memory and high-end physical memory thresholds is shown in the memory page area above (zone) concept description.

8) high-end linear address space: The linear address space from High_memory to 0xFFFFFFFF belongs to the high-end linear address space, where vmalloc_start~vmalloc_end between the linear address: (1) is The Vmalloc () function allocates high-end physical memory that is physically discontinuous but linear address space contiguous, or (2) is used by the Vmap () function to map high-end or low-end physical memory, or (3) to remap by the Ioremap () function I/O physical space. Where Pkmap_base begins the last_pkmap (typically equal to 1024) page linear address space: the Kmap () function is used to permanently map high-end physical memory. fixaddr_start start km_type_nr*nr_cpus page linear address space: used by the kmap_atomic () function to temporarily map high-end physical memory, Other unused high-end linear address spaces can be used to permanently map I/O address space during system initialization.

Linux memory Management-high-end memory

Related Article

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.