Chapter3:MemoryManagement
for (i = 0; i < e820.nr_map; i++)
if (e820_find_active_region(&e820.map[i],
start_pfn, end_pfn,
&ei_startpfn, &ei_endpfn))
add_active_range(nid, ei_startpfn, ei_endpfn);
}
Essentially the code iterates over all regions provided by the BIOS and finds the active region for each
entry. This is interesting becauseadd_active_rangeis potentially called multiple times in contrast to the
IA-32 variant.
Filling inmax_zone_pfnsis handled bypaging_init:
arch/x86/mm/init_64.c
void __init paging_init(void)
{
unsigned long max_zone_pfns[MAX_NR_ZONES];
memset(max_zone_pfns, 0, sizeof(max_zone_pfns));
max_zone_pfns[ZONE_DMA] = MAX_DMA_PFN;
max_zone_pfns[ZONE_DMA32] = MAX_DMA32_PFN;
max_zone_pfns[ZONE_NORMAL] = end_pfn;
...
free_area_init_nodes(max_zone_pfns);
}
The page frame boundaries for the 16- and 32-bit DMA regions are stored in pre-processor symbols that
translate the 16 MiB and 4 GiB ranges into page frames:
include/asm-x86/dms_64.h
/* 16MB ISA DMA zone */
#define MAX_DMA_PFN ((16*1024*1024) >> PAGE_SHIFT)
/* 4GB broken PCI/AGP hardware bus master zone */
#define MAX_DMA32_PFN ((4UL*1024*1024*1024) >> PAGE_SHIFT)
end_pfnis the largest page frame number detected. Since AMD64 does not require high memory, the
corresponding entry inmax_zone_pfnsremainsNULL.
Address SpaceSetupon AMD64
The address space setup on AMD64 systems is easier than for IA-32 in some respects, but unfortunately
also harder in others. While having a 64-bit virtual address space allows for avoiding oddities like high
memory, things are complicated by another factor: The address space spanned by 64 bits is so large
that there are currently simply no applications that would require this. Current implementations there-
fore implement a smallerphysical address spacethat is only 48 bits wide. This allows for simplifying and
speeding up address translation without losing flexibility: 2^48 bits still allows addressing 256 TiB, or
256 ×1,024 GiB — which is plenty even for Firefox!
While the physical address space is restricted to 48 bits, addressing the virtual address space is still per-
formed with 64-bit pointers, and the space therefore has to span 64 bits formally. This raises a problem,
though: Some parts of the virtual address space cannot be addressed because effectively only 48 bits can
be handled.