Bootmem Analysis in uclinux2.6 (bf561) (3): init_bootmem_node

Source: Internet
Author: User

The implementation of this function is in mm/bootmem. c:/** called once to set up the Allocator itself. */static unsigned long _ init partition (pg_data_t * pgdat, unsigned long mapstart, unsigned long start, unsigned long end) {bootmem_data_t * bdata = pgdat-> bdata; unsigned long mapsize; bdata-> node_bootmem_map = phys_to_virt (pfn_phys (mapstart); bdata-> node_boot_start = pfn_phys (start); bdata-> node_low_pfn = end; link_boo Tmem (bdata);/** initially all pages are reserved-setup_arch () has to * register free RAM areas explicitly. */mapsize = get_mapsize (bdata); memset (bdata-> node_bootmem_map, 0xff, mapsize); Return mapsize;} unsigned long _ init partition (pg_data_t * pgdat, unsigned long freepfn, unsigned long startpfn, unsigned long endpfn) {return init_bootmem_core (pgdat, freepfn, startpfn, endpfn);} Data Transmission on Parameters When passed to init_bootmem_core, the corresponding values of each parameter are: mapstart takes memory_start> page_shift, that is, the first page number after the kernel code ends. Start takes page_offset> page_shift, 0. The end value is memory_end> page_shift, that is, the last page number of the SDRAM. 1. Meaning of bdata membersFrom the implementation of this function, we can see that it only initializes bdata members of the structure pg_data_t. Let's look at the definition of bootmem_data_t: /** node_bootmem_map is a map pointer-the bits represent all physical * Memory pages (including holes) on the node. */typedef struct bootmem_data {unsigned long node_boot_start; unsigned long timeout; void * node_bootmem_map; unsigned long last_offset; unsigned long last_pos; unsigned long timeout;/* previous allocation Point. To speed * up searching */struct list_head list;} bootmem_data_t; the initialization function roughly shows the meaning of several members. L Node_bootmem_mapBdata-> node_bootmem_map = phys_to_virt (pfn_phys (mapstart); in this line of statements, mapstart is the first page number after the kernel code ends. pfn_phys is defined as: # define pfn_phys (X) (x) <page_shift) while phys_to_virt is defined as: # define phys_to_virt (vaddr) (void *) (vaddr )) therefore, node_bootmem_map saves the page address of the first page after the kernel ends, rather than the page number. L Node_boot_startBdata-> node_boot_start = pfn_phys (start); Value: 0. L Node_low_pfnBdata-> node_low_pfn = end; the page number pointing to the last page in the SDRAM. 2 link_bootmemThis function is implemented as:/** link bdata in order */static void _ init link_bootmem (bootmem_data_t * bdata) {bootmem_data_t * ent; If (list_empty (& bdata_list )) {list_add (& bdata-> list, & bdata_list); return;}/* Insert in order */list_for_each_entry (ENT, & bdata_list, list) {If (bdata-> node_boot_start <ent-> node_boot_start) {list_add_tail (& bdata-> list, & ent-> list); return ;}} list_add_tail (& bdata-> list, & bdata_l IST);} Put bdata in a linked list named bdata_list. The definition of bdata_list is bootmem. in C: static list_head (bdata_list); For bf561, this function will be called only once and the Code marked in red will not be executed. Therefore, the linked list of bdata_list also has only one element! 3 get_mapsizeGet_mapsize is implemented as:/** given an initialised bdata, it returns the size of the boot bitmap */static unsigned long _ init get_mapsize (bootmem_data_t * bdata) {unsigned long mapsize; unsigned long start = pfn_down (bdata-> node_boot_start); unsigned long end = bdata-> node_low_pfn; mapsize = (end-Start) + 7)/8; return align (mapsize, sizeof (long);} Where bdata-> node_boot_start points to the starting position of the SDRAM, and its value is 0. Bdata-> node_low_pfn is the page number of the last page of SDRAM. So far, we can see that bootmem is trying to use a binary bit to indicate whether a page is occupied. If it is idle, this bit is 0. If it is used, this bit is 1. For 64 m sdram, the page size is 4 K, so the total number of pages is 0x3fff (16 K), and the required bytes are 0x800. We can also know from here that bootmem uses the 1st page after kernel code to save all the usage of the SDRAM page.

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.