Linux Kernel Architecture

(Jacob Rumans) #1

Chapter3:MemoryManagement


The next major step is performed insetup_memoryof which there are two versions; one for systems with
contiguous memory (inarch/x86/kernel/setup_32.c) and one for machines with discontiguous mem-
ory (inarch/x86/mm/discontig_32.c). They both have the same effect although their implementations
differ.

❑ The number of physical pages available (per node) is determined.
❑ The bootmem allocator is initialized (Section 3.4.3 describes the implementation of the allocator
in detail).
❑ Various memory areas are then reserved, for instance, for the initial RAM disk needed when
running the first userspace processes.

paging_initinitializes the kernel page tables and enables paging since it is not active by default on
IA-32 machines.^12 Execute Disable Protectionis also enabled if supported by the processor and if the ker-
nel was compiled with PAE support; unfortunately, the feature is otherwise not available. By calling
pagetable_init, the function also ensures that the directmapping of physical memory into the kernel
address space is initialized. All page frames in low memory are directly mapped to the virtual memory
region abovePAGE_OFFSET. This allows the kernel to address a good part of the available memory with-
out having to deal with page tables anymore. More details aboutpaging_initand the whole mechanism
behind it are discussed below.

Callingzone_sizes_initinitializes thepgdat_tinstances of all nodes of the system. First a com-
paratively simple list of the available physical memory is prepared usingadd_active_range.The
architecture-independent functionfree_are_init_nodesthen uses this information to prepare the
full-blown kernel data structures. Since this is a very important step that has numerous implications for
how the kernel manages page frames at run time, it is discussed in more detail in Section 3.5.3.

Notice that the memory-related initialization sequence is quite similar on AMD64 machines, as the code
flow diagram in Figure 3-13 shows.

The basic memory setup does not require any machine-type-specific handling, but can always be
done withsetup_memory_region. Information about the available RAM is given by the so-called
E820 map supplied from the BIOS. After parsingthe command-line options relevant for the
early boot process, a simple list of the available memory is created byadd_activecalled from
e820_register_active_region, which, in turn, just walks over the information provided by parsing the
E820 map above.

The kernel then callsinit_memory_mappingto directly map the available physical memory into the vir-
tual address space portion of the kernel starting fromPAGE_OFFSET.contig_initmem_initis responsible
to activate the bootmem allocator.

The last function in the list,paging_init, is actually a misnomer: It does not initialize paging, but has
to deal with some set-up routines for sparse memory systems that are not interesting for our purposes.
The important thing, however, is that the function also callsfree_area_init_nodes, which is as in the
IA-32 case responsible to initialize the data structures required to manage physical page frames by the
kernel.Recallthatthisisanarchitecture-independent function and relies on the information provided
byadd_active_rangeas mentioned above. A detailed discussion of howfree_area_init_nodessets up
memory follows in Section 3.5.3.

(^12) All addresses are interpreted linearly if paging is not explicitly enabled.

Free download pdf