简体   繁体   中英

alloc_pages() is paired by __free_pages()

I read the book "Linux Kernel Development", and find some functions that make me confused, listed as bellow:

struct page *alloc_pages(gfp_t gfp_mask, unsigned int order)
void __free_pages(struct page *page, unsigned int order)

unsigned long __get_free_pages(gfp_t gfp_mask, unsigned int order)
void free_pages(unsigned long addr, unsigned int order)

The problem is the use of the two underline in the function name, and how the function pairs. 1. when will the linux kernel uses two underline in its function name? 2. why alloc_pages is paired with __free_pages, but not free_pages?

As you can notice:

alloc_pages() / __free_pages() takes "page *" (page descriptor) as argument. They are ususally used internally by some infrastrcture kernel code, like page fault handler, which wish to manipulate page descriptor instead of memory block content.

__get_free_pages() / free_pages() takes "unsigned long" (virtual address of memory block) as argument They could be used by code which wish to use the memory block itself, after allocation, you can read / write to this memory block.

As for their name and double underscore "__", you don't need to bother too much. Sometimes kernel functions were named casually without too much consideration when they were first written. And when people think of that the names are not proper, but later those functions are already used wildly in kernel, and kernel guys are simply lazy to change them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM