Monday, June 3, 2013

ARM linux build process page table

paging_init used to create the page table, initialize the memory map zone


  1. void  * zero_page;  
  2.   
  3. Sort (& meminfo.bank, meminfo.nr_banks,  sizeof (meminfo.bank [0]), meminfo_cmp, NULL);  
  4.   
  5. build_mem_type_table ();  
  6. sanity_check_meminfo ();  
  7. prepare_page_table ();  
  8. map_lowmem ();  
  9. bootmem_init ();  
  10. devicemaps_init (mdesc);  
  11. kmap_init ();  
  12.   
  13. top_pmd = pmd_off_k (0xffff0000);  
  14.   
  15. / * 
  16.  * Allocate the zero page. Note that this always succeeds and 
  17.  * Returns a zeroed result. 
  18.  * /  
  19. zero_page = alloc_bootmem_low_pages (PAGE_SIZE);  
  20. empty_zero_page = virt_to_page (zero_page);  
  21. __flush_dcache_page (NULL, empty_zero_page);  

build_mem_type_table This function is based on CPU type, set mem_types global array, mem_types array holds the page directory and page table attributes in the future create the page directory and page tables, will be used mem_types.

sanity_check_meminfo testing to determine whether you need to create highmem area and rebuild the array describes the memory bank
VMALLOC_MIN vmalloc area defines the starting position (via VMALLOC_END and vmalloc_reserve calculated), VMALLOC_END vmalloc area defines the end position, vmalloc_reserve vmalloc area is reserved for the system size.

prepare_page_table This function will call an empty page directory, there are two address space area is not clear, one kernel image, the other is the kernel linear address mapping area

map_lowmem build low memory all pages directory and page tables: Traversing memory bank, mapping those without highmem tag memory bank

bootmem_init:
1 call check_initrd get initrd memory bank where the corresponding node
2 for each node:
  • Gets the node's min (minimum pfn), node_low (maximum low memory pfn), node_hight (maximum high memory pfn)
  • Call bootmem_init_node initialization node, bootmem_init_node initializes bootmem bitmap
  • If the node 0, then the call reserve_node_zero to node 0 reserve of memory: the kernel text and data areas, initializing page table area (16KB), as well as a memory swapper_pg_dir before (on my machine is 4 page)
  • If initrd stored in the current node, then call bootmem_reserve_initrd initrd reserved memory occupied.initrd_start is initrd in starting virtual memory address, initrd_end initrd end is a virtual memory address.
3 For each node calls bootmem_free_node
  • Set this node within the size of each zone
  • Call free_area_init_node: computing node number of the total pages for this node allocated mem map, pay attention to all the zone of the node are assigned together memmap
  • Call free_area_init_core: for each node within the zone, is initialized. Note that this function is present_pages total size of the partition is less occupied memmap corresponding pages, but in fact is on the node memmap the starting position where the value does not seem to be less
4. High_memory is a very strange variables, high_memory should be a concept of physical memory, but the exact high_memory variable holds a kernel address.

devicemaps_init This function creates a mapping device,
1. The machine vectors mapped at 0xffff0000
2 Call the platform-specific map_io, for mx51, this function is mainly mapping mx51 function register area, AIPS1 AIPS2 and SPBA0, these three registers zone size is 1MB, after mapping virtual addresses are 0xF7E00000, 0xF7D00000, 0xFB100000

kmap_init create pkmap the pgd and pte. And let pkmap_page_table point to the PTE page of linux p/t.Generally kmap are used to map a page of pte high memory into the kernel address space, for the arm, each page can store 512 pte_t, so pkmap address space is 2M.

empty zero page 
According to source notes, it is initialized to 0 for a particular page, for COW
My understanding is that the system sometimes need a page all zero, in which case, do not need to allocate a page of all zeros, but let PTE point empty_zero_page, when trying to write this page, because this empty_zero_page is shared, so led COW.

No comments:

Post a Comment