get_free_page and Friends
If a module needs to allocate big chunks of memory, it is usually better to use a page-oriented technique. Requesting whole pages also has other advantages, which will be introduced later, in Section 13.2 in Chapter 13.
To allocate pages, the following functions are available:
- get_zeroed_page
Returns a pointer to a new page and fills the page with zeros.
- __get_free_page
Similar to get_zeroed_page, but doesn’t clear the page.
- __get_free_pages
Allocates and returns a pointer to the first byte of a memory area that is several (physically contiguous) pages long, but doesn’t zero the area.
- __get_dma_pages
Similar to get_free_pages, but guarantees that the allocated memory is DMA capable. If you use version 2.2 or later of the kernel, you can simply use __get_free_pages and pass the
__GFP_DMAflag; if you want backward compatibility with 2.0, you need to call this function instead.
The prototypes for the functions follow:
unsigned long get_zeroed_page(int flags); unsigned long __get_free_page(int flags); unsigned long __get_free_pages(int flags, unsigned long order); unsigned long __get_dma_pages(int flags, unsigned long order);
The flags argument works in the same way as with
kmalloc; usually either
GFP_KERNEL or GFP_ATOMIC is
used, perhaps with the addition of the
__GFP_DMA flag (for memory that can be used
for direct memory access operations) or
__GFP_HIGHMEM when high memory can be used.
order is the base-two logarithm of the number of pages ...