1. Kernel initialization:
* To establish a good core kernel page directory page table database, assuming physical memory size len, is a [3 G - 3G + len]:: [0 - len] such a false address and physical address vaddr paddr the line Sexual relationship;
* The establishment of a core array page, page array and physical pages series is linear counterparts, page to page management of the physical state of each physical page addresses stored in the virtual page-> virtual;
* To establish a good core of a free_list, will not use the physical pages Add to the corresponding page of which has been used do not have to Add to;
2. Kernel module for memory vaddr = get_free_pages (mask, order):
* Memory management module from the free_list find a page, will be page-> virtual as a return value, the return value is the corresponding physical pages of virtual address;
* Page from the free_list of detachment;
* Modules to use the virtual operation of the corresponding address physical memory;
3. Kernel module using vaddr, such as the implementation of directives mov (eax, vaddr):
* CPU was vaddr this virtual address, using the establishment of good-page directory page table database, to find its corresponding physical memory address;
* Eax vaddr write the contents of the corresponding physical memory address;
4. Kernel module release memory free_pages (vaddr, order):
* Vaddr find a basis for the corresponding page;
* Added to the page free_list;
5. User application process memory vaddr = malloc (size):
* Memory management module from the user process memory space (0 - 3 G) to find a space before the vm_area_struct (start - end);
* Then be inserted into the task-> mm-> mmap List;
6. Users into the process vaddr (0-3G), for example, the implementation of directives mov (eax, vaddr):
* CPU was vaddr this virtual address, the virtual address should have been set up by glibc library, some in the 3 G to a certain region, according to CR3 register at the current-> pgd check the current process page directory page table database, found that the vaddr the corresponding page table of contents of 0, it generated anomaly;
* Exceptions, found that the vaddr corresponding vm_area_struct already exists, vaddr to the corresponding page table of contents page of the distribution of a table;
* From free_list then find a page, the page of the physical pages corresponding physical address of the first assign vaddr leader of the corresponding page, it is clear that at this time of vaddr and paddr not a linear relationship;
* Page from the free_list of detachment;
* Exceptions to return;
* CPU just happened to the implementation of the directive abnormal mov (eax, vaddr);
* CPU was vaddr this virtual address, according to CR3 register at the current-> pgd, use of the establishment of good-page directory page table database, to find its corresponding physical memory address;
* Eax vaddr write the contents of the corresponding physical memory address;
7. User process to release memory vaddr, free (vaddr):
* Find the vaddr of the vm_area_struct;
* Find vm_area_struct: start - end all of the corresponding page directory page of the table, emptying all the corresponding page table;
* The release of these pages at the table of the physical pages corresponding to the page, the page and join the queue to free_list;
* The need to be some empty page catalog items, and the release of these items at the table of contents page of the page table;
* From the task-> mm-> mmap chain and the release of the deletion of the vm_area_struct out;
General Description:
* Available physical memory is free_list in the corresponding page of physical memory;
* Page directory page form the main purpose of the database is to visit physical memory, CPU conversion vaddr -> paddr use, distribution, and will not release memory used, but the need for core memory management system in the right time for the good of the establishment of the CPU ;
* For users in the process of six pages in the physical access, two-page table of correspondence, is the core of a page directory page of a database table pte [i], the current process is a core page directory page of a database table A pte [j], but there is only one page and its counterparts. If the scheduling of other processes, applications and other processes to a memory, is not related to the physical pages, as its first allocation from the free_list in finding a page, and the physical pages from the corresponding page in the free_list From out, so there is no other page was the physical process of rewriting operating conditions. Get_free_pages kernel, including through access memory, and will not involve the physical pages, described in principle with the former.




No user commented in " Linux memory management essence "
Follow-up comment rss or Leave a TrackbackLeave A Reply