Linux Kernel Development-memory management

Source: Internet
Author: User

1.1What is memory management

Memory management is the technique of allocating and using computer memory. Memory management is mainly in the multitasking operating system, due to the extremely limited memory resources, the need to share memory between different tasks, memory management is to be efficient, fast non-matching memory, and when appropriate to recover and release memory, in order to guarantee the normal execution of each task. The most common memory management mechanisms are: segment Memory management and page-type memory management.

1.2in-memory addresses

In early computing, the register has a bit width of only three bits , in order to access the memory space ofthe 1M bit , theCPU A segmented way to manage memory, the 1M of memory into a number of logical segments, the starting address of each logical segment must be an integer multiple, the maximum access space for each logical segment is 64K .

1) Subgrade Address

The physical address is divided into segments of 64K bits , since the last 4 bits are always 0, so the start address of the segment is shifted right by 4 After the bit is saved, you need to calculate the actual physical address and then move the left four bits.

2) Logical address (offset address within paragraph)

The offset within the segment after the logical address is segmented.

3) Linear Address

The linear address represents the address access capability of the computer and represents a non-physical entity address. Is the middle tier between the logical address and the physical address transformation.

In segment management, the linear address = the base address in the segment + the logical address.

4) Virtual Address

The concept of virtual address is mainly in the virtual memory technology, which makes the application think that it has contiguous memory available (a contiguous complete address space), so it is called a linear address in some cases.

5) Physical Address

The address of the actual physical memory is the final result of the address translation.

PS: for the three-bit machine, his actual physical address is a bit, the linear address and physical address is the same, so the linear address to the physical address is one by one corresponding.

1.3Segment-Type management( +bitCPU)

x86 's model has "real mode" and "protection mode" two, in the "real mode" the use of the next segment is consistent with the time machine, but in "protected mode", the segment register is called the segment selector (segment selector), which stores the segment descriptor (segment descriptor), and the segment descriptor records the base address, permissions, and other information of the segment, Subgrade address + logical addresses can be converted to linear addresses.

The advantages of segment management: the ability to divide code into logical segments, such as data segments, code snippets, and stack segments, from the perspective of the User (programmer), based on the actual code. The segment size is variable, which helps to protect data and facilitate memory sharing.

1.4page-style management

Page management is to divide a linear address into a fixed- length snap-in , usually 4K in size, dividing the 2^20 into a four-bit computer. Also, with a two-level page memory management mechanism, the linear address is divided into three parts

L-Page Directory address:22~31 ( total )

L-Page Table address:12~21 ( total )

L in-page offset:0~11(total )

The system will find the starting address of the page table for each process's page directory location, the highest ten digits of the linear address, and the beginning address of the page through the median, and finally pass the lower 12 The bit finds the offset in the page and finally calculates the physical address.

1.5 Linux Memory Management mode

Linux  is a cross-platform operating system, in order to support +  page management mechanism, but LINUX  LINUX  The base address of each segment in the system is 0 so   logical address =  linear address, the logical address is translated into a linear address when the corresponding. LINUX 

More strictly,Linux uses a page-based management model, but because of the inconsistent page progression of different platforms,Linux 2.6.29 uses a four-level page management structure to accommodate different page series CPU. These four levels are:

Page Global Directory ( page globally directory) :PGD

Page Parent Directory (page Upper directory):pud

Page Intermediate Directory (page middle directory):PMD

Page Tables (page table Entry):Pte


Linux Kernel Development-memory management

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.