Allocating a Memory Area

Allocation of a non-continuous memory area is initiated by vmalloc. This is simply a front-end function to supply_vmalloc with suitable parameters and to directly invoke vmalloc node. The associated code flow diagram is shown in Figure 3-39.

Implementation is divided into three parts. First, get_vm_area finds a suitable area in the vmalloc address space. Then individual pages are allocated from physical memory, and finally, these pages are mapped contiguously into the vmalloc area — and VM allocation is done.

The full code need not be reproduced here because it is riddled with boring safety checks.23 What is interesting is the allocation of the physical memory area (ignore the possibility that there may not be enough physical pages available).

23This, however, does not mean that you should avoid safety checks in your own code!

mm/vmalloc.c void *_vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask, pgprot_t prot, int node)

i for (i = 0; i < area->nr_pages; i++) { if (node < 0)

else area->pages[i] = alloc_pages_node(node, gfp_mask, 0);

goto fail; return area->addr;

_vmalloc_node

cs oe

Allocate memory for page instances

Return address

Continue reading here: Figure 339 Code flow diagram for vmalloc

Was this article helpful?

0 0