The memory management mechanism of Linux

Source: Internet
Author: User

Some basic concepts of memory management:

Address


1) Logical address: Refers to the part of the offset address generated by the program related to the segment. In the C language pointer, read the pointer variable itself value (& operation), which is actually the logical address, which is relative to your current process data segment address.

2) Linear Address: The offset address (logical address) in the segment, plus the base address of the corresponding segment, generates a linear address.

3) Physical Address: The address placed on the addressing bus.

4) Virtual Address: The address of the offset in the next segment and paragraph in protected mode, and the logical address is the offset within the code segment, or the logical address of the process.



Memory management primarily addresses the following issues:


    1. Address space isolation of the process;

    2. Improve the efficiency of memory usage;

    3. Re-locating the problem when the program is running;


The current approach to memory management is to introduce the concept of virtual memory between program and physical memory. Virtual memory resides between the program and the physical memory, and the program sees only virtual memory and no longer has direct access to physical memory. Each process has its own process address space, which enables process isolation.


Since there is virtual memory, the solution from the virtual address mapping to the physical address, mainly using segmentation and paging two of the technology.


    1. Fragmentation (logical address translates to linear address): Maps the virtual space of the memory address space required by the program to the physical address space, and each byte in the virtual space corresponds to each byte in the actual space. This mapping process is the mechanism by which the software sets the mapping, and the actual conversion is done by the hardware. The segmentation mechanism solves the above problems of 1 and 3.

    2. Paging (Converting a linear address to a physical address): Paging is the memory address space is divided into a number of small fixed-size pages, each page size is determined by memory, the General page size is 4KB.


650) this.width=650; "class=" AlignCenter size-full wp-image-1238 "title=" linux-mm "src=" http://dongxicheng.org/ Wp-content/uploads/2011/09/linux-mm.jpg "width=" 411 "height=" "style=" border:0px;font-family: ' Lucida Grande ', ' Lucida Sans Unicode ', Verdana, sans-serif;font-size:12px;line-height:18px;text-indent:25.2000007629395px; white-space:normal;margin:0px auto;padding:0px; "/>


650) this.width=650; "src=" http://pic002.cnblogs.com/images/2012/394673/2012101215042913.jpg "style=" White-space: normal;border:0px;font-family: ' Microsoft Black ', ' Microsoft Yahei ', ' Helvetica Neue ', ' Hiragino Sans GB ', ' Arial ', SimSun, ' black body ', Arial, sans-serif;line-height:24px; "/>


Differences in segmentation and paging:


    1. Page is the physical unit of information, paging is to achieve discrete distribution, to reduce the amount of memory, improve memory utilization or can be said that paging is only a system management needs, rather than user management needs. A segment is a logical unit of information that contains a set of information that is relatively complete in its meaning. The purpose of segmentation is to better meet the needs of users;

    2. The size of the page is fixed and determined by the system, the logical address is divided into page number and in-page address two parts, implemented by hardware. The length of the segment is not fixed and is determined by the user to write the program, usually by the compilation system when the source program compiled according to the nature of the information to be divided.

    3. Page system address space is one-dimensional, that is, a single linear address space, the programmer only need to use an identifier, can represent an address. The job address space of the segment is two-dimensional, and when the programmer signs an address, it needs to give both the segment name and the address in the paragraph.


The following is an approximate process of calling memory for a process:


    1. First of all, APP1 through the Fork,execute,nmap function to create the process;

    2. Functions such as malloc or BRK dynamically allocate a space on virtual memory for APP1 use;

    3. After the virtual memory is divided, the actual physical memory is not allocated at this time. (deferred allocation)

    4. When the program really uses this memory, it will only produce page request that the paging mechanism occurs;

    5. The physical memory will establish the corresponding page table;

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/6F/78/wKiom1WdJN2zN-uQAAJuN8RA0u8371.jpg "title=" Linux memory calls. jpg "alt=" wkiom1wdjn2zn-uqaajun8ra0u8371.jpg "/>





Resources:

Basic concepts of Linux memory management:

http://dongxicheng.org/os/linux-memory-management-basic/

Linux Memory Management:

Http://www.cnblogs.com/autum/archive/2012/10/12/linuxmalloc.html

Memory Management in Linux:

Http://blog.chinaunix.net/uid-26611383-id-3761754.html

This article is from the "Mama Sister" blog, please make sure to keep this source http://smallc.blog.51cto.com/926344/1672180

The memory management mechanism of Linux

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.