Linux Kernel Architecture

(Jacob Rumans) #1

Chapter3:MemoryManagement


Based on this information,setup_bootmem_allocatoris then responsible to initiate all necessary steps to
initialize the bootmem allocator. It first invokes the generic functioninit_bootmem, which itself is a front
end forinit_bootmem_core.

The purpose ofinit_bootmem_coreis to perform the first initialization step of the bootmem allocator.
The previously detected range of low-memory page frames is entered in the responsiblebootmem_data_t
instance, in this case,contig_bootmem_data. All pages are initially marked as used in the bitmap
contig_bootmemdata->node_bootmem_map.Becauseinit_bootmem_coreis an architecture-independent
function, it cannot yet know which pages are available for use and which are not. Some need special
handling for architectural reasons, for example, page 0 on IA-32 systems. Some are already used, for
instance, by the kernel image. The pages that can actually be used must be explicitly marked by the
architecture-dependent code.

This marking is done with two architecture-specific functions:register_bootmem_low_pagesfrees
all potentially usable memory pages by setting the corresponding bits in the bitmap to 0 so that the
pages are marked as unused. IA-32 systems are supported in this task by the BIOS, which provides
the kernel with a list of all usable memory areas — the e820 map — at an earlier point during
initialization.

Since the bootmem allocator requires some memory pages to manage the reservation bitmap, these must
be reserved first by callingreserve_bootmem.

However, there are still more regions that are already in use and must be marked accordingly. For
this purpose,reserve_bootmemregisters the corresponding pages after the event. The exact number
of regions that must be registered depends highly on the kernel configuration. It is, for instance,
required to reserve the zeroth page because this page is a special BIOS page on many machines
that is required for some machine-specific functions to work properly. Otherreserve_bootmemcalls
reserve configuration-dependent memory areas, for ACPI data or SMP boot-time configurations, for
instance.

Initialization for AMD64


While the technical details of bootmem initialization differ on AMD64, the general structure is rather
similar to the IA-32 case. This timecontig_initmemis the responsible dispatcher.

First of all,bootmem_bootmap_bitmapcomputes the number of pages required for the bootmem
bitmap. Using the information provided by the BIOS in the e820 map, this allows — as on IA-
32 — for finding a continuous memory region of suitable size that is populated with proper
RAM pages.

This information is then filled into the architecture-independent bootmem data structure using
init_bootmem. As before, the function marks all pages as reserved, and the free pages must now
be selected.free_bootmem_with_active_regionscan once more use the information in the e820
map to free all memory regions that were reported as usable by the BIOS. Finally, a single call to
reserve_bootmemis sufficient to register the space required for the bootmem allocation bitmap.
In contrast to IA-32, it is not required to reservespace for legacy information on magical places
in memory.
Free download pdf