至此,节点和管理区的关键数据已完成初始化,内核在后面为内存管理做得一个准备工作就是将所有节点的管理区都链入到zonelist中,便于后面内存分配工作的进行
内核在start_kernel()-->build_all_zonelist()中完成zonelist的初始化
- void build_all_zonelists(void)
- {
- /*设定zonelist的顺序,是按节点还是按管理区排序,只对NUMA有意义*/
- set_zonelist_order();
- if (system_state == SYSTEM_BOOTING) {
- __build_all_zonelists(NULL);
- mminit_verify_zonelist();
- cpuset_init_current_mems_allowed();
- } else {
- /* we have to stop all cpus to guarantee there is no user
- of zonelist */
- stop_machine(__build_all_zonelists, NULL, NULL);
- /* cpuset refresh routine should be here */
- }
- /*得到所有管理区可分配的空闲页面数*/
- vm_total_pages = nr_free_pagecache_pages();
- /*
- * Disable grouping by mobility if the number of pages in the
- * system is too low to allow the mechanism to work. It would be
- * more accurate, but expensive to check per-zone. This check is
- * made on memory-hotadd so a system can start with mobility
- * disabled and enable it later
- */
- if (vm_total_pages < (pageblock_nr_pages * MIGRATE_TYPES))
- page_group_by_mobility_disabled = 1;
- else
- page_group_by_mobility_disabled = 0;
- printk("Built %i zonelists in %s order, mobility grouping %s. "
- "Total pages: %ld\n",
- nr_online_nodes,
- zonelist_order_name[current_zonelist_order],
- page_group_by_mobility_disabled ? "off" : "on",
- vm_total_pages);
- #ifdef CONFIG_NUMA
- printk("Policy zone: %s\n", zone_names[policy_zone]);
- #endif
- }
- static int __build_all_zonelists(void *dummy)
- {
- int nid;
- #ifdef CONFIG_NUMA
- memset(node_load, 0, sizeof(node_load));
- #endif
- for_each_online_node(nid) {/*遍历节点*/
- pg_data_t *pgdat = NODE_DATA(nid);
- build_zonelists(pgdat);
- build_zonelist_cache(pgdat);
- }
- return 0;
- }
