Kernel Address Space Distribution
Direct ing zone: The maximum m range starting from 3G in a linear space. It is a direct memory ing zone. The linear address and physical address in this region have a linear conversion relationship: linear address = 3G + physical address.
Dynamic Memory ing area: This area is allocated by the kernel function vmalloc. It features linear space continuity, but the corresponding physical space is not necessarily continuous. The physical page corresponding to the linear address allocated by vmalloc may be in low-end memory or high-end memory.
Permanent memory ing area: high-end memory is accessible in this area. You can use alloc_page (_ gfp_highmem) to allocate a high-end memory page or use the kmap function to map the allocated high-end memory to this area.
Fixed ing zone: this region and 4G have only 4 K isolation bands at the top, and each address item serves a specific purpose, such as acpi_base.
Process address space
Linux uses virtual memory management technology. Each process has a 3G independent process address space, which is the user space. The user space of each process is completely independent and complementary. The process accesses the kernel space by means of system calls and interruptions.
Process-related operations such as process creation must be allocated to the process. At this time, the process does not apply for and obtain physical addresses, but virtual addresses.
The actual physical memory is used only when the process actually accesses the newly obtained virtual address, the "Page request mechanism" will generate a "page missing" exception, so as to enter the program for allocating the actual leaf Box. This exception is the basic guarantee for the existence of the virtual memory mechanism-it will tell the kernel to allocate physical pages to the process and create a corresponding page table, after that, the virtual address is mapped to the physical address.
Differences between vmalloc and kmalloc
1. kmalloc corresponds to kfree, and the allocated memory is 3 GB ~ High_memory: The ing between the kernel space and physical memory is one-to-one, and continuous physical memory can be allocated;
Vmalloc corresponds to vfree, and the allocated vmalloc_start ~ Between 4 GB, allocate continuous virtual memory, but physically not necessarily consecutive.
2. The physical addresses allocated by vmalloc () do not need to be consecutive, while kmalloc () ensures that the pages are physically consecutive.
3. kmalloc memory allocation is based on slab. Therefore, some features of slab include coloring and alignment, which provides better performance. The physical and logical addresses are continuous.
4. The main difference is the allocation size. For example, if you need 28 bytes, you must use kmalloc. If you use vmalloc, the machine will go on strike after a few allocations.
Although physical contiguous memory blocks are only required in some cases, many kernel code calls kmalloc () instead of vmalloc () to obtain the memory. This is mainly because of performance considerations. The vmalloc () function must create a page table to convert a physically discontinuous page into a continuous page in a virtual address space. Also, the pages obtained through vmalloc () must be mapped one by one (because they are not physically consecutive), which leads to a buffer refresh that is much larger than direct memory ing. For these reasons, vmalloc () is used only when absolutely necessary-typically to obtain a large memory, for example, when a module is dynamically inserted into the kernel, load the module to the memory allocated by vmalloc.