Issue
struct page* alloc_pages(gfp_t gfp_mask, unsigned int order)
is the function used to allocate page in kernel. So this will allocate 2^order contiguous physical pages.
So this means the pages will allocate in the manner of 1,2,4,8,16 and so on.
What if only 3 pages are needed or 5 ,9 and so on.
Solution
alloc_pages
allocates continuous page frames from the physical memory. Linux kernel has this ill-named, of course.
I believe it is using the buddy allocator.
Most of the time you don't even need continuous page frames. This is only mostly needed for hardware that does DMA transfers or similar. Very unlikely that you'd need 9 continuous frames. If you really do, you'll allocate 16 pages and free the remaining 7, for example order=0
.
Answered By - Antti Haapala