----------------------------------------
硬件:E500v2内核PowerPC ,linux版本:2.6.35
----------------------------------------
linux内核的内存管理分三个阶段。
1. 启动---->bootmem初始化完成为第一阶段。此阶段只能使用memblock_reserve函数分配内存。
此阶段结束标志为:init_bootmem_done = 1.
2. bootmem初始化完--->buddy完成前。结束标志为mem_init_done = 1.
3. 全部内存初始化完毕,可以用cache和buddy分配内存。
本文先分析第1阶段。
1. 初始化:head_fsl_booke.S->machine_init->early_init_devtree:
- mm/memblock.c
-
108 void __init memblock_init(void)
-
109 {
-
110 /* Create a dummy zero size MEMBLOCK which will get coalesced away later.
-
111 * This simplifies the memblock_add() code below...
-
112 */
-
113 memblock.memory.region[0].base = 0;
-
114 memblock.memory.region[0].size = 0;
-
115 memblock.memory.cnt = 1;
-
116
-
117 /* Ditto. */
-
118 memblock.reserved.region[0].base = 0;
-
119 memblock.reserved.region[0].size = 0;
-
120 memblock.reserved.cnt = 1;
-
121 }
2. 内存原始数据由u-boot传入,在初始化完memblock_init后,用memblock_add_region加入原始内存数据,我的板子上配了2G内存,即:0x0000 0000->0x80000000,加完后的配置如下:
MEMBLOCK configuration:
rmo_size = 0x80000000
memory.size = 0x0
memory.cnt = 0x1
memory[0x0] 0x0000000000000000 - 0x000000007fffffff, 0x80000000 bytes
reserved.cnt = 0x1
reserved[0x0] 0x0000000000000000 - 0xffffffffffffffff, 0x0 bytes
3. memblock_reserve用来分配内存页。
以分配内核本身占用的内存为例:
/* Reserve MEMBLOCK regions used by kernel, initrd, dt, etc... */
memblock_reserve(PHYSICAL_START, __pa(klimit) - PHYSICAL_START);
分配完之后的内存配置为:
MEMBLOCK configuration:
rmo_size = 0x80000000
memory.size = 0x0
memory.cnt = 0x1
memory[0x0] 0x0000000000000000 - 0x000000007fffffff, 0x80000000 bytes
reserved.cnt = 0x1
reserved[0x0] 0x0000000000000000 - 0x00000000006b0fff, 0x6b1000 bytes
如果分配有连续则进行合并。
几次分配后的配置如下:
MEMBLOCK configuration:
rmo_size = 0x80000000
memory.size = 0x80000000
memory.cnt = 0x1
memory[0x0] 0x0000000000000000 - 0x000000007fffffff, 0x80000000 bytes
reserved.cnt = 0x6
reserved[0x0] 0x0000000000000000 - 0x00000000006b0fff, 0x6b1000 bytes
reserved[0x1] 0x0000000000ffa000 - 0x0000000000ffcfff, 0x3000 bytes
reserved[0x2] 0x000000002fbc4000 - 0x000000002fbdefff, 0x1b000 bytes
reserved[0x3] 0x000000002fbdfa88 - 0x000000002ffff4cc, 0x41fa45 bytes
reserved[0x4] 0x000000002fbe4000 - 0x000000002ffff4cd, 0x41b4ce bytes
reserved[0x5] 0x000000007ffff000 - 0x000000007fffffff, 0x1000 bytes
阅读(992) | 评论(0) | 转发(0) |