Reserving Pages

All API functions lead back to alloc_pages_node, which is a kind of ''launch pad'' for central implementation of the buddy system.

static inline struct page *alloc_pages_node(int nid, gfp_t gfp_mask, unsigned int order)

if (unlikely(order >= MAX_ORDER)) return NULL;

return _alloc_pages(gfp_mask, order,

NODE_DATA(nid)->node_zonelists + gfp_zone(gfp_mask));

Just a simple check is carried out to ensure that no overly large memory chunk is allocated. If a negative node ID (which does not exist) is specified, the kernel automatically uses the ID that belongs to the currently executing CPU. Work is then delegated to_alloc_pages to which an appropriate set of parameters is passed. Notice that gfp_zone is used to select the zone from which the allocation is supposed to be fulfilled. This is an important detail that can easily be missed!

The kernel sources refer to this_alloc_pages as the ''heart of the buddy system'' because it deals with the essential aspects of allocation. Since a heart is an important thing to have, I shall introduce the function in detail below.

Continue reading here: Helper Functions

Was this article helpful?

0 0