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

Early in the calculation, the register is only a bit wide , in order to access the 1M bit of memory space, theCPU uses a segmented way to manage memory, the 1M  of memory into a number of logical segments, each logical segment must start with an integer multiple, and the maximum access space for each logical segment is 64K.

1) Subgrade Address

The physical address is divided into a number of segments in 64K bit, since the last 4 bits are always 0, so the start address of the segment is saved after the 4-bit shift right, and the actual physical address needs to be calculated and then 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 Management (CPU- level )

x86 's model has "real mode" and "protection mode" two, in the "real mode" in the next paragraph is used in accordance with the same time, but in "protected mode", the segment register is called the segment selector (segment selector ), it stores the segment Descriptor (segment descriptor), thesegment descriptor records the base address of the segment, permissions, and so on, subgrade address + logical address can be converted to a linear address.

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 the linear address into a fixed-length management unit , usually 4K size, for the four -bit computer is divided into 2^20 , with a two-level page-based 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 the page directory location of each process, the highest number of linear address, and then find the starting address of the page through the median, and finally find the offset within the page by a low bit, and finally calculate the physical address.

1.5 Linux Memory Management mode

Linux  is a cross-platform operating system, in order to support +  linux  so   logical address =  linear address, which corresponds when the logical address is translated into a linear address. 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 be compatible with different page series CPUs. 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

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.