Linux Kernel Architecture

(Jacob Rumans) #1

Chapter3:MemoryManagement


Empty nodes with no pages can obviously be skipped. If the memory map has not already been set up
by architecture-specific code (this can happen, e.g., on IA-64 systems), then the memory required for
all instances ofstruct pageassociated with the node must be allocated. Individual architectures can
provide a specific function for this purpose. This is, however, currently only the case for IA-32 with a
discontiguous memory configuration. On all other configurations, the regular boot memory allocator is
used to perform the allocation. Notice that the code aligns the memory map with the maximal allocation
order of the buddy system because this is required for all calculations to work properly.

A pointer to this space is held not only in thepglist_datainstance but also in the global variable
mem_map— providing the node just examined is the zeroth node of the system (always the case on a
system with just one memory node).mem_mapis a global array that we will come across frequently in our
description of memory management.

mm/memory.c
struct page *mem_map;

The heavy work involved in the initialization of zone data structures is carried out by
free_area_init_core, which iterates over all zones of the node one after the other.

mm/page_alloc.c
static void __init free_area_init_core(struct pglist_data *pgdat,
unsigned long *zones_size, unsigned long *zholes_size)
{
enum zone_type j;
int nid = pgdat->node_id;
unsigned long zone_start_pfn = pgdat->node_start_pfn;
...
for (j = 0; j < MAX_NR_ZONES; j++) {
struct zone *zone = pgdat->node_zones + j;
unsigned long size, realsize, memmap_pages;

size = zone_spanned_pages_in_node(nid, j, zones_size);
realsize = size - zone_absent_pages_in_node(nid, j,
zholes_size);
...

The true size of the zone is obtained by correcting the number of spanned pages with the number of
holes. Both quantities are computed by two helper functions, which I will not bother to discuss in more
detail. Their complexity naturally depends on the memory model and configuration options chosen, but
ultimately all variants do not provide any unexpected surprises.

mm/page_alloc.c
...
if (!is_highmem_idx(j))
nr_kernel_pages += realsize;
nr_all_pages += realsize;

zone->spanned_pages = size;
zone->present_pages = realsize;
...
zone->name = zone_names[j];
...
zone->zone_pgdat = pgdat;
Free download pdf