Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between return values of alloc_pages() and get_free_pages()

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?

like image 459
Pravesh Gupta Avatar asked Oct 04 '22 04:10

Pravesh Gupta


1 Answers

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

like image 64
EnterKEY Avatar answered Oct 07 '22 21:10

EnterKEY