Linux Kernel Architecture

(Jacob Rumans) #1

Chapter3:MemoryManagement


Registering Regions on IA-32


Besides callingadd_active_range, the functionzone_sizes_initstores the boundaries of the different
memory zones in terms of page frames.

arch/x86/kernel/setup_32.c
void __init zone_sizes_init(void)
{
unsigned long max_zone_pfns[MAX_NR_ZONES];
memset(max_zone_pfns, 0, sizeof(max_zone_pfns));
max_zone_pfns[ZONE_DMA] =
virt_to_phys((char *)MAX_DMA_ADDRESS) >> PAGE_SHIFT;
max_zone_pfns[ZONE_NORMAL] = max_low_pfn;
#ifdef CONFIG_HIGHMEM
max_zone_pfns[ZONE_HIGHMEM] = highend_pfn;
add_active_range(0, 0, highend_pfn);
#else
add_active_range(0, 0, max_low_pfn);
#endif

free_area_init_nodes(max_zone_pfns);
}

MAX_DMA_ADDRESSis the highest suitable memory address for DMA operations. The constant is
declared asPAGE_OFFSET+0x1000000. Recall that the physical pages are mapped into the virtual
starting fromPAGE_OFFSET, and the first 16 MiB — hexadecimal0x1000000— are suitable for DMA
operations. Conversion withvirt_to_physyields the address in physical memory, and shifting
right byPAGE_SHIFTbits effectively divides this figure by the page size and produces the number
of pages that can be used for DMA. Unsurprisingly, the result is 4,096 since IA-32 uses pages
of 4 KiB.

max_low_pfnandhighend_pfnare global constants to specify the highest page number in the low
(usually≤896 MiB if 3 : 1 split of the address space is used) and high memory ranges that were
filled before.

Notice thatfree_area_init_nodeswill combine the information inearly_mem_mapandmax_zone_pfns:
The active ranges for each memory region are selected,and architecture-independent data structures are
constructed.

Registering Regions on AMD64


Registering the available memory is split between two functions on AMD64. The active memory regions
are registered as follows:

arch/x86/kernel/e820_64.c
e820_register_active_regions(int nid, unsigned long start_pfn,
unsigned long end_pfn)
{
unsigned long ei_startpfn;
unsigned long ei_endpfn;
int i;
Free download pdf