http://scriptmatrix.net/cs2106/wiki/index.php/Zone_Allocator

Zone Allocator

From The Linux Memory Wiki

Jump to: navigation, search

There are several functions and macros that can be used to allocate 2^order of contiguous page frames. 2 of these functions are essential while others are just macros that used to call that functions.

alloc_pages(gfp_mask, order)

struct page * __alloc_pages(  unsigned int gfp_mask,
                                     unsigned int order,
                                     zonelist_t *zonelist)

allocate 2^order of continuous page frames. This function returns the address of the page descriptor of the first page frame in this block.

__get_free_pages(gfp_mask, order)

unsigned long __get_free_pages(int flags, unsigned long order)

same as alloc_pages(), it allocate 2^order of continuous page frames. But this function returns the linear address of the first page frame instead of the page descriptor address.


gfp_mask

The gfp_mask contains flags to describe the type of memory that is needed. For instance, there is a flag called __GFP_DMA to indicate if the zone needs to be from DMA zone, and another called __GFP_HIGHMEM to indicate High memory zone is needed. There are also some other flags such as the zero flag which request to zero the content of page frames after allocation. There are also a flag which indicate wheter the call can be blocked to wait until free memory is available or not.


The page frame allocation functions in turns call the buddy allocator function __rmqueue() passing in appropriate parameters according to the flags. For instance, if neither __GFP_DMA nor __GFP_HIGHMEM is set, page frames will be allocated either from Normal zone or DMA zone in order of preference. If __GFP_DMA is set, only page frames in DMA zone can be allocated, else if __GFP_HIGHMEM is set, page frame can be allocated from either 3 zones.





Reply via email to