Linux Kernel Architecture

(Jacob Rumans) #1

Chapter3:MemoryManagement


include/asm-x86/pgtable_64.h
#define __AC(X,Y) (X##Y)
#define _AC(X,Y) __AC(X,Y)

#define __PAGE_OFFSET _AC(0xffff810000000000, UL)
#define PAGE_OFFSET __PAGE_OFFSET
#define MAXMEM _AC(0x3fffffffffff, UL)

Modules

TASK_SIZE_64Ox FFFF 8000 0000 0000PAGE_OFFSET VMALLOC_STARTVMALLIC_ENDVMMEMMAP_STARTKERNEL_TEXT_START_START_KERNEL_MAP_START_KERNELMODULES_VADDRMODULES_END
Identity maped pages
Hole
(unused)

KERNEL_TEXT_SIZE
212 Bits

246
0

Non-canonical area Bits (MAXMEM)

Figure 3-19: Organization of the virtual address space on AMD64 systems. The image is not drawn to
scale, naturally.

Note that_ACis used to mark a given constant with a suffix._AC(17,UL)becomes(17UL), for instance,
which makes the constant anunsigned long. This can be handy in C code, but is not allowed in assembler
code, where the_ACmacro directly resolves to the given value without postfix.

Another guard hole is placed between the identity-mapped region and the area forvmallocarea, which
lies betweenVMALLOC_STARTandVMALLOC_END:

include/asm-x86/pgtable_64.h
#define VMALLOC_START _AC(0xffffc20000000000, UL)
#define VMALLOC_END _AC(0xffffe1ffffffffff, UL)

Thevirtual memory map(VMM) area immediately behind thevmallocarea is 1 TiB in size. It is only
useful on kernels that use the sparse memory model. Converting between virtual and physical page
frame number viapfn_to_pageandpage_to_pfncan be costly on such machines because all holes in
the physical address space must be taken into account.Starting with kernel 2.6.24, a simpler solution is
offered by generic code inmm/sparse-memmap.c: The page tables for the VMM area are set up such that
allstruct pageinstances located in physical memory are mapped into the areawithoutany holes. This
provides a virtually contiguous area in which only the active memory regions are included. The MMU
therefore automatically aids the translation between virtual and physical numbers that does not need to
be concerned with holes anymore. This accelerates the operation considerably.

Besides simplifying the translation between physical and virtual page numbers, the technique also has
benefits for the implementation of the auxiliary functionsvirt_to_pageandpage_address, because the
required calculations are likewise simplified.

The kernel text is mapped into the region starting from__START_KERNEL_MAP, with a compile-time con-
figurable offset given byCONFIG_PHYSICAL_START. Setting the offset is required for a relocatable kernel,
Free download pdf