Linux Memory Management

Source: Internet
Author: User

Basic Conceptual relationships

In the computer architecture, the main body of the hardware board is divided into North and South bridges, the bridge is mainly CPU memory graphics and other data transmission, and the bridge is mainly responsible for IO-related, external storage devices, BIOS-related data.

And we know that the memory management, is actually the program's logical address, through the segmentation mechanism into a linear address, through the paging mechanism to the physical address (this is supported by the CPU's MMU module), the physical address again through the North Bridge access to the specific RAM device, or ISA device, or PCI and other IO-related (again through the South Bridge).

Memory addressing is done by the Linux kernel and the MMU, where the Linux kernel is responsible for setting up registers such as CR3,GDTR, maintenance of page tables, page management, and MMU for specific mapping work.

In addition, we know that the most primitive access physical address is accessed through the CS:IP segmentation mechanism, so the x86 architecture is a fragmentation mechanism due to historical reasons, but Linux memory management is a paging mechanism. In order to be forward compatible we widened the entire memory paragraph to only one section, the segment base is 0, the segment is limited to 4G, only the segment type and segment access rights are differentiated, and the Linux kernel and all processes share 1 GDT, do not use the LDT (that is, all the segment descriptors in the system are stored in the same GDT), This is to cope with the minimum amount of work that the CPU's staging mechanism can do.

Specific linear address and physical address translation can be referenced

Physical Address space

0-16m ZONE_DMA, the physical pages for this area are dedicated to the DMA use of I/O devices. The physical pages of DMA are required to be managed separately because DMA uses physical addresses to access memory, does not go through the MMU, and requires a contiguous buffer, so in order to provide a physically contiguous buffer, a region must be specifically partitioned from the physical address space for DMA.
16m-896m

Zone_normal, the physical page of this area is the kernel direct mapping, that is, kernel space commonly used data such as kernel code, GDT, IDT, PGD, Mem_map array and so on zone_normal, in order to kernel the virtual address and physical address is directly mapped, Does not pass the page mechanism.

896m-4g Zone_height, the region is a physical high-end address that maps to user space and kernel part space.
640k-1m This address space is occupied by the BIOS and VGA adapters. Ram address hole.
MMIO

In Mmio, IO devices and memory share the same address bus, their address space is the same; In Pmio, the address space of the IO device and memory is isolated. The simple point is that mmio the IO address into the memory address, call the corresponding memory address is called to the corresponding IO device, and the downward is like the Inter int/out instruction port independent address or ARM's unified address regardless.

Virtual address space

Virtual address space Practical significance
0-3g User space
3g-4g Kernel space
3g-3g+16m ZONE_DMA in the corresponding physical address
3g+16m-3g+896m Zone_normal in the corresponding physical address
Vmalloc_start-vmallocend Vmalloc Area
Pkmap_base Persistent kernel mapping area
Fixaddr_base Temporary kernel mapping Area

Kernel space

For the virtual address space, we know that 0-3g is the user space, and 3g-4g is the kernel space, the first 896M has been used for direct mapping, then the remaining 128M space needs to map other different locations of physical space, that is, high-end physical space.

Kernel provides three mechanisms, namely Vmalloc area, persistent kernel mapping area, and temporary kernel mapping zone.

    • Vmallo area, which provides a contiguous virtual address, but the physical address pointed to is not necessarily contiguous
    • Persistent kernel mapping area, convenient to find the corresponding virtual address through the physical address, for fixed linear address constants, such as 0xffffc000, and the constant can be determined during the compilation phase. The function Kmap () that creates a persistent kernel map may block the current process and therefore cannot be used in the interrupt context.
    • The Temporary kernel mapping area, which is faster than a persistent kernel mapping, and does not block the current process, so it can be used in the interrupt context. However, it also has a weakness, that is, the code that uses it cannot sleep. Because each CPU has 13 temporary mapped addresses on its own, if the switchover process may cause the address to be changed.

User space

The code area of the user process typically starts with the 0x08048000 of the virtual address space, which is to facilitate checking for null pointers. Above the code area is the data area, uninitialized data area, heap area, stack area, and parameters, Global environment variables.

Reference:

Linux memory addressing and memory management//processes

Memory Management//process

Linux Memory Management

Memory management diagram of the Linux kernel//process

Kernel that stuff. Memory management (one)---kernel mappings

Talking about the difference between memory-mapped I/O (MMIO) and port-mapped I/O (Pmio)

Linux Memory Management

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.