歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux教程

Linux節點和內存管理區的初始化

節點和管理區是內存管理中所涉及的重要概念,其數據結構在前文《linux物理內存概述》中已經介紹,現在讓我們來看看linux是如何完成節點和管理區的。

在內核首先通過setup_arch()-->paging_init()-->zone_sizes_init()來初始化節點和管理區的一些數據項

  1. static void __init zone_sizes_init(void)  
  2. {  
  3.     unsigned long max_zone_pfns[MAX_NR_ZONES];  
  4.     memset(max_zone_pfns, 0, sizeof(max_zone_pfns));  
  5.   
  6.     /*分別獲取三個管理區的頁面數*/  
  7.     max_zone_pfns[ZONE_DMA] =  
  8.         virt_to_phys((char *)MAX_DMA_ADDRESS) >> PAGE_SHIFT;  
  9.     max_zone_pfns[ZONE_NORMAL] = max_low_pfn;  
  10. #ifdef CONFIG_HIGHMEM   
  11.     max_zone_pfns[ZONE_HIGHMEM] = highend_pfn;  
  12. #endif   
  13.   
  14.     free_area_init_nodes(max_zone_pfns);  
  15. }  

在獲取了三個管理區的頁面數後,通過free_area_init_nodes()來完成後續工作

  1. void __init free_area_init_nodes(unsigned long *max_zone_pfn)  
  2. {  
  3.     unsigned long nid;  
  4.     int i;  
  5.   
  6.     /* Sort early_node_map as initialisation assumes it is sorted */  
  7.     sort_node_map();/*將所有節點按起始頁框號排序*/  
  8.   
  9.     /* Record where the zone boundaries are */  
  10.     /*記錄三個管理區的邊界*/  
  11.     memset(arch_zone_lowest_possible_pfn, 0,  
  12.                 sizeof(arch_zone_lowest_possible_pfn));  
  13.     memset(arch_zone_highest_possible_pfn, 0,  
  14.                 sizeof(arch_zone_highest_possible_pfn));  
  15.     arch_zone_lowest_possible_pfn[0] = find_min_pfn_with_active_regions();  
  16.     arch_zone_highest_possible_pfn[0] = max_zone_pfn[0];  
  17.     for (i = 1; i < MAX_NR_ZONES; i++) {  
  18.         if (i == ZONE_MOVABLE) /*不處理ZONE_MOVABLE*/  
  19.             continue;  
  20.         /*將下一個管理區的起始頁框置為上一個管理區的結束頁框*/  
  21.         arch_zone_lowest_possible_pfn[i] =  
  22.             arch_zone_highest_possible_pfn[i-1];  
  23.         arch_zone_highest_possible_pfn[i] =  
  24.             max(max_zone_pfn[i], arch_zone_lowest_possible_pfn[i]);  
  25.     }  
  26.     arch_zone_lowest_possible_pfn[ZONE_MOVABLE] = 0;  
  27.     arch_zone_highest_possible_pfn[ZONE_MOVABLE] = 0;  
  28.   
  29.     /* Find the PFNs that ZONE_MOVABLE begins at in each node */  
  30.     memset(zone_movable_pfn, 0, sizeof(zone_movable_pfn));  
  31.     find_zone_movable_pfns_for_nodes(zone_movable_pfn);  
  32.   
  33.     /* Print out the zone ranges */  
  34.     printk("Zone PFN ranges:\n");  
  35.     for (i = 0; i < MAX_NR_ZONES; i++) {  
  36.         if (i == ZONE_MOVABLE)  
  37.             continue;  
  38.         printk("  %-8s %0#10lx -> %0#10lx\n",  
  39.                 zone_names[i],  
  40.                 arch_zone_lowest_possible_pfn[i],  
  41.                 arch_zone_highest_possible_pfn[i]);  
  42.     }  
  43.   
  44.     /* Print out the PFNs ZONE_MOVABLE begins at in each node */  
  45.     printk("Movable zone start PFN for each node\n");  
  46.     for (i = 0; i < MAX_NUMNODES; i++) {  
  47.         if (zone_movable_pfn[i])  
  48.             printk("  Node %d: %lu\n", i, zone_movable_pfn[i]);  
  49.     }  
  50.   
  51.     /* Print out the early_node_map[] */  
  52.     printk("early_node_map[%d] active PFN ranges\n", nr_nodemap_entries);  
  53.     for (i = 0; i < nr_nodemap_entries; i++)  
  54.         printk("  %3d: %0#10lx -> %0#10lx\n", early_node_map[i].nid,  
  55.                         early_node_map[i].start_pfn,  
  56.                         early_node_map[i].end_pfn);  
  57.   
  58.     /* Initialise every node */  
  59.     mminit_verify_pageflags_layout();  
  60.     setup_nr_node_ids();  
  61.     for_each_online_node(nid) {/*遍歷每個節點*/  
  62.         pg_data_t *pgdat = NODE_DATA(nid);  
  63.         /*初始化節點*/  
  64.         free_area_init_node(nid, NULL,  
  65.                 find_min_pfn_for_node(nid), NULL);  
  66.   
  67.         /* Any memory on that node */  
  68.         if (pgdat->node_present_pages)  
  69.             node_set_state(nid, N_HIGH_MEMORY);  
  70.         check_for_regular_memory(pgdat);  
  71.     }  
  72. }  
Copyright © Linux教程網 All Rights Reserved