Linux processes and memory management have been learning linux for so long, and I feel that I have not gone deep into it. Today I have re-read the linux memory management mechanism and written down these fragmented notes, it will be easy to remember in the future. I feel like I really like linux now ~ Www.2cto.com basic knowledge of Linux memory management the memory management program provides the following functions: 1. Large address space. The amount of memory used by your program can exceed the actual amount of physical memory. 2. Memory protection, the memory of a process is private and cannot be read or modified by other processes. In addition, the memory management program can prevent the process from overwriting code and read-only data. 3: Memory ing, you can map a file to the virtual memory area and use the file as the memory to access 4; fair access to the physical memory, the memory management program ensures that all processes can access the computer's memory resources fairly, so as to ensure the ideal system performance 5: Sharing virtual memory, memory Management programs allow sharing part of their www.2cto.com storage space: In 32 for the storage system, the address range of the storage space is from 0*00000000 to 0 * xFFFFFFFF. A total of 4G storage range 2: memory space: system memory space refers to the above RAM memory space 3: Memory Page: Linux manages physical memory in units of pages, the size of a page is generally equal to 4096B. The larger the page capacity, the more memory fragments may exist in the system. The process memory management may involve five different data segments for any common file: code segment, data segment, and BBS segment, heap and stack 1: code segment, which is used to store the operation instructions of executable files. That is to say, it is an image of the executable program in the memory. The code segment must be prevented from being modified illegally at runtime. Therefore, only read operations can be run, and write operations are not allowed. 2. data segments are used to store initialized global variables in executable files, in other words, it is to store the static allocation variables and global variables of the program. 3: BBS segment. BBS segment contains uninitialized global variables in the program. In the memory, BBS all sets 0 to 4: heap is used to store dynamically allocated memory segments in the running process. The heap size is not fixed and can be expanded or reduced. When a process calls a function such as malloc to allocate memory, the newly allocated memory is dynamically added to the stack. When the free function is used to release the memory, the released memory is deleted from the stack. 5: STACK: A stack is a local variable temporarily created by the user to store the program. Because the stack has the features of first-in-first-out, it is particularly convenient to save/restore the call site ~ Process Memory Allocation and release create process fork (), Program Load execve (), map file mmap (), dynamic memory allocation malloc () and other process-related operations need to allocate memory to the process. However, what the process requests and obtains is not the actual memory, but the virtual memory. The address that a process can directly operate on is read as a virtual address. When the process does not obtain the physical memory, only the virtual memory area is obtained from the kernel, instead of the actual physical address. The process does not obtain the physical memory, obtain the right to use a new linear address. The actual physical memory will be interrupted by the "request page mechanism" only when the process actually accesses the new virtual address, so as to enter the routine for allocating the actual page. The management kernel space and user space of a virtual space are in the linux system. The kernel is executed at the highest level, also known as "system state". At this level, any operation can be performed. The application is executed at the lowest level, that is, the so-called "User State ". At this level, the processor prohibits direct access to hardware and unauthorized access to memory. Modules run in the so-called "kernel space", while applications run in the "user space ". They apply different memory ing, that is, the program code uses different "address spaces ". The function of the module is to expand the functions of the kernel, and is the modular code that runs in the kernel space. Some functions of the module are called and executed by the system, while some functions are responsible for handling interruptions. Each module is compiled and connected to a set of target files, which can be loaded into the running kernel or detached from the running kernel. The module uses another method. The Kernel provides a socket, which is like a plug-in. It is used in inserting the kernel as needed and does not need to be pulled out from the kernel. There is a difference between the kernel module and the application. The application completes a task from start to end, and the module registers itself for processing certain requests in the future. After the task is completed, its main function is immediately aborted.