Linux Kernel Architecture

(Jacob Rumans) #1

Chapter3:MemoryManagement


mm/vmalloc.c
void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask,
pgprot_t prot, int node)
{
...
for (i = 0; i < area->nr_pages; i++) {
if (node < 0)
area->pages[i] = alloc_page(gfp_mask);
else
area->pages[i] = alloc_pages_node(node, gfp_mask, 0);
}
...
if (map_vm_area(area, prot, &pages))
goto fail;
return area->addr;
...
}

Return address

Allocate as manypages as necessary

Allocate memory for
page instances

vmalloc

_vmalloc_node

get_vm_area_node

alloc_pages_node

_vmalloc_area_node

_vmalloc

Figure 3-39: Code flow diagram forvmalloc.

If an explicit node is specified from which the pages are to be allocated, the kernel invokes
alloc_pages_node. Otherwise, pages are taken from the current node usingalloc_page.


The pages are removed from the buddy systemof the relevant node; when this is done,vmallocsets
gfp_masktoGFP_KERNEL | __GFP_HIGHMEM— the kernel instructs memory management to take the pages
fromZONE_HIGHMEMif possible. The reasons for this were given above: Pages from the lower-memory
areas are more valuable and should therefore not be wasted forvmallocallocations that could just as
well be satisfied with high-memory pages.


Memory is taken from the buddy system, andgfp_maskis set toGFP_KERNEL | __GFP_HIGHMEMso that the
kernel instructs memory management to take the pages fromZONE_HIGHMEMif possible. We have already
seen the reasons.

Free download pdf