Linux Kernel Architecture

(Jacob Rumans) #1

Chapter3:MemoryManagement


Theclear_pagestandard function that must be implemented by all architectures helpsalloc_pagesfill
pages with null bytes.^19


__get_free_pagesaccessesalloc_pages, whilealloc_pages, in turn, resorts toalloc_pages_node:


<gfp.h>
#define alloc_pages(gfp_mask, order) \
alloc_pages_node(numa_node_id(), gfp_mask, order)

mm/page_alloc.c
fastcall unsigned long __get_free_pages(gfp_t gfp_mask, unsigned int order)
{
struct page * page;
page = alloc_pages(gfp_mask, order);
if (!page)
return 0;
return (unsigned long) page_address(page);
}

In this case, a proper function is used instead of a macro because thepageinstance returned
byalloc_pagesstillremainstobetranslatedintoamemoryaddressusingthehelperfunction
page_address. At this point it is enough for us to know that the function yields the linear memory
address of a page associated with the passedpageinstance. This is problematic with highmem pages, so
I discuss the details of the function in Section 3.5.7.


The unification of allAPIfunctions to a common base function —alloc_pages—isthuscomplete.
Figure 3-30 shows the relationships among the various functions in a graphical overview.


alloc_page get_zeroed_page __get_free_page __get_dma_pages

get_free_pages

alloc_pages

alloc_pages_node
Figure 3-30: Relationships among the allocation functions of the buddy
system.

page_cache_allocandpage_cache_alloc_coldare also convenience functions to yield cache-warm
and cache-cold pages, respectively, by setting the__GFP_COLDmodifier accordingly.


Similarly, the memory-freeing functions can be reduced to a central function (__free_pages)invoked
with different parameters:


<gfp.h>
#define __free_page(page) __free_pages((page), 0)
#define free_page(addr) free_pages((addr),0)

(^19) Of course, pages could be filled with zeros by generic processor-independent code, but most CPUs feature special commands that
do this much faster.

Free download pdf