![](hrule.gif)
Allocating Kernel Memory
![](hrule.gif)
There are several different methods of allocating kernel memory at runtime.
- The bootmem allocator is used to
reserve pages for static kernel data during the early boot process.
- alloc_pages() is the
basic interface to the zone allocator, which hands you a page struct
representing a (range of) physical pages.
- get_free_pages() is a slightly
nicer interface to alloc_pages() which returns the virtual address in
kernel memory, rather than a page struct pointer. get_free_pages()
only works for low memory. [This is not enforced, but it looks like if
you call get_free_pages() with GFP_HIGHMEM, Bad Things can happen.]
- kmalloc() is the slab allocator, which
uses the zone allocator to whack off chunks of kernel
physically-mapped-virtual pages, and carves them up into smaller bits
for particular uses.
- vmalloc() allocates arbitrary physical
pages and maps them into kernel VM contiguously.
- kmap() temporarily maps *any* physical
page into kernel VM.
![](hrule.gif)
![](hrule.gif)
Questions and comments to Joe Knapka
The LXR links in this page were produced by lxrreplace.tcl, which is available for free.
Credits