https://www.cnblogs.com/tolimit/p/5287801.html
在zone_sizes_init 之后,各个node,zone'的page总数已知。但是此时的每个order的空闲链表是空的,也就是无法通过alloc_page这种接口来分配。此时page还在memblock管控,需要memblock释放。释放的函数是free_low_memory_core_early:
mm_init //init/main.c
mem_init(void) //arch/arm64/mm/init.c
memblock_free_all();
void __init memblock_free_all(void)
{
unsigned long pages;
free_unused_memmap();
reset_all_zones_managed_pages();
pages = free_low_memory_core_early();
totalram_pages_add(pages);
}
free_low_memory_core_early
for_each_free_mem_range
__free_memory_core(start, end);
__free_pages_memory(start_pfn, end_pfn);
memblock_free_pages(pfn_to_page(start), start, order);
__free_pages_core
__free_pages_ok
__free_one_page
在memblock_free_all之前,各个NUMA的pglist_data的zone下面不同order的nr_free链表数为0:
[ 0.000000] ===show_mem_info after zone_sizes_init
[ 0.000000] ===show_pgdata_info nodeid 0
[ 0.000000] ===show_zone_info :
name : DMA
managed_pages:7a000
spanned_pages:80000
present_pages:7c000
[ 0.000000] MAX_ORDER 10 of order :0 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :1 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :2 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :3 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :4 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :5 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :6 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :7 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :8 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :9 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :10 has nr_free 0
[ 0.000000] ===show_zone_info :
name : DMA32
managed_pages:0
spanned_pages:0
present_pages:0
[ 0.000000] MAX_ORDER 10 of order :0 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :1 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :2 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :3 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :4 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :5 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :6 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :7 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :8 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :9 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :10 has nr_free 0
[ 0.000000] ===show_zone_info :
name : Normal
managed_pages:762000
spanned_pages:2680000
present_pages:780000
[ 0.000000] MAX_ORDER 10 of order :0 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :1 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :2 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :3 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :4 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :5 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :6 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :7 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :8 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :9 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :10 has nr_free 0
[ 0.000000] ===show_zone_info :
name : Movable
managed_pages:0
spanned_pages:0
present_pages:0
[ 0.000000] MAX_ORDER 10 of order :0 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :1 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :2 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :3 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :4 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :5 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :6 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :7 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :8 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :9 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :10 has nr_free 0
在memblock_free_all之后,才有,特别是order为10的情况最多,这是看空闲的组成大的buddy:
[ 0.000000] ===free_low_mwmory_core_early return pages 7c4864
[ 0.000000] ===show_mem_info after memblock_free_all
[ 0.000000] ===show_pgdata_info nodeid 0
[ 0.000000] ===show_zone_info :
name : DMA
managed_pages:6b9f1
spanned_pages:80000
present_pages:7c000
[ 0.000000] MAX_ORDER 10 of order :0 has nr_free 5
[ 0.000000] MAX_ORDER 10 of order :1 has nr_free 4
[ 0.000000] MAX_ORDER 10 of order :2 has nr_free 5
[ 0.000000] MAX_ORDER 10 of order :3 has nr_free 4
[ 0.000000] MAX_ORDER 10 of order :4 has nr_free b
[ 0.000000] MAX_ORDER 10 of order :5 has nr_free 4
[ 0.000000] MAX_ORDER 10 of order :6 has nr_free 6
[ 0.000000] MAX_ORDER 10 of order :7 has nr_free 6
[ 0.000000] MAX_ORDER 10 of order :8 has nr_free 6
[ 0.000000] MAX_ORDER 10 of order :9 has nr_free 5
[ 0.000000] MAX_ORDER 10 of order :10 has nr_free 1a9
[ 0.000000] ===show_zone_info :
name : DMA32
managed_pages:0
spanned_pages:0
present_pages:0
[ 0.000000] MAX_ORDER 10 of order :0 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :1 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :2 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :3 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :4 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :5 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :6 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :7 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :8 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :9 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :10 has nr_free 0
[ 0.000000] ===show_zone_info :
name : Normal
managed_pages:758e73
spanned_pages:2680000
present_pages:780000
[ 0.000000] MAX_ORDER 10 of order :0 has nr_free 1
[ 0.000000] MAX_ORDER 10 of order :1 has nr_free 1
[ 0.000000] MAX_ORDER 10 of order :2 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :3 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :4 has nr_free 1
[ 0.000000] MAX_ORDER 10 of order :5 has nr_free 1
[ 0.000000] MAX_ORDER 10 of order :6 has nr_free 1
[ 0.000000] MAX_ORDER 10 of order :7 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :8 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :9 has nr_free 1
[ 0.000000] MAX_ORDER 10 of order :10 has nr_free 1d63
[ 0.000000] ===show_zone_info :
name : Movable
managed_pages:0
spanned_pages:0
present_pages:0
[ 0.000000] MAX_ORDER 10 of order :0 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :1 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :2 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :3 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :4 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :5 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :6 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :7 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :8 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :9 has nr_free 0
[ 0.000000] MAX_ORDER 10 of order :10 has nr_free 0