Linux Kernel Architecture

(Jacob Rumans) #1

Chapter3:MemoryManagement


The loop continues until the order 4. This page group cannot be merged with its buddy because the
buddy is not empty, as the figure shows. Consequently,page_is_buddydoes not allow for merging the
two regions, and the loop is left.

Finally, the 2^4 =16 page region must now be placed on the free lists of the buddy system. This is not
very complicated:

mm/page_alloc.c
set_page_order(page, order);
list_add(&page->lru,
&zone->free_area[order].free_list[migratetype]);
zone->free_area[order].nr_free++;
}

Notice that the allocation order of the page group is preserved in theprivateelement of the firstpage
instance of the group. This way the kernel knows that not only page 0, but also the whole range [0, 15], is
free and in the buddy system.

3.5.7 Allocation of Discontiguous Pages in the Kernel


Physically contiguous mappings are best for the kernel for the reasons given above, but they cannot
always be used successfully. When a larger chunk of memory is allocated, it may be that it is not available
in a contiguous block despite all efforts made to avoid this situation. This is not a problem in userspace
because normal processes are designed to use the paging mechanism of the processor even though this
is costly in terms of speed and TLBs.

The same technique can also be applied in the kernel. As discussed in Section 3.4.2, the kernel reserves a
chunk of its virtual address space so that it can set up contiguous mappings in them.

As Figure 3-37 shows, a memory zone for the management of discontiguous memory on IA-32 follows
the direct mapping of the first 892 MiB of RAM after an intervening safety gap of 8 MiB. This segment
has all the properties of a linear address space; the pages assigned to it can be located anywhere in RAM
memory. This is achieved by modifying the kernel page tables responsible for this area.

Direct physical
page mappings

Protection gap

vmalloc-Areas

8 MiB

Figure 3-37:vmallocarea in the kernel’s virtual address space on IA-32
systems.

A self-contained area separated from the other areas by a memory page is assigned to eachvmalloc
allocation. Like the boundary between direct mappings and thevmallocarea, the purpose of this is to
safeguard against incorrect memory access operations; these occur only as a result of kernel faults and
Free download pdf