Linux version: 2.6.36
Related data structure
Arch/arm/include/asm/setup.h
#ifdef config_arch_lh7a40x
# define Nr_banks 16
#else
# define Nr_banks 8
#endif
struct Membank {
unsigned long start;
unsigned long size;
unsigned int highmem;
};
struct Meminfo {
int nr_banks;
struct Membank bank[nr_banks];
};
The memory management of the Linux kernel is divided into three phases.
1. Start---->BOOTMEM initialization completes as the first stage. Only memory can be allocated using the Memblock_reserve function at this stage.
This stage end flag is: Init_bootmem_done = 1.
2. Bootmem initialization is completed before the completion of the--->buddy. End sign for mem_init_done = 1.
3. Complete memory initialization, you can allocate memory with cache and buddy.
Memory raw data passed by U-boot, in contrast to this development Board Uboot part of the memory initialization function, we know Uboot passed over the Tag->u.mem.start, Tag->u.mem.size, respectively, 0x30000000, 0x4000000, that is, the memory start address is 0x30000000, the size of 64m,start_arch gets the parameter address passed by U-boot, and the Parse_tag_mem32 function is called to handle the passed memory parameter:
556 static int __init parse_tag_mem32 (const struct TAG *tag)
557 {
558 return Arm_add_memory (Tag->u.mem.start, tag->u.mem.size);
559}
560
561 __tagtable (Atag_mem, parse_tag_mem32);
As seen above, the Parse_tag_mem32 function calls the Arm_add_memory function to save parameters such as start and size of RAM into the meminfo structure of the MEMINFO structure. Now we're going to analyze arm_add_memory.
Arm_add_memory is defined as follows (ARCH/ARM/KERNEL/SETUP.C)
static int __init arm_add_memory (unsigned long start, unsigned long size)
{
struct Membank *bank = &meminfo.bank[meminfo.nr_banks];
if (meminfo.nr_banks >= nr_banks) {
PRINTK (Kern_crit "nr_banks too Low,"
"Ignoring memory at% #lx \ n", start);
Return-einval;
}
/*
* Ensure that start/size are aligned to a page boundary.
* The Size is appropriately rounded down, the start is rounded up.
*/
Size = start & ~page_mask;
Bank->start = Page_align (start);
bank->size = size & page_mask;
/*
* Check Whether this memory region has non-zero size or
* Invalid node number.
*/
if (bank->size = 0)
Return-einval;
meminfo.nr_banks++;
return 0;
}
After such a process, the meminfo in the Setup.c file is no longer
struct Meminfo Meminfo = {0,};
But
struct Meminfo meminfo = {1,{0x30000000,0x4000000,0},{},};
Indicates that there is currently an area of memory where the physical address starts at 0x30000000, the size is 64M, and the node is 0
After processing the data, Start_arch calls the No. 822 row to call Arm_memblock_init (&meminfo, Mdesc);
Analyze the 1th phase first.
1. Initialization: Setup_arch-->arm_memblock_init-->memblock_init
Arch/arm/mm/init.c
270 void __init arm_memblock_init (struct meminfo *mi, struct MACHINE_DESC)
271 {
272 int i;
273
274 Memblock_init ();
275 for (i = 0; i < mi->nr_banks; i++)
276 Memblock_add (Mi->bank[i].start, mi->bank[i].size);
277
278/* Register the kernel text, kernel data and initrd with Memblock. */
279 #ifdef Config_xip_kernel//configuration kernel XIP mode, to avoid the kernel from nor Flash copy to main memory SDRAM space, let the kernel run in the Low-power nor flash, save the system start-up time, reduce the system to SDRAM Need, reduce power consumption, so that products can continue to use a longer time
280 Memblock_reserve (__pa (_data), _end-_data);
281 #else
282 Memblock_reserve (__pa (_stext), _end-_stext);
/* Line No. 282, in 0 nodes to retain the kernel mirror part of the memory, probably 0x30108000 to the next 5M or so (after the decompression of the kernel).
Refer to Arch/arm/kernel/vmlinux.lds file,
375 SECTIONS
376 {
377. = 0xc0000000 + 0x00108000;
378. Init: {/* init code and Data */
379 _stext =.;
So stext equals c0108000, corresponds to physical address 30108000,
For _end again, refer to ARCH/ARM/KERNEL/VMLINUX.LDS.S file, which is also in the sections area, defined in 233 lines
232 bss_section (0, 0, 0)
233 _end =.;
For my ported 2.3.36 kernel, _end equals c0555b60, corresponding to the physical address 30555b60, after this statement add print information to get
_end-_stext=44db60,4.512608m size, so this sentence function is to 0x30108000 ~ 0X30555B60 This paragraph (4.512608M) space to retain.
*/
283 #endif
284 #ifdef CONFIG_BLK_DEV_INITRD//The Development Board is not configured
285 if (phys_initrd_size) {
286 Memblock_reserve (Phys_initrd_start, phys_initrd_size);
287
* * Now convert INITRD to virtual addresses * *
289 Initrd_start = __phys_to_virt (Phys_initrd_start);
290 Initrd_end = Initrd_start + phys_initrd_size;
291}
292 #endif
293
294 Arm_mm_memblock_reserve ()//is the 0x30104000 ~ 0x30108000 This paragraph (16K) for the content of the page directory to retain.
295
296/* Reserve any platform specific memblock areas * *
297 if (Mdesc->reserve)//is not defined in st2410
298 Mdesc->reserve ();
299
Memblock_analyze ()//Calculate memory block Size
Memblock_dump_all ()//display
302}
Memory raw data passed by U-boot, after initialization of Memblock_init, Arm_memblock_init function Memblock_add call memblock_add_region add raw memory data, my board with 64M memory , namely: 0x0000 0000->0x40000000, after the completion of the configuration as follows:
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service