Linux Kernel Architecture

(Jacob Rumans) #1

Chapter3:MemoryManagement


initialized, a simple additional form of memory management is used during the boot process and is
discarded thereafter.

As the CPU-specific parts of memory management initialization employ many minor, subtle details of
the underlying architecture that reveal little of interest about the structure of the kernel and are simply
best practices in assembly language programming, let’s concern ourselves in this section only with ini-
tialization work on a higher level. The key aspect is initialization of thepg_data_tdata structure (and its
subordinate structures) introduced in Section 3.2.2 because this is already machine-independent.

The primary purpose of the aforementioned processor-specific operations whose details we will ignore is
to investigate how much memory is available in total and how it is shared between the individual nodes
and zones of the system.

3.4.1 Data Structure Setup


Initialization of the data structures is launched from within thestart_kernelglobal start routine that is
executed after kernel loading to render the various subsystems operational. As memory management is
a very important kernel component, it is initialized almost immediately after architecture-specific setup,
which is responsible for the technical details of detecting memory and establishing how it is distributed
in the system (Section 3.4.2 deals briefly with the implementation of system-dependentinitialization on
IA-32 systems). At this point, an instance ofpgdat_thas been generated for each system memory mode
to hold information on how much memory there is in the node and how it is distributed over the node
zones. The architecture-specificNODE_DATAmacro implemented on all platforms is used to query the
pgdat_tinstance associated with a NUMA node by reference to the number of the instance.

Prerequisites


Since the majority of systems have just one memory node, only systems of this type are examined below.
What is the situation on such systems? To ensure that memory management code is portable (so that it
can be used on UMA and NUMA systems alike), the kernel defines a single instance ofpg_data_t(called
contig_page_data)inmm/page_alloc.cto manage all system memory. As the file pathname suggests,
this is not a CPU-specific implementation; in fact, it isadopted by most architectures. The implementation
ofNODE_DATAis now even simpler.

<mmzone.h>
#define NODE_DATA(nid) (&contig_page_data)

Although the macro has a formal parameter for selecting a NUMA node, the same data are always
returned — there is just one pseudo-node.

The kernel can also rely on the fact that the architecture-dependent initialization code has set the
numnodesvariable to the number of nodes present in the system. This number is 1 on UMA systems
because only one (formal) node is present.

At compilation time, pre-processor statements select the correct definitions for the particular
configuration.

SystemStart


Figure 3-8 shows a code flow diagram forstart_kernel. It includes only the system initialization func-
tions associated with memory management.
Free download pdf