This article was reproduced from: http://blog.csdn.net/yusiguyuan/article/details/12045255
There are three points to note about virtual memory:
- The 4G process address space is artificially divided into two parts-user space and kernel space. The user space is from 0 to 3G (0xc0000000) and the kernel space occupies 3G to 4G. Typically, a user process can only access the virtual address of a user space and cannot access the virtual address of the kernel space. The exception is when the user process makes a system call (on behalf of the user process in the kernel state execution), and so on, can access the kernel space.
- The user space corresponds to the process, so whenever the process switches, the user space changes, and the kernel space is mapped by the kernel, it does not follow the process changes, is fixed. The kernel space address has its own page table, and the user process has a different page table.
- The user space for each process is completely independent and irrelevant.
One, 4G address space resolution diagram
shows the distribution of the entire process address space, where the address space of 4G is divided into two parts, in user space, corresponding to the memory distribution of five segments: Data segment, code segment, BSS segment, heap, stack. Detailed introduction in the previous article.
two, virtual address space allocation and physical memory corresponding diagram
This diagram shows the partitioning of the kernel user space, the most important of which is the mapping of high-end memory
The space where the Kmalloc and VMALLOC functions are applied corresponds to different regions, but also to different meanings.
three, physical memory allocation diagram
The page in this picture explains the different relationships between the three, and is similar to what was in the previous article.
Partner algorithm:
A method of physical memory allocation and reclamation in which all free pages of physical memory are recorded in the buddy linked list. Preferred, the system establishes a linked list, each element of the list represents a class size of physical memory, respectively, 2 of 0, 1, 2, page size, corresponding to 4K, 8K, 16K of memory, no one size of memory and a linked list, indicating the current can allocate physical memory. For example, now only the need to allocate 8K of physical memory, the system first from the 8K list of the query has no assignable memory, if there is direct allocation; otherwise find 16K size of the linked list, if any, first will 16K in two, one assigned to the process, the other inserted in the list of 8K, if none, continue to find 32K, If so, first divide the 32K into two, one 16K of the size of the memory into the 16K linked list, and then another 16K to continue in two, one inserted into the list of 8K, the other is assigned to the process .... And so on When the memory is released, look at the adjacent memory is not idle, if there are two contact 8K of free memory, directly merged into a 16K of memory, inserted into the 16K linked list. (Partner algorithm for physical memory allocation scheme)
Slab algorithm:
is a partner calculation of the memory allocation of the user process, the partner algorithm is good enough, but for the kernel process, there is also a very small type of data (byte size, such as process descriptor, virtual memory descriptor, etc.), if each time a few bytes of data allocated a 4KB page, is too wasteful, So there is the SLBA algorithm, the slab algorithm is actually a page to split the force into a small piece of a small piece, and then allocated.
Linux memory Management--user space and kernel space "go"