Realizing the vast potential for wastage within the default page allocator (or BSA), a developer from Freescale Semiconductor (see the information box) contributed a patch to the kernel page allocator that extends the API, adding a couple of new ones.
In the 2.6.27-rc1 series, on 24 July 2008, Timur Tabi submitted a patch to mitigate the page allocator wastage issue. Here's the relevant commit: https://github.com/torvalds/linux/commit/2be0ffe2b29bd31d3debd0877797892ff2d91f4c.
Using these APIs leads to more efficient allocations for large-ish chunks (multiple pages) of memory with far less wastage. The new (well, it was new back in 2008, at least) pair of APIs to allocate and free memory are as follows:
#include <linux/gfp.h>
void *alloc_pages_exact(size_t size, gfp_t gfp_mask);
void free_pages_exact(void *virt, size_t size);
The first parameter to the alloc_pages_exact() API, size, is in bytes, the second is...