I. Linux memory structures include node, zone, and page)
Node ---- {zone ----- {page
......
{Zone ----- {page
Ii. How to map high-end memory:
Permanent kernel mapping and temporary kernel mapping and noncontiguous memory)
1) Permanent ing:
Using a page table stored in the kernel is equivalent to creating a page table ing, because the operation page table may sleep.
Void * kmap (struct page * page );
Usage:
Struct page * page = alloc_pages (gfp_highmem, 1 );
Int * vaddr = kmap (PAGE );
2) Temporary ing:
It is implemented by using a page table entry stored in the kernel. This is equivalent to creating a page table ing, which does not cause sleep.
Void * kmap_atomic (struct page * page );
Usage:
Struct page * page = alloc_pages (gfp_highmem, 1 );
Int * vaddr = kmap_atomic (PAGE );
Iii. Memory region Management
The zone and Buddy algorithms solve the problem when applying for a page box: hardware restrictions and memory fragments.
In actual kernel programming, the most common problem is the application and release of MEM requests with different size data structures. To solve the problem of Memory Request efficiency and memory fragmentation,
The cache and slab need to be used for the following reasons:
1) it is quite common to apply for and release the same size of memory. To prevent the kernel from getting tired of these tasks, the kernel provides a method: to build an Slab System Based on cache, each Slab
The corresponding memory unit size is met in a timely manner when the application is made, and the software is recycled when the application is released. This avoids frequent page box operations.
2) to solve the memory fragmentation problem,
Iv. Management of non-contiguous memory zones
The Discontinuous memory area refers to the vmalloc area with consecutive linear addresses and discontinuous physical addresses. This area is used to map the physical memory page boxes that exceed MB,
Generally, it is only applicable to x86 architectures, and embedded architectures such as arm seldom use such a large amount of memory. Therefore, in the ARM architecture, kmap, permanent kernel ing,
No fixed kernel ing is available.
In fact, the implementation of vmalloc is to apply for several page boxes through alloc_pages. Of course, these page boxes are located in highmem to meet the size of the applied memory,
Then, modify the page table and create a ing between the vmalloc linear address segments and these page tables.