Why do we require alloc_pages() to return pointer to a struct page unlike other memory allocator function (get_free_pages(), kmalloc() ) ? Please provide a use case. Is it related to HIGHMEM Zone allocation?
alloc_pages(mask, order)
allocates 2order pages and returns an instance of struct page to represent the start of the reserved block. alloc_page(mask) is a shorter notation for order = 0 if only one page is requested.
__get_free_pages(mask, order) and __get_free_page(mask)
work in the same way as the
above functions but return the virtual address of the reserved memory chunk instead of a page instance.
kmalloc(size, mask)
reserves a memory area of size bytes and returns a void pointer to the start of the area. If insufficient memory is available (a very improbable situation in the kernel but one that must always be catered for), a null pointer is the result.
mask specifies details about request:
• memory zone
• behavior of allocator (blocking/unblocking request, etc.)
• e.g. GFP_KERNEL, GFP_ATOMIC, GFP_DMA, etc
alloc_pages() and __get_free_pages() : allocate pages, at low level
kmalloc() : allocate physically contiguous sequence of bytes
for more information refer professional linux kernel architecture by wolfgang mauerer
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With