LINUX memory management

Source: Internet
Author: User
An understanding of LINUX memory management-general Linux technology-Linux programming and kernel information. The following is a detailed description. Mode Conversion

Linux runs in real-time mode in the first half of the boot process. The program runs on a physical address, for example, 0X9000.
0X9000. The second half of the transfer to protection mode uses a virtual address. The switch of virtual address conversion is in the CR1 register. The foundation of virtual address conversion is that the Program establishes a page Directory and a page table mechanism. The virtual address is mapped to the corresponding physical address through the page Directory.

Virtual Address

The addressing space (virtual address) of 32-bit machines is 4 GB, with 0-3G as the user space and 3-4G as the system space. In the user's opinion, our program is like running on 4 GB memory. In addition, each process can use the same virtual address without interfering with each other. In fact, it is a trick that the operating system is playing. For example, program a uses 0x1000, and program B uses 0x1000, however, the operating system may point 0x1000 of a to 0X01000000 of the physical memory, and 0x1000 of B to 0X02000000 of the physical memory.

Conversion Principle

Linux uses a three-level ing mechanism: page Directory, intermediate page table, and page table. I386 supports two levels, so the intermediate page table does not work and is transparent. The virtual address is automatically converted to the actual physical address by the hardware MMU. The specific process is that the address of the page Directory is obtained by the register S3, the address of the page table is obtained based on the 22-31 bits of the virtual address (as the displacement), and the value of the page table is obtained based on the page table address plus 12-21 bits of the virtual address (as the displacement ), the physical address is obtained based on the physical page address plus the value of the virtual address 0-11 bits (as the displacement) to complete the conversion.

Virtual Address status

Each process has its own page table. The space described in the page table is 0-4 GB. The system space also has its own page table. The description space is 0-4G, but the initialization for 0-3G is 0. Only the ing is performed for 3g-4G, and the linear ing is used, for example, 0xC0009000 refers to the physical memory 0x00009000, and xC0029000 refers to the physical memory 0x00029000.

The process uses its own page table no matter whether it is running in the system space or in the user space, and the 3g-4g space of all processes is the same ing.

During the Process switchover, the page Directory address of the next process will be entered. Therefore, when the page table 3g-4g space of all processes is the same ing, the kernel can run normally regardless of the switching mode of S3.

Virtual Memory Management

To manage the virtual memory, each process has a mm_struct structure and some vm_area_struct. The former is a general description of the virtual memory of a process, the latter is the description of each memory area of the process.

LINUX uses the paging system, while the CPU-provided partition system can be understood as a direct system penetration.

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.