Chapter3:MemoryManagement
free_area_init_nodesfirst has to analyze and rewrite the information provided by the architecture-
specific code. Among others, the numbers of the lowest and highest page frames that can beused—in
contrast to the principal boundaries specified inzone_max_pfnandzone_min_pfn— need to be obtained
for each zone. Two global arrays are used to store the information:
mm/page_alloc.c
static unsigned long __meminitdata arch_zone_lowest_possible_pfn[MAX_NR_ZONES];
static unsigned long __meminitdata arch_zone_highest_possible_pfn[MAX_NR_ZONES]
First of all, however,free_area_init_nodessortstheentriesinearly_node_mapby their first page frame
start_pfn.
mm/page_alloc.c
void __init free_area_init_nodes(unsigned long *max_zone_pfn)
{
unsigned long nid;
enum zone_type i;
/* Sort early_node_map as initialisation assumes it is sorted */
sort_node_map();
...
Sorting the entries makes life easier for the following tasks, but is not particularly complicated, so it is
not required to inspectsort_node_mapfurther. Just note that the kernel provides a generic heap sort
implementation inlib/sort.cthat is employed by the function.
The information passed tofree_area_init_nodesinmax_zone_pfnrecords the maximal page frame
numbers that can be contained in each zone.free_area_init_nodesprepares a more convenient
representation of this information by providing page frame intervals of the form [low, high] for
each zone in the aforementioned global variables (I omit initialization of these variables with
zero bytes):
mm/page_alloc.c
arch_zone_lowest_possible_pfn[0] = find_min_pfn_with_active_regions();
arch_zone_highest_possible_pfn[0] = max_zone_pfn[0];
for (i = 1; i < MAX_NR_ZONES; i++) {
if (i == ZONE_MOVABLE)
continue;
arch_zone_lowest_possible_pfn[i] =
arch_zone_highest_possible_pfn[i-1];
arch_zone_highest_possible_pfn[i] =
max(max_zone_pfn[i], arch_zone_lowest_possible_pfn[i]);
}
The auxiliary functionfind_min_pfn_with_active_regionsis used to find the smallest regis-
tered usable page frame for the lowest registered zone. This need not necessarily beZONE_DMA,
but can, for instance, also beZONE_NORMALif the machine does not require DMA memory. The
maximum page frame for the smallest zone can be directly taken from the information provided by
max_zone_pfn.