Article Title: summary of the principles of memory application in Linux. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
1. address space management
Physical addresses are managed by the kernel. node --> zone --> mem_map --> page, all physical pages correspond to page frames in the mem_map array, and different pages are divided into DMA, normal, highmem three zones.
The Kernel linear address space, in fact, only the low-end memory has a linear address, 0--896MB.
The virtual address of the kernel. The virtual address of the low-end memory is the same as the linear address. High-end memory only has virtual addresses after ing
User space address, tast_struct --> mmap --> mm_struct --> vm_area_struct
2. Memory application or use
For physical memory allocation, _ alloc_pages () must be called in the kernel (). It is the core allocation function. The applied MAX_ORDER power cannot exceed 2. It seems that the maximum size is 4 MB.
Linear address: kmalloc and get_free_pages. The corresponding physical memory is the low-end memory. kmalloc is based on slab allocation technology and cannot exceed kb.
Virtual Address, applied for by vmalloc. it just creates a virtual memory space similar to the vm_area of the user space in the kernel to vmlist, and the final physical memory allocation is still based on the missing page.
The virtual memory of the user space, such as malloc, will eventually be do_map () and do_brk () in the kernel (). In fact, it only creates a virtual space, and the final physical memory is allocated when the page is missing.
3. Memory Switching
Both the page Structure and the vm_area_struct structure of the user layer contain the locked and reserved flags. You can set these labels in a proper way. The page locks are stored in the physical memory and are not exchanged.
4. The device memory can be mapped to the kernel virtual address space through ioremap or the user space through mmap.