Linux Kernel Architecture

(Jacob Rumans) #1

Chapter3:MemoryManagement


If this is not the case, the kernel gives up and can do nothing more than return aNULLpointer to the user,
and print a warning message that a memory request could not be fulfilled.

Removing the SelectedPages


Two things remain to be done once the kernel has found a suitable zone with sufficient free pages for
the allocation. First, it must be checked whether the pages arecontiguous(up to now it only knowshow
manyfree pages there are). And second, the pages must be removed from thefree_lists in the buddy
fashion, and this may make it necessary tobreak up and rearrange memory regions.

The kernel delegates this work tobuffered_rmqueueas discussed in the previous section. Figure 3-32
shows the essential steps of the function.

Fill in per-CPU cache if necessary

Appropriate page found? Remove page

Return Null pointer

Ye s

No

== 0? Yes

No

buffered_rmqueue

order

prep_new_page

_ _rmqueue

prep_new_page

Figure 3-32: Code flow diagram forbuffered_rmqueue.

The kernel performs optimization if only a single page is to be allocated, that is, if the allocation order
is 0 because 2^0 =1. The page is not taken directly from the buddy system but from the per-CPU page
cache (recall that this cache provides a CPU-locallist of cache-hot and cache-cold pages; the required
data structures are described in Section 3.2.2).

As usual, some variables need to be set up first:

mm/page_alloc.c
static struct page *
buffered_rmqueue(struct zone *zone, int order, gfp_t gfp_flags)
{
unsigned long flags;
struct page *page;
int cold = !!(gfp_flags & __GFP_COLD);
int migratetype = allocflags_to_migratetype(gfp_flags);

IfGFP_COLDis set in the allocation flags, then a cache-cold page must be taken from the per-CPU allocator
if any exists. The double negation ensures thatcoldis either 0 or 1.^21 It is also essential to determine the

(^21) If justgfp_flags & __GFP_COLDwere used, then the numerical value ofcoldwould be the bit value of__GFP_COLDif the
flag is set. This would not allow usingcoldas an index into a binary array.

Free download pdf