Bootmem allocator is a simple memory management mechanism before page tables and Buddy algorithms are available. It is a process in the early startup of Linux kernel and also the ancestor of other memory management algorithms, its implementation method is relatively simple. We only need to understand its main functions and working principles, so we don't need to study it further.
Question 1: Memory range managed by bootmem Allocator
PFN = 0 to PFN = max_low_pfn, that is, low-end general memory, usually refers to memory smaller than MB.
Question 2: How bootmem Allocator works
Use a simple ing relationship: each 1 bit corresponds to a page frame (page frame) of the physical memory ). Therefore, you must first apply for a memory as the mapped bitmap. The bitmap size is max_low_pfn/8 bytes.
1 first, set all bits in the bitmap to 1, indicating that the corresponding page frame is unavailable.
2. Based on the memory information (e81_map []) detected by e820, set the location in the bitmap corresponding to the page frame of the e820_ram type to 0,
Indicates that the corresponding page frame is idle.
3. Mark part of the occupied page frame as 1, which indicates that it is unavailable. It mainly includes:
(1) The first page frame, which has special purposes, such as BIOS usage and SMP operations.
(2) protection mode kernel, temporary page table, and bootmem Allocator bit chart
(3) Other special page frames, such as EBDA region and ACPI
So far, the initialization of bootmem Allocator has been completed.
Question 3: Functions of bootmem Allocator
1. Manage the memory usage of the Linux kernel before the buddy algorithm
2. initialize the node, zone, and page systems to prepare for the buddy algorithm.
3. Establish the management structure of the buddy algorithm. It mainly includes the idle page frame into the management system of the buddy algorithm.
Focus on the establishment of the node, zone, and page architecture: the zone_sizes_init function first determines the range of different types of zones, and then initializes pglist_data (node) in free_area_init_node ), in the X86 architecture, there is only one node, namely contig_page_data. Then, initialize the Zone in the node, calculate the number of pages of the node, and finally apply for this multiple page frame from bootmem allocator, initialize the corresponding number of page structures based on the page frame, but here we only set the status of all pages to keep until the end, in the free_all_bootmem_core function, the kernel sets the status of the corresponding page structure based on the status of the page frame identified in the bootmem Allocator bitmap.
After the above node, zone, and page architecture is initialized, the buddy algorithm can run correctly. Because the buddy algorithm mainly uses a Data Structure struct free_area [max_order], this data structure is released for each page by calling _ free_pages_bootmem (page, order) in free_all_bootmem_core, to initialize the buddy system.
For more information about the buddy algorithm, see Buddy system initialization.